#nginx日誌統計獨立ip的個數: awk '{print $1}' /path-to-log-dir/access.log | sort | uniq | wc -l
#查詢訪問最多的前10個ip awk '{print $1}' /path-to-log-dir/access.log | sort | uniq -c | sort -nr | head -10
#查看某段時間的 grep "2012:0[3-6]" nginx.log |
Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:8652 127.0.0.1:40193 TIME_WAIT tcp 0 0 127.0.0.1:8652 127.0.0.1:40192 TIME_WAIT tcp 0 0 127.0.0.1:8652 127.0.0.1:40196 TIME_WAIT tcp 0 0 127.0.0.1:8652 127.0.0.1:40199 TIME_WAIT tcp 0 0 127.0.0.1:8652 127.0.0.1:40201 TIME_WAIT tcp 0 0 127.0.0.1:8652 127.0.0.1:40204 TIME_WAIT tcp 0 0 127.0.0.1:8652 127.0.0.1:40207 TIME_WAIT tcp 0 0 127.0.0.1:8652 127.0.0.1:40210 TIME_WAIT tcp 0 0 192.168.32.62:41682 192.168.47.207:5432 TIME_WAIT tcp 0 0 192.168.32.62:41685 192.168.47.207:5432 TIME_WAIT #訪問次數最多的IP netstat -ntu | tail -n +3 | awk '{ print $5}' | cut -d : -f 1 | sort | uniq -c| sort -n -r | head -n 5 tail -n +3 :去掉前兩行。 awk '{ print $5}':取數據的低5域(第5列) cut -d : -f 1 :取IP部分。 sort:對IP部分進行排序。 uniq -c:打印每一重複行出現的次數。(並去掉重複行) sort -n -r:按照重複行出現的次序倒序排列。 head -n 5:取排在前5位的IP