在 CentOS 系统中,可以通过以下几种方法查看 Apache 的连接数:
netstat 命令查看当前所有连接:
netstat -ant | grep ':80' | wc -l
这里假设 Apache 监听的是 80 端口。如果监听的是其他端口,请相应修改。
查看当前活跃连接:
netstat -an | grep ':80' | grep ESTABLISHED | wc -l
查看每个 IP 的连接数:
netstat -an | grep ':80' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
ss 命令ss 是一个更现代的工具,比 netstat 更快且功能更强大。
查看当前所有连接:
ss -tn | grep ':80' | wc -l
查看当前活跃连接:
ss -tn | grep ':80' | grep ESTAB | wc -l
查看每个 IP 的连接数:
ss -tn | grep ':80' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
Apache 提供了一些模块可以帮助监控连接数,例如 mod_status。
启用 mod_status 模块:
编辑 Apache 配置文件(通常是 /etc/httpd/conf/httpd.conf 或 /etc/apache2/apache2.conf),添加以下内容:
<Location "/server-status">
SetHandler server-status
Require host localhost
</Location>
然后重启 Apache:
systemctl restart httpd
访问状态页面:
打开浏览器,访问 http://your_server_ip/server-status,可以看到详细的服务器状态信息,包括当前的连接数。
还有一些第三方工具可以帮助监控 Apache 的连接数,例如 htop、atop 等。
安装 htop:
yum install htop
运行 htop:
htop
在 htop 界面中,可以查看实时的连接数和其他系统资源使用情况。
通过以上方法,你可以方便地查看 CentOS 系统中 Apache 的连接数。选择适合你的方法进行监控即可。