监控方案总览 在 CentOS 上监控 Apache 性能,建议同时覆盖:实时连接与吞吐(如 mod_status、apachetop)、日志分析与可视化(如 GoAccess、logwatch)、系统资源(如 top/htop、vmstat),以及企业级告警与可视化(如 Zabbix)。这些工具组合能帮助你从请求速率、响应码分布、慢 URL、资源瓶颈到容量规划与告警形成闭环。
快速上手 实时与内置监控
ExtendedStatus On
<Location "/server-status">
SetHandler server-status
Require host 127.0.0.1
Require ip 192.168.0.0/24
</Location>
重启后在浏览器访问 http://服务器IP/server-status 查看当前连接、请求速率、状态码分布等;如需命令行查看可用 lynx http://localhost/server-status。sudo yum install -y apachetop
apachetop -f /var/log/httpd/access_log
进入界面后可用方向键选择条目、按 → 展开详情、按 s 切换排序字段(如 reqs、bytes、2xx/4xx/5xx)。日志分析与可视化
sudo yum install -y goaccess
goaccess /var/log/httpd/access_log -o /var/www/html/report.html --log-format=COMBINED
sudo yum install -y logwatch
sudo logwatch --output html --range yesterday --detail high
awk '{print $4}' /var/log/httpd/access_log \
| cut -d: -f2 | cut -d. -f1 \
| sort | uniq -c | sort -nr
/var/log/httpd/access_log /var/log/httpd/error_log {
daily
rotate 7
missingok
compress
delaycompress
notifempty
create 640 root root
sharedscripts
postrotate /usr/bin/systemctl reload httpd >/dev/null 2>&1 || true
endscript
}
以上可帮助你从访问模式、热点资源、错误趋势与容量增长趋势上识别性能问题与优化方向。系统资源与压力测试
ab -n 1000 -c 50 http://yourserver.com/
压测同时观察 mod_status 的 Req/S、Busy/Idle workers、Bytes/S 等指标,定位并发与吞吐瓶颈。企业级监控与告警 Zabbix
关键指标与优化方向