要监控 CentOS 上 Nginx 的运行状态,您可以使用以下方法:
-
使用
systemctl
命令检查 Nginx 服务状态:sudo systemctl status nginx
如果 Nginx 服务正在运行,您将看到类似以下的输出:
● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2021-06-21 10:00:00 UTC; 1min ago
如果服务未运行,您可以使用以下命令启动它:
sudo systemctl start nginx
若要确保 Nginx 在系统启动时自动运行,请执行:
sudo systemctl enable nginx
-
使用
ps
命令检查 Nginx 进程:ps aux | grep nginx
这将显示所有与 Nginx 相关的进程。 您应该看到一个类似于以下的输出:
nginx 1234 0.0 0.1 12345 6789 ? Ss Jun21 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; nginx 5678 0.0 0.1 12345 6780 ? S Jun21 0:00 nginx: worker process
-
使用
netstat
命令检查 Nginx 监听的端口:sudo netstat -tuln | grep 80
如果 Nginx 正在运行并监听 80 端口,您将看到类似以下的输出:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1234/nginx
-
使用
iftop
命令监控 Nginx 的网络流量:首先,安装
iftop
:sudo yum install epel-release sudo yum install iftop
然后,运行
iftop
并监控 Nginx 的网络流量:sudo iftop -i
将
替换为您的网络接口名称,例如eth0
。 这将显示实时的网络流量信息,包括发送和接收的数据包数量。
通过这些方法,您可以有效地监控 CentOS 上 Nginx 的运行状态。