首页 > 代码库 > 统计nginx日志单IP访问请求数排名
统计nginx日志单IP访问请求数排名
下面是我截取一段nginx日志
127.0.0.1 - - [20/Jan/2015:10:54:02 +0800] "GET / HTTP/1.1" 200 20808 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"127.0.0.1 - - [20/Jan/2015:10:54:03 +0800] "GET /favicon.ico HTTP/1.1" 404 151 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"127.0.0.1 - - [20/Jan/2015:10:54:15 +0800] "GET /index.php HTTP/1.1" 200 20806 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"127.0.0.1 - - [20/Jan/2015:10:54:23 +0800] "GET /index.html HTTP/1.1" 404 151 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"127.0.0.1 - - [20/Jan/2015:10:56:08 +0800] "GET /index.html HTTP/1.1" 200 45 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"127.0.0.1 - - [20/Jan/2015:11:31:33 +0800] "GET / HTTP/1.1" 200 45 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"192.168.60.200 - - [20/Jan/2015:11:55:11 +0800] "GET / HTTP/1.1" 200 45 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"192.168.60.200 - - [20/Jan/2015:11:55:11 +0800] "GET /favicon.ico HTTP/1.1" 404 151 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"192.168.60.200 - - [20/Jan/2015:11:55:11 +0800] "GET /favicon.ico HTTP/1.1" 404 151 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"192.168.60.200 - - [20/Jan/2015:11:55:15 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"192.168.60.200 - - [20/Jan/2015:11:55:16 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"192.168.60.200 - - [20/Jan/2015:11:55:17 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"192.168.60.200 - - [20/Jan/2015:12:14:44 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"192.168.60.200 - - [20/Jan/2015:12:14:45 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
方法一:
awk ‘{++S[$1]} END {for(a in S) print a,S[a]}‘ nginx.log | sort -rn -k 2192.168.60.200 8127.0.0.1 6
方法二:
awk ‘{print $1}‘ nginx.log|sort|uniq -c|sort -nr -k1 8 192.168.60.200 6 127.0.0.1
方法三:
sed ‘s/- -.*$//g‘ nginx.log|sort|uniq -c|sort -nr -k1 8 192.168.60.200 6 127.0.0.1
参考:http://oldboy.blog.51cto.com/2561410/1184206
http://oldboy.blog.51cto.com/blog/2561410/1184177
统计nginx日志单IP访问请求数排名
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。