在 CentOS 上监控 Apache(httpd),可以从 系统层、Apache 自身状态、日志、性能工具 四个方面来做。下面给你一套从简单到专业的完整方案。
systemctl status httpd
或
ps -ef | grep httpd
查看端口:
ss -lntp | grep 80
mod_status编辑配置文件:
vim /etc/httpd/conf/httpd.conf
确认或添加:
LoadModule status_module modules/mod_status.so
<Location /server-status>
SetHandler server-status
Require all granted
</Location>
⚠️ 生产环境建议限制 IP
Require ip 127.0.0.1 192.168.1.100
systemctl restart httpd
http://服务器IP/server-status
示例:
http://127.0.0.1/server-status
✅ 能看到:
ps -ef | grep httpd
ss -ant | grep :80 | wc -l
或:
netstat -an | grep :80 | wc -l
tail -f /var/log/httpd/access_log
tail -f /var/log/httpd/error_log
awk '{print $4}' /var/log/httpd/access_log | cut -c 14-18 | sort | uniq -c
top
查看:
安装 htop(更直观):
yum install -y htop
htop
监控项包括:
结合 node_exporter 和 apache_exporter
传统但稳定
| 指标 | 说明 |
|---|---|
| 并发连接数 | 是否过高 |
| 请求响应时间 | 是否变慢 |
| 错误日志 | 是否有 5xx |
| 内存占用 | 是否泄漏 |
| 端口监听 | 是否异常 |
#!/bin/bash
echo "Apache 状态:"
systemctl status httpd | grep Active
echo "当前连接数:"
ss -ant | grep :80 | wc -l
echo "最近错误:"
tail -n 10 /var/log/httpd/error_log
如果你愿意,我可以帮你:
✅ 写一个 CentOS + Apache 监控脚本
✅ 配置 Zabbix 监控 Apache
✅ 给你一个 生产环境监控方案图
你现在是 学习 / 测试 / 生产环境?