在CentOS上部署Nginx
yum install -y nginx
详细命令:
[root@CentOS7 ~]# yum install nginx -y
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.20.1-10.el7 will be installed
--> Processing Dependency: nginx-filesystem = 1:1.20.1-10.el7 for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libcrypto.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_1)(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libcrypto.so.1.1()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Processing Dependency: libssl.so.1.1()(64bit) for package: 1:nginx-1.20.1-10.el7.x86_64
--> Running transaction check
---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed
---> Package nginx-filesystem.noarch 1:1.20.1-10.el7 will be installed
---> Package openssl11-libs.x86_64 1:1.1.1k-7.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================================
Installing:
nginx x86_64 1:1.20.1-10.el7 epel 588 k
Installing for dependencies:
gperftools-libs x86_64 2.6.1-1.el7 base 272 k
nginx-filesystem noarch 1:1.20.1-10.el7 epel 24 k
openssl11-libs x86_64 1:1.1.1k-7.el7 epel 1.5 M
Transaction Summary
===========================================================================================================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 2.3 M
Installed size: 6.6 M
Downloading packages:
(1/4): nginx-filesystem-1.20.1-10.el7.noarch.rpm | 24 kB 00:00:00
(2/4): gperftools-libs-2.6.1-1.el7.x86_64.rpm | 272 kB 00:00:01
(3/4): nginx-1.20.1-10.el7.x86_64.rpm | 588 kB 00:00:02
(4/4): openssl11-libs-1.1.1k-7.el7.x86_64.rpm | 1.5 MB 00:00:04
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 463 kB/s | 2.3 MB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:openssl11-libs-1.1.1k-7.el7.x86_64 1/4
Installing : 1:nginx-filesystem-1.20.1-10.el7.noarch 2/4
Installing : gperftools-libs-2.6.1-1.el7.x86_64 3/4
Installing : 1:nginx-1.20.1-10.el7.x86_64 4/4
Verifying : gperftools-libs-2.6.1-1.el7.x86_64 1/4
Verifying : 1:nginx-filesystem-1.20.1-10.el7.noarch 2/4
Verifying : 1:nginx-1.20.1-10.el7.x86_64 3/4
Verifying : 1:openssl11-libs-1.1.1k-7.el7.x86_64 4/4
Installed:
nginx.x86_64 1:1.20.1-10.el7
Dependency Installed:
gperftools-libs.x86_64 0:2.6.1-1.el7 nginx-filesystem.noarch 1:1.20.1-10.el7 openssl11-libs.x86_64 1:1.1.1k-7.el7
Complete!
[root@CentOS7 ~]#
启动Nginx
systemctl start nginx
查看Nginx进程启动状态(显示有几个worker process就是几核CPU,我这里是8核CPU)
ps -ef | grep nginx
开机自启动Nginx
systemctl enable nginx
详细命令:
[root@CentOS7 ~]# systemctl start nginx
[root@CentOS7 ~]# ps -ef | grep nginx
root 1893 1 0 13:52 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1894 1893 0 13:52 ? 00:00:00 nginx: worker process
nginx 1895 1893 0 13:52 ? 00:00:00 nginx: worker process
nginx 1896 1893 0 13:52 ? 00:00:00 nginx: worker process
nginx 1897 1893 0 13:52 ? 00:00:00 nginx: worker process
nginx 1898 1893 0 13:52 ? 00:00:00 nginx: worker process
nginx 1899 1893 0 13:52 ? 00:00:00 nginx: worker process
nginx 1900 1893 0 13:52 ? 00:00:00 nginx: worker process
nginx 1901 1893 0 13:52 ? 00:00:00 nginx: worker process
root 1903 1716 0 13:52 pts/0 00:00:00 grep --color=auto nginx
[root@CentOS7 ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@CentOS7 ~]#
查看TCP和UDP的监听端口
netstat -lntup
netstat -lntup
是一个用于显示网络连接状态的命令行工具,通常用于诊断网络问题和查看系统上运行的服务。下面是这个命令各部分的详细解释:
netstat
: 这是命令本身,用来显示网络连接、路由表和其他网络相关信息。-l
: 显示所有监听中的套接字(sockets),即展示所有正在监听的网络服务。-n
: 显示数字形式的地址和端口,而不是尝试查找名称(如域名)。-t
: 显示 TCP 协议的连接。-u
: 显示 UDP 协议的连接。-p
: 显示每个连接对应的程序名或者进程ID(PID)。
当你运行 netstat -lntup
时,它会输出一个列表,其中包括以下信息:
Proto
: 连接的协议类型(TCP 或 UDP)。Recv-Q
: 接收队列的长度,通常为0,除非有数据未被应用程序读取。Send-Q
: 发送队列的长度,通常为0,除非有数据正等待发送。Local Address
: 本地地址和端口。Foreign Address
: 远程地址和端口,如果是监听状态则可能显示为*:*
。State
: 连接的状态(例如,LISTEN
,ESTABLISHED
,TIME_WAIT
等)。PID/Program name
: 对应的进程ID和程序名。
[root@CentOS7 ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 854/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1893/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1253/sshd
tcp6 0 0 :::111 :::* LISTEN 854/rpcbind
tcp6 0 0 :::80 :::* LISTEN 1893/nginx: master
tcp6 0 0 :::22 :::* LISTEN 1253/sshd
udp 0 0 0.0.0.0:600 0.0.0.0:* 854/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 854/rpcbind
udp6 0 0 :::600 :::* 854/rpcbind
udp6 0 0 :::111 :::* 854/rpcbind
[root@CentOS7 ~]#
我们可以看到,Nginx 正确地在监听 80 端口(TCP 和 TCP6)
放行 firewall 的http端口
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
这条命令会打开 HTTP 服务所使用的标准端口,即 TCP 80 端口。这意味着它只针对标准的 HTTP 服务端口进行配置。如果您更改了 Nginx 的启动端口为 8080,那么这条命令将不再适用于您的情况,因为 8080 端口不是 HTTP 服务的标准端口。
因此你可以使用下面的命令放行指定端口:如 80
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload
检查防火墙的状态以确认 80 端口是否已经开放。
sudo firewall-cmd --list-all
标签:00,x86,nginx,Nginx,64,1.20,el7 From: https://www.cnblogs.com/Magiclala/p/18369383