[root@100 nginx]# cat liuhaihua.access.log | awk -F " " '{print $1}' |sort |uniq -c |sort -rn|head -n 20
217636 47.76.99.127
217605 47.76.209.138
79007 38.55.194.100
39006 66.249.74.72
38747 66.249.71.40
33965 216.244.66.244
29643 66.249.74.73
29207 14.153.238.144
28882 129.211.163.247
28485 14.155.183.120
23862 66.249.79.167
21645 14.153.233.199
19477 66.249.74.74
18979 14.155.230.15
17436 66.249.71.41
14782 66.249.69.35
13284 47.94.150.2
12954 66.249.70.71
12742 14.155.204.218
12728 14.153.241.201
sort:
-r:逆序输出排序结果
-n:根据字符串数值比较
uniq:从输入文件或者标准输入中筛选相邻的匹配行并写入到输出文件或标准输出。
-c:在每行前加上表示相应行目出现次数的前缀编号
[root@100 nginx]# grep '47.76.99.127' liuhaihua.access.log |awk '{print $7}'|sort |uniq -c |sort -rn |head -n 100
1641 /archives/497017.html
1038 /archives/503168.html
238 /
156 /js/libs/jquery-confirm.min.js
147 /js/libs/jquery.lazyload.min.js
142 /js/libs/nprogress.min.js
142 /js/libs/jquery.fancybox.min.js
141 /js/zhyd.js
.....................
grep "47.76.99.127" /var/log/nginx/liuhaihua.access.log | grep "$(date +%d/%b/%Y)" | awk -F'"' '{print $2}' | awk '{print $2}'
这个命令的作用是:
grep "47.76.99.127"
:过滤出包含该IP地址的日志行。grep "$(date +%d/%b/%Y)"
:进一步过滤出包含今天日期的日志行。wc -l
:统计这些行的数量。grep "47.76.99.127" /var/log/nginx/liuhaihua.access.log | grep "$(date +%d/%b/%Y)" | awk -F'"' '{print $2}' | awk '{print $2}'
这个命令的作用是:
grep "47.76.99.127"
:过滤出包含该IP地址的日志行。grep "$(date +%d/%b/%Y)"
:进一步过滤出包含今天日期的日志行。awk -F'"' '{print $2}'
:提取出请求行(通常是第二个字段)。awk '{print $2}'
:从请求行中提取出请求的URL路径(通常是第二个字段)。yum install goaccess
goaccess liuhaihua.access.log
goaccess liuhaihua.access.log -o report.html --log-format=COMBINED