Web troubleshooting分析常用的命令

1.查看TCP�B接��B
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'
netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'
netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'
netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c

2.查看�求�登�20��IP
netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20
netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A[i],i}' |sort -rn|head -n20

3.用tcpdump嗅探80埠的存取前20�酌�
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20

4.查看前20名�^多time_wait�B接
netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20

5.找查�^多的SYN�B接
netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more

6.根��埠列�M程
netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1

�W站日�I分析篇(Apache Log)
1.�@得存取前10位的ip位址
cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10
cat access.log|awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}'

2.存取次�底疃嗲�20名的�n案或�面
cat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -20

3.列出�鬏�最大前20名的���exe�n案(分析下�d站的�r候常用)
cat access.log |awk '($7~/\.exe/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -20

4.列出�出大於200000byte(�s200kb)的exe�n以及����n案�l生次��
cat access.log |awk '($10 > 200000 && $7~/\.exe/){print $7}'|sort -n|uniq -c|sort -nr|head -100

5.列出到用�舳俗詈�r的�面
cat access.log |awk  '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100

6.列出最最耗�r的�面(超�^60秒的)的以及����面�l生次��
cat access.log |awk '($NF > 60 && $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100

7.列出�鬏��r�g超�^ 30 秒的�n案
cat access.log |awk '($NF > 30){print $7}'|sort -n|uniq -c|sort -nr|head -20

8.�y��W站流量(G)
cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}'

9.�y�代�a404的�B接
awk '($9 ~/404/)' access.log | awk '{print $9,$7}' | sort

10. �y�http status
cat access.log |awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}'
cat access.log |awk '{print $9}'|sort|uniq -c|sort -rn

11.查看是哪些蜘蛛在抓取�热�
/usr/sbin/tcpdump -i eth0 -l -s 0 -w - dst port 80 | strings | grep -i user-agent | grep -i -E 'bot|crawler|slurp|spider'

12.�y�各HTTP ��B��
cat tmp.log | awk -F' ' '$9 == "400" || $9 == "408" || $9 == "499" || $9 == "500" || $9 =="502" || $9 =="504" {print $9}' | sort | uniq -c | more

13.�^�V出�L���W站的IP
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' access.log >ip.txt

�W站日分析(Squid篇)
按域�y�流量
zcat squid_access.log.tar.gz| awk '{print $10,$7}' |awk 'BEGIN{FS="[ /]"}{trfc[$4]+=$1}END{for(domain in trfc){printf "%s\t%d\n",domain,trfc[domain]}}'

查看�Y料��绦械�sql
/usr/sbin/tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | egrep -i 'SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL'

系�yDebug分析篇
1.�{�命令strace -p pid
2.跟�指定�M程的PIDgdb -p pid

你可能感兴趣的:(Web,troubleshooting)