温馨提示×

怎样用centos查apache日志

小樊
35
2026-10-09 01:01:57
栏目: 智能运维

在 CentOS 上查看 Apache 日志,通常按照以下步骤操作:

一、确认 Apache 是否安装并运行

systemctl status httpd

如果未运行,可启动:

systemctl start httpd

二、Apache 日志默认位置

在 CentOS(使用 httpd)中,默认日志目录是:

/var/log/httpd/

常见日志文件:

  • 访问日志:/var/log/httpd/access_log
  • 错误日志:/var/log/httpd/error_log

三、查看日志的常用命令

1. 实时查看访问日志

tail -f /var/log/httpd/access_log

2. 实时查看错误日志

tail -f /var/log/httpd/error_log

3. 查看最后 100 行

tail -n 100 /var/log/httpd/access_log

4. 搜索关键字(如 404、IP)

grep "404" /var/log/httpd/access_log
grep "192.168.1.1" /var/log/httpd/access_log

5. 查看日志大小

ls -lh /var/log/httpd/

四、如果日志路径被修改过

查看 Apache 配置:

grep -R "CustomLog" /etc/httpd/
grep -R "ErrorLog" /etc/httpd/

五、使用 journalctl(系统日志)

如果是通过 systemd 启动:

journalctl -u httpd

如果你愿意,可以告诉我:

  • Apache 是 httpd 还是 apache2
  • 日志路径是否改过
  • 想查“访问异常 / 报错 / 某个 IP”

我可以给你更精确的命令。

0 踩