在 CentOS 上,Apache 的日志通常位于:
/var/log/httpd/access_log/var/log/httpd/error_log下面按常见需求给你一些日志过滤方法(命令行为主)。
grep "192.168.1.100" /var/log/httpd/access_log
grep "/login.php" /var/log/httpd/access_log
grep " 404 " /var/log/httpd/access_log
grep -i "php" /var/log/httpd/error_log
grep "$(date +%d/%b/%Y)" /var/log/httpd/access_log
awk '$4 >= "[10/Apr/2024:10:00:00" && $4 <= "[10/Apr/2024:11:00:00"' /var/log/httpd/access_log
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
tail -f /var/log/httpd/access_log
tail -f /var/log/httpd/access_log | grep "192.168.1.100"
less(可搜索)less /var/log/httpd/access_log
/关键字 搜索G 跳到末尾journalctl(systemd 环境)Apache 错误也可能在系统日志:
journalctl -u httpd
goaccess(可视化分析)yum install goaccess
goaccess /var/log/httpd/access_log
默认 combined 格式:
IP - - [时间] "请求" 状态码 大小 "Referer" "User-Agent"
如果你有具体过滤场景(比如:只看成拜占庭请求、只看某个域名、只看 POST 请求),可以告诉我,我给你更精确的命令。