统计nginx/apache 访问日志中访问次数最多的IP

原文地址http://www.07net01.com/2015/08/914079.html

nginx

awk '{print $1}' urlogfile | sort | uniq -c | sort -nr -k1 | head -n 10
awk '{print $1}' /usr/local/nginx/logs/localhost.access.log | sort | uniq -c | sort -nr -k1 | head -n 10

Apache

cd /var/log/httpd/&&\
cat access_log | awk '{print $1}' | uniq -c | sort -rn -k1 | head -n 10

说明:

awk '{ print $1}':取数据的低1域(第1列)

sort:对IP部分进行排序。

uniq -c:打印每一重复行出现的次数。(并去掉重复行)

sort -nr -k1:按照重复行出现的次序倒序排列,-k1以第一列为标准排序。

head -n 10:取排在前10位的IP 。

猜你喜欢

转载自blog.csdn.net/weixin_42123737/article/details/81840375