从accesslog中统计nginx访问频率
时间:2016-01-02 20:28 来源:linux.it.net.cn 作者:IT
1、使用正则表达式从accesslog中将ip地址筛选出来,并存入/root/test1
sed "s/.* \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/;s/[^0-9 ]*\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/" /【nginx路径】/logs/access.log > /root/test
2、使用shell命令对ip地址进行统计,并输出到/root/test2
cat /root/test | sort | uniq -c | sort -k1,1nr | head -10 > /root/test2
3、查看结果
cat /root/test2
(责任编辑:IT)
1、使用正则表达式从accesslog中将ip地址筛选出来,并存入/root/test1 sed "s/.* \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/;s/[^0-9 ]*\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/" /【nginx路径】/logs/access.log > /root/test 2、使用shell命令对ip地址进行统计,并输出到/root/test2 cat /root/test | sort | uniq -c | sort -k1,1nr | head -10 > /root/test2 3、查看结果 cat /root/test2 (责任编辑:IT) |