Linux中部署tomcat 日志顯示訪問者IP地址
Linux中部署tomcat 日志顯示訪問者IP地址
原創(chuàng)2022-03-11 11:00·Linux云計算架構(gòu)
tomcat日志文件訪問IP統(tǒng)計
server.xml文件默認(rèn)配置
"org.apache.catalina.valves.AccessLogValve" directory="logs"?
? ? ? ? ? ? ? prefix="localhost_access_log." suffix=".txt"? ? ? ? ? ? ? ? ? ? ? ? ?? pattern="%h %l %u %t "%r" %s %b" />

如果想在日志文件中顯示訪問者的IP,需要修改配置如下
"org.apache.catalina.valves.AccessLogValve" directory="logs"
? ? ? ? ? ? ? prefix="localhost_access_log." suffix=".txt"
? ? ? ? ? ? ? pattern="common" resolveHosts="false"/>

訪問日志命令:
[root@iZ2zeab8t820b5yseZ logs]# tail -f localhost_access_log.2022-03-11.txt
tomcat日志文件訪問IP統(tǒng)計
訪問前10的IP以及對應(yīng)IP訪問次數(shù)降序排列(因IP在日志中的第一列,所以取$1)
[root@iZ2zeab8t820feZ logs]# cat localhost_access_log.2022-03-11.txt|awk '{print $1}'|sort |uniq -c|sort -nr|head -10

shell腳本1:統(tǒng)計某日志文件中所有訪問者的IP
awk '{aaa[$1]++;} END{for(i in aaa) { printf("%s\t%s\n", aaa[i], i); }}' localhost_access_log.2022-03-11.txt | sort -bn

grep -i -o -E -r -e "([0-9]{1,3}.){3}[0-9]{1,3}" localhost_access_log.2018-09-19.txt | sort -n | uniq -c | sort -n
shell腳本2:統(tǒng)計某日志文件中所有訪問者的IP
[root@iZ2zeab8t820b5ywp0rkfeZ logs]# awk '{print $1}' localhost_access_log.2022-03-11.txt | grep -E "([0-9]{1,3}.){3}[0-9]{1,3}" | sort | uniq -c | sort -g
