温馨提示×

Apache日志在CentOS上如何分析

小樊
47
2025-08-16 16:52:31
栏目: 智能运维

一、日志文件位置

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

二、常用命令行工具

  • 查看实时日志tail -f /var/log/httpd/access_log
  • 搜索特定信息grep "关键字" /var/log/httpd/access_log
  • 统计IP访问次数awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -nr
  • 分析状态码grep " 404 " /var/log/httpd/access_log

三、图形化工具

  • Webalizer:生成图表报告,需安装配置。
  • Awstats:支持详细统计,需安装配置。
  • ELK Stack:实时分析,需部署Logstash、Elasticsearch、Kibana。

四、日志轮替管理

使用logrotate工具自动压缩、删除旧日志,配置文件为/etc/logrotate.d/httpd

0