在 CentOS 系统中,Apache 服务器的日志文件通常位于 /var/log/httpd/ 目录下。主要的访问日志文件是 access_log,错误日志文件是 error_log。要分析 GET 请求,我们需要关注 access_log 文件。
首先,确保 Apache 的访问日志记录功能已启用。编辑 Apache 配置文件(通常位于 /etc/httpd/conf/httpd.conf 或 /etc/httpd/conf.d/access_log.conf),并确保以下配置行没有被注释掉:
CustomLog /var/log/httpd/access_log combined 这里的 combined 是一种日志格式,它包括了 GET 请求的信息。还有其他几种日志格式,如 common、combined 和 referer,可以根据需要进行选择。
接下来,我们可以使用 grep、awk、sed 等命令行工具来分析访问日志中的 GET 请求。以下是一些示例:
grep -c 'GET' /var/log/httpd/access_log awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -nr grep 'GET /your-page' /var/log/httpd/access_log awk '{print $9}' /var/log/httpd/access_log | sort | uniq -c | sort -nr awk '{print $7}' /var/log/httpd/access_log | sort | uniq -c | sort -nr | head -n 10 这些命令只是分析 GET 请求的起点,你可以根据自己的需求进行修改和扩展。