在 CentOS 上监控 Apache 日志,常见方式从简单实时查看到专业监控告警都有。下面按使用场景给你一个实用清单。
tail -f /var/log/httpd/access_log
tail -f /var/log/httpd/error_log
CentOS 默认 Apache 日志路径:
- 访问日志:
/var/log/httpd/access_log- 错误日志:
/var/log/httpd/error_log
tail -f /var/log/httpd/error_log | grep 500
tail -f /var/log/httpd/access_log | grep 1.2.3.4
tail -f /var/log/httpd/error_log | grep -i php
awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -nr | head
awk '{print $7}' /var/log/httpd/access_log | sort | uniq -c | sort -nr | head
awk '{print $9}' /var/log/httpd/access_log | sort | uniq -c | sort -nr
journalctl -u httpd -f
查看错误:
journalctl -u httpd -p err -f
CentOS 默认使用 logrotate:
cat /etc/logrotate.d/httpd
手动测试:
logrotate -d /etc/logrotate.d/httpd
yum install goaccess -y
goaccess /var/log/httpd/access_log -o report.html --log-format=COMBINED
实时终端模式:
goaccess /var/log/httpd/access_log
适合多台服务器、长期存储、告警:
✅ 错误日志中出现 AH 错误
✅ 5xx 状态码比例 > 1%
✅ 单 IP 请求频率异常
✅ Apache 进程数过高
✅ 磁盘日志增长过快
如果你愿意,可以告诉我:
我可以直接给你一套可复制的监控方案。