apache日志access_log格式分析

一.日志

11.104.211.13 -- [03/Mar /2020:15:23:17 +0800] "POST  /perbank/add.do HTTP/1.1"   200  254  0  "https://pbank.psbc/com/preperbank/index.html" "Mozilla/5.0 (windows NT 10.0 wow64) AppleweKit/537.36(KHTML, like Gecko) Chrome/77.0.3865 Safari/537.36"
117.136.38.168 -- [03/Mar /2020:15:23:17 +0800] "POST  /preperbank/add.do HTTP/1.1"   200  254  0  "https://pbank.psbc/com/preperbank/index.html" "Mozilla/5.0 (windows NT 10.0 wow64) AppleweKit/537.36(KHTML, like Gecko) Chrome/77.0.3865 Safari/537.36"
  1. 11.104.211.13 : 远端主机地址,客户端发送到apach服务器时服务器的地址,服务器返回数据时客户端的地址,如果 客户端使用了代理服务器,那么这里的ip就是代理服务器的地址。

  2. - 远端登录名(由identd而来,如果支持的话),除非IdentityCheck设为"On",否则将得到一个"-"。
    The “hyphen” in the output indicates that the requested piece of information is not available. In this case, the information that is not available is the RFC 1413 identity of the client determined by identd on the clients machine. This information is highly unreliable and should almost never be used except on tightly controlled internal networks. Apache httpd will not even attempt to determine this information unless IdentityCheck is set to On.

  3. - 远程用户名(根据验证信息而来;如果返回status(%s)为401,可能是假的)

  4. [03/Mar /2020:15:23:17 +0800] 请求的时间,格式为[day/month/year:hour:minute:second zone],最后的+0800表示服务器所处的时区为东八区

  5. “POST /perbank/add.do HTTP/1.1” 请求的第一行,请求方法/访问路径/协议

  6. 200 这是一个状态码,由服务器端发送回客户端,它告诉我们客户端的请求是否成功,或者是重定向,或者是碰到了什么样的错误,这项值为200,表示服务器已经成 功的响应了客户端的请求,一般来说,这项值以2开头的表示请求成功,以3开头的表示重定向,以4开头的标示客户端存在某些的错误,以5开头的标示服务器端 存在某些错误,详细的可以参见 HTTP specification (RFC2616 section 10).

  7. 254 以CLF格式显示的除HTTP头以外传送的字节数,也就是当没有字节传送时显示’-'而不是0。它告诉我们传输是否被打断(该数值是否和文件的大小相同)。把日志记录中的这些值加起来就可以得知服务器在一天、一周或者一月内发送了多少数据。

  8. 0 “%{Referer}i” 接收的字节数,包括请求头的数据,并且不能为零。要使用这个指令你必须启用mod_logio模块。

  9. “https://pbank.psbc/com/preperbank/index.html” “Mozilla/5.0 (windows NT 10.0 wow64) AppleweKit/537.36(KHTML, like Gecko) Chrome/77.0.3865 Safari/537.36” 客户端的浏览器信息

  10. 格式定义再/etc/httpd/conf/httpd.conf

  11. LogFormat “%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”” combined

二.实用的日志分析命令和脚本

了解日志的各种定义后,这里分享一下从网上淘来的一些对日志分析的脚本。
1.查看apache的进程数
ps -aux | grep httpd | wc -l
2.分析日志查看当天的ip连接数
cat default-access_log | grep “10/Dec/2010” | awk ‘{print $2}’ | sort | uniq -c | sort -nr
3.查看指定的ip在当天究竟访问了什么url
cat default-access_log | grep “10/Dec/2010” | grep “218.19.140.242” | awk ‘{print $7}’ | sort | uniq -c | sort -nr
4.查看当天访问排行前10的url
cat default-access_log | grep “10/Dec/2010” | awk ‘{print $7}’ | sort | uniq -c | sort -nr | head -n 10
5.看到指定的ip究竟干了什么
cat default-access_log | grep 218.19.140.242 | awk ‘{print $1"\t"$8}’ | sort | uniq -c | sort -nr | less
6.查看访问次数最多的几个分钟(找到热点)
awk ‘{print $4}’ default-access_log |cut -c 14-18|sort|uniq -c|sort -nr|head

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值