1.nginx
# 1. 查看虚拟机系统和版本
[root@stream9 ~]# cat /etc/os-release
NAME="CentOS Stream"
VERSION="9"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="9"
PLATFORM_ID="platform:el9"
PRETTY_NAME="CentOS Stream 9"
ANSI_COLOR="0;31"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:centos:centos:9"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 9"
REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream"
# 2. 安装 => centos stream 虚拟机
[root@stream9 ~]# yum -y install nginx
# 3.启动nginx
[root@stream9 ~]# systemctl start nginx
[root@stream9 ~]# systemctl enable nginx # 设置开机自启
[root@stream9 ~]# systemctl status nginx # 查看nginx服务状态
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled)
Active: active (running) since Tue 2023-10-31 20:18:30 CST; 42s ago
Main PID: 38057 (nginx)
Tasks: 3 (limit: 11125)
Memory: 2.8M
CPU: 48ms
CGroup: /system.slice/nginx.service
├─38057 "nginx: master process /usr/sbin/nginx"
├─38059 "nginx: worker process"
└─38060 "nginx: worker process"
Oct 31 20:18:29 stream9 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Oct 31 20:18:29 stream9 nginx[38043]: nginx: the configuration file /etc/nginx/nginx.conf syntax >
Oct 31 20:18:29 stream9 nginx[38043]: nginx: configuration file /etc/nginx/nginx.conf test is suc>
Oct 31 20:18:30 stream9 systemd[1]: Started The nginx HTTP and reverse proxy server.
lines 1-16/16 (END)
# 4. 查看配置文件 所有服务的配置文件目录 => /etc/服务名/xxx
[root@stream9 ~]# cat /etc/nginx/nginx.conf
# 5. 改页面内容
[root@stream9 ~]# cat /usr/share/nginx/html/index.html
123
[root@stream9 ~]# systemctl restart nginx.service # 重启服务
# 6. 访问页面
http://IP/
# 7. 查看nginx版本
[root@stream9 ~]# nginx -V
nginx version: nginx/1.22.1
built by gcc 11.3.1 20221121 (Red Hat 11.3.1-4) (GCC)
built with OpenSSL 3.0.7 1 Nov 2022
TLS SNI support enabled
# 8. 查看nginx安装包
[root@stream9 ~]# rpm -qa | grep nginx
nginx-filesystem-1.22.1-2.el9.noarch
nginx-core-1.22.1-2.el9.x86_64
nginx-1.22.1-2.el9.x86_64
# 9. 查看包装的位置及文件
[root@stream9 ~]# rpm -ql nginx-1.22.1-2.el9.x86_64
/usr/bin/nginx-upgrade
/usr/lib/systemd/system/nginx.service
/usr/share/man/man3/nginx.3pm.gz
/usr/share/man/man8/nginx-upgrade.8.gz
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx/html/404.html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/icons
/usr/share/nginx/html/icons/poweredby.png
/usr/share/nginx/html/index.html
/usr/share/nginx/html/nginx-logo.png
/usr/share/nginx/html/poweredby.png
/usr/share/nginx/html/system_noindex_logo.png
/usr/share/vim/vimfiles/ftdetect/nginx.vim
/usr/share/vim/vimfiles/ftplugin/nginx.vim
/usr/share/vim/vimfiles/indent/nginx.vim
/usr/share/vim/vimfiles/syntax/nginx.vim
[root@stream9 ~]#
[root@stream9 ~]# ls /usr/share/nginx/html
404.html 50x.html icons index.html nginx-logo.png poweredby.png system_noindex_logo.png
[root@stream9 ~]#
[root@stream9 ~]# cat /usr/share/nginx/html/index.html
This is my first web!
# 10. 卸载nginx
[root@stream9 ~]# yum -y remove nginx
[root@stream9 ~]# rpm -qa | grep nginx
[root@stream9 ~]#
[root@stream9 ~]# systemctl status nginx
Unit nginx.service could not be found.
[root@stream9 ~]# ps -aux | grep 80
root 24187 0.0 0.3 18060 6216 pts/0 R+ 21:50 0:00 ps -aux
root 24188 0.0 0.1 6408 2124 pts/0 S+ 21:50 0:00 grep --color=auto 80
2.httpd 服务
[root@stream9 ~]# yum -y install httpd
[root@stream9 ~]# rpm -qa | grep httpd
httpd-tools-2.4.57-5.el9.x86_64
httpd-filesystem-2.4.57-5.el9.noarch
centos-logos-httpd-90.4-1.el9.noarch
httpd-core-2.4.57-5.el9.x86_64
httpd-2.4.57-5.el9.x86_64
[root@stream9 ~]#
[root@stream9 ~]# rpm -ql httpd-2.4.57-5.el9.x86_64 查看关于httpd的部分常用包的路径
/etc/httpd/conf.modules.d/00-brotli.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/usr/lib/.build-id
/usr/lib/.build-id/a8
/usr/lib/.build-id/a8/4ef0b427863d9631a252966f625d8712420d94
/usr/lib/.build-id/b4
/usr/lib/.build-id/b4/b37ec4829dd8bf8a3210bd55fe01ab42be08ec
/usr/lib/systemd/system/htcacheclean.service
/usr/lib/systemd/system/httpd.service
/usr/lib/systemd/system/httpd.socket
/usr/lib/systemd/system/[email protected]
/usr/lib64/httpd/modules/mod_brotli.so
/usr/lib64/httpd/modules/mod_systemd.so
/usr/share/man/man5/httpd.conf.5.gz
/usr/share/man/man8/apachectl.8.gz
/usr/share/man/man8/fcgistarter.8.gz
/usr/share/man/man8/htcacheclean.8.gz
/usr/share/man/man8/htcacheclean.service.8.gz
/usr/share/man/man8/httpd.8.gz
/usr/share/man/man8/httpd.service.8.gz
/usr/share/man/man8/httpd.socket.8.gz
/usr/share/man/man8/[email protected]
/usr/share/man/man8/rotatelogs.8.gz
/usr/share/man/man8/suexec.8.gz
[root@stream9 ~]# systemctl start httpd
[root@stream9 ~]#
[root@stream9 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
Active: active (running) since Tue 2023-10-31 21:55:20 CST; 6s ago
Docs: man:httpd.service(8)
Main PID: 24687 (httpd)
Status: "Started, listening on: port 80"
Tasks: 213 (limit: 11125)
Memory: 39.5M
CPU: 297ms
CGroup: /system.slice/httpd.service
├─24687 /usr/sbin/httpd -DFOREGROUND
├─24688 /usr/sbin/httpd -DFOREGROUND
├─24689 /usr/sbin/httpd -DFOREGROUND
├─24690 /usr/sbin/httpd -DFOREGROUND
└─24691 /usr/sbin/httpd -DFOREGROUND
Oct 31 21:55:08 stream9 systemd[1]: Starting The Apache HTTP Server...
Oct 31 21:55:14 stream9 httpd[24687]: AH00558: httpd: Could not reliably determine the server\'s fully qualified domain name, using 10.10.10.129. Set the 'ServerName' di>
Oct 31 21:55:20 stream9 httpd[24687]: Server configured, listening on: port 80
Oct 31 21:55:20 stream9 systemd[1]: Started The Apache HTTP Server.
[root@stream9 ~]#
[root@stream9 ~]# curl 127.0.0.1
123
[root@stream9 ~]# cat /var/www/html/index.html
123
[root@stream9 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.10.129 netmask 255.255.255.0 broadcast 10.10.10.255
inet6 fe80::5054:ff:feba:3ee prefixlen 64 scopeid 0x20<link>
ether 52:54:00:ba:03:ee txqueuelen 1000 (Ethernet)
RX packets 13195 bytes 31168624 (29.7 MiB)
RX errors 0 dropped 1066 overruns 0 frame 0
TX packets 10684 bytes 1390937 (1.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 10 bytes 860 (860.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 860 (860.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@stream9 ~]# curl 10.10.10.129:80
123
[root@stream9 ~]# grep -Ev "^#|^$|^[ \+]" /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
</Directory>
<Directory "/var/www/html">
</Directory>
<IfModule dir_module>
</IfModule>
<Files ".ht*">
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
</IfModule>
<IfModule alias_module>
</IfModule>
<Directory "/var/www/cgi-bin">
</Directory>
<IfModule mime_module>
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf
[root@stream9 ~]#
[root@stream9 ~]# grep "apache" /etc/passwd
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@stream9 ~]#
[root@stream9 ~]# id apache
uid=48(apache) gid=48(apache) groups=48(apache)
# 卸载
[root@stream9 ~]# yum -y remove httpd
[root@stream9 ~]# rpm -qa | grep httpd
3.tomcat
[root@stream9 ~]# yum -y install tomcat
[root@stream9 ~]# rpm -qa | grep tomcat
tomcat-el-3.0-api-9.0.62-37.el9.noarch
tomcat-servlet-4.0-api-9.0.62-37.el9.noarch
tomcat-jsp-2.3-api-9.0.62-37.el9.noarch
tomcat-lib-9.0.62-37.el9.noarch
tomcat-9.0.62-37.el9.noarch
[root@stream9 ~]# rpm -ql tomcat-9.0.62-37.el9.noarch
/etc/logrotate.d/tomcat.disabled
/etc/sysconfig/tomcat
/etc/tomcat
/etc/tomcat/Catalina
/etc/tomcat/Catalina/localhost
/etc/tomcat/catalina.policy
/etc/tomcat/catalina.properties
/etc/tomcat/conf.d
/etc/tomcat/conf.d/README
/etc/tomcat/conf.d/java-9-start-up-parameters.conf
/etc/tomcat/context.xml
/etc/tomcat/jaspic-providers.xml
/etc/tomcat/jaspic-providers.xsd
/etc/tomcat/logging.properties
/etc/tomcat/server.xml
/etc/tomcat/tomcat-users.xml
/etc/tomcat/tomcat-users.xsd
/etc/tomcat/tomcat.conf
/etc/tomcat/web.xml
/usr/bin/tomcat-digest
/usr/bin/tomcat-tool-wrapper
/usr/lib/systemd/system/tomcat.service
/usr/lib/systemd/system/[email protected]
/usr/libexec/tomcat
/usr/libexec/tomcat/functions
/usr/libexec/tomcat/preamble
/usr/libexec/tomcat/server
/usr/sbin/tomcat
/usr/share/doc/tomcat
/usr/share/doc/tomcat/LICENSE
/usr/share/doc/tomcat/NOTICE
/usr/share/doc/tomcat/RELEASE-NOTES
/usr/share/tomcat
/usr/share/tomcat/bin/bootstrap.jar
/usr/share/tomcat/bin/catalina-tasks.xml
/usr/share/tomcat/conf
/usr/share/tomcat/lib
/usr/share/tomcat/logs
/usr/share/tomcat/temp
/usr/share/tomcat/webapps
/usr/share/tomcat/work
/var/cache/tomcat
/var/cache/tomcat/temp
/var/cache/tomcat/work
/var/lib/tomcat
/var/lib/tomcat/webapps
/var/lib/tomcats
/var/log/tomcat
[root@stream9 ~]# systemctl start tomcat.service
[root@stream9 ~]#
[root@stream9 ~]# systemctl enable tomcat.service
Created symlink /etc/systemd/system/multi-user.target.wants/tomcat.service → /usr/lib/systemd/system/tomcat.service.
[root@stream9 ~]#
[root@stream9 ~]# systemctl status tomcat.service
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled; preset: disabled)
Active: active (running) since Tue 2023-10-31 22:37:18 CST; 12s ago
Main PID: 25617 (java)
Tasks: 28 (limit: 11125)
Memory: 54.5M
CPU: 3.423s
CGroup: /system.slice/tomcat.service
└─25617 /usr/lib/jvm/jre/bin/java -Djavax.sql.DataSource.Factory=org.apache.commons.dbcp.BasicDataSourceFactory -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar: ->
Oct 31 22:37:19 stream9 server[25617]: 31-Oct-2023 22:37:19.925 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/var/cache/tomcat/temp
Oct 31 22:37:19 stream9 server[25617]: 31-Oct-2023 22:37:19.926 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/share/tomcat/conf/logg>
Oct 31 22:37:19 stream9 server[25617]: 31-Oct-2023 22:37:19.926 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogM>
Oct 31 22:37:19 stream9 server[25617]: 31-Oct-2023 22:37:19.933 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found o>
Oct 31 22:37:20 stream9 server[25617]: 31-Oct-2023 22:37:20.577 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
Oct 31 22:37:20 stream9 server[25617]: 31-Oct-2023 22:37:20.651 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [1207] milliseconds
Oct 31 22:37:20 stream9 server[25617]: 31-Oct-2023 22:37:20.781 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
Oct 31 22:37:20 stream9 server[25617]: 31-Oct-2023 22:37:20.782 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.62]
Oct 31 22:37:20 stream9 server[25617]: 31-Oct-2023 22:37:20.796 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
Oct 31 22:37:20 stream9 server[25617]: 31-Oct-2023 22:37:20.841 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [188] milliseconds
# 目录
[root@stream9 ~]# cat /usr/share/tomcat/webapps/ROOT/index.html
123
# 查看网页内容
[root@stream9 ~]# curl 127.0.0.1:8080
123
# 服务端 使用 python 起一个http服务
[root@stream9 ckh]# python -m http.server 8090
Serving HTTP on 0.0.0.0 port 8090 (http://0.0.0.0:8090/) ...
10.10.10.1 - - [31/Oct/2023 22:54:48] "GET / HTTP/1.1" 200 -
10.10.10.1 - - [31/Oct/2023 22:55:23] "GET / HTTP/1.1" 200 -
10.10.10.1 - - [31/Oct/2023 22:55:24] "GET / HTTP/1.1" 200 -
10.10.10.1 - - [31/Oct/2023 22:55:25] "GET / HTTP/1.1" 200 -
10.10.10.1 - - [31/Oct/2023 22:55:26] "GET / HTTP/1.1" 200 -
10.10.10.1 - - [31/Oct/2023 22:55:26] "GET / HTTP/1.1" 200 -
10.10.10.1 - - [31/Oct/2023 22:55:27] "GET / HTTP/1.1" 200 -
^C
Keyboard interrupt received, exiting.
[root@stream9 ckh]# ls
index.html
[root@stream9 ckh]# cat index.html
789
[root@stream9 ckh]# pwd
/root/ckh
# 客户端访问
[root@kvm ~]# curl 10.10.10.129:8090
789
标签:web,服务,tomcat,33,share,nginx,usr,root,stream9
From: https://www.cnblogs.com/ckh2023/p/18070130