nginx访客ip统计
时间:2016-11-11 16:17 来源:潇湘夜雨 作者:华嵩阳 点击:次
本文主要介绍nginx服务器中统计日志中的访客ip数据
1.统计最近20个请求的客户端ip
[root@www ~]# tail -n 20 /var/log/nginx/access.log|awk '{print $2}' #$2表示日志文件中ip的位置,根据实际日志格式设置
182.150.46.143,182.140.184.154
182.150.46.143,182.140.184.154
182.150.46.143,182.140.184.154
182.150.46.143,117.175.88.50
101.226.162.90
111.206.241.75
42.96.189.63
112.126.74.55
112.124.127.224
42.96.189.63
-
112.126.74.55
171.8.167.63
112.124.127.224
111.206.241.75
42.96.189.63
112.126.74.55
112.124.127.224
42.96.189.63
112.126.74.55
2.对统计信息排序
[root@www ~]# tail -n 20 /var/log/nginx/access.log|awk '{print $2}'|sort
-
101.226.162.90
111.206.241.75
111.206.241.75
112.124.127.224
112.124.127.224
112.124.127.224
112.126.74.55
112.126.74.55
112.126.74.55
112.126.74.55
171.8.167.63
171.8.167.64
182.150.46.143,117.175.88.50
182.150.46.143,182.140.184.154
182.150.46.143,182.140.184.154
42.96.189.63
42.96.189.63
42.96.189.63
42.96.189.63
3.对统计信息去重
[root@www ~]# tail -n 20 /var/log/nginx/access.log|awk '{print $2}'|sort|uniq -c
1 -
1 101.226.162.90
2 111.206.241.75
4 112.124.127.224
4 112.126.74.55
1 171.8.167.63
1 171.8.167.64
1 182.150.46.143,117.175.88.50
1 182.150.46.143,182.140.184.154
4 42.96.189.63
4.统计独立ip数量
[root@www ~]# tail -n 20 /var/log/nginx/access.log|awk '{print $2}'|sort|uniq -c|wc -l
10
5.统计当前日志的所有独立ip数
awk '{print $2}' /var/log/nginx/access.log |sort|uniq -c|wc -l
6.在代理服务器需要去除空值
awk '{print $2}' access.log|grep ^[0-9]|sort|uniq -c|wc -l
7.统计访问次数最多的ip
[root@m-proxy1 log]# awk '{print $2}' access.log|grep ^[0-9]|sort|uniq -c|sort -rn -k1|head -n 5 # sort -k1表示按第一个值排序
1646 103.240.16.71
413 220.182.4.137
382 117.180.237.122
280 36.162.210.126
277 117.180.238.12
|