PS:整理一些Linux Web服務(wù)器網(wǎng)站故障分析常用的命令,內(nèi)容均來源于網(wǎng)絡(luò)。如果你是老手,什么好的命令集或者必殺技?xì)g迎留言,豐富此文!
系統(tǒng)連接狀態(tài)篇:
1.查看TCP連接狀態(tài)
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn</p>
<p>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]}'</p>
<p>netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn</p>
<p>netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
2.查找請求數(shù)請20個IP(常用于查找攻來源):
netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20</p>
<p>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端口的訪問看看誰最高
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20
4.查找較多time_wait連接
netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20
5.找查較多的SYN連接
netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more
6.根據(jù)端口列進(jìn)程
netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1
網(wǎng)站日志分析篇1(Apache):
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.訪問次數(shù)最多的文件或頁面,取前20
cat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -20
3.列出傳輸最大的幾個exe文件(分析下載站的時候常用)
cat access.log |awk '($7~/.exe/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -20
4.列出輸出大于200000byte(約200kb)的exe文件以及對應(yīng)文件發(fā)生次數(shù)
cat access.log |awk '($10 > 200000 && $7~/.exe/){print $7}'|sort -n|uniq -c|sort -nr|head -100
5.如果日志最后一列記錄的是頁面文件傳輸時間,則有列出到客戶端最耗時的頁面
cat access.log |awk '($7~/.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100
6.列出最最耗時的頁面(超過60秒的)的以及對應(yīng)頁面發(fā)生次數(shù)
cat access.log |awk '($NF > 60 && $7~/.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100
7.列出傳輸時間超過 30 秒的文件
cat access.log |awk '($NF > 30){print $7}'|sort -n|uniq -c|sort -nr|head -20
8.統(tǒng)計(jì)網(wǎng)站流量(G)
cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}'
9.統(tǒng)計(jì)404的連接
awk '($9 ~/404/)' access.log | awk '{print $9,$7}' | sort
10. 統(tǒng)計(jì)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
10.蜘蛛分析,查看是哪些蜘蛛在抓取內(nèi)容。
/usr/sbin/tcpdump -i eth0 -l -s 0 -w - dst port 80 | strings | grep -i user-agent | grep -i -E 'bot|crawler|slurp|spider'
網(wǎng)站日分析2(Squid篇)按域統(tǒng)計(jì)流量
zcat squid_access.log.tar.gz| awk '{print $10,$7}' |awk 'BEGIN{FS="[ /]"}{trfc[$4]+=$1}END{for(domain in trfc){printf "%st%dn",domain,trfc[domain]}}'
數(shù)據(jù)庫篇
查看數(shù)據(jù)庫執(zhí)行的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'
系統(tǒng)Debug分析篇
1.調(diào)試命令
strace -p pid
2.跟蹤指定進(jìn)程的PID
gdb -p pid
美國服務(wù)器租用
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。