linux下常用的故障排查命令列

來源:互聯網
上載者:User

linux下常用的故障排查命令列 1.查看TCP串連狀態netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rnnetstat -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]}'  www.2cto.com  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 -rnnetstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -cnetstat -ant|awk '/ip:80/{split($5,ip,":");++S[ip[1]]}END{for (a in S) print S[a],a}' |sort -nnetstat -ant|awk '/:80/{split($5,ip,":");++S[ip[1]]}END{for (a in S) print S[a],a}' |sort -rn|head -n 10awk 'BEGIN{printf ("http_code\tcount_num\n")}{COUNT[$10]++}END{for (a in COUNT) printf a"\t\t"COUNT[a]"\n"}'
 2.尋找請求數請20個IP(常用於尋找攻來源):netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A[i],i}' |sort -rn|head -n203.用tcpdump嗅探80連接埠的訪問看看誰最高tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -204.尋找較多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 | more6.根據連接埠列進程netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1
 網站日誌分析(Apache):1.獲得訪問前10位的ip地址cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10cat access.log|awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}'2.訪問次數最多的檔案或頁面,取前20及統計所有訪問IPcat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -20awk '{ print $1}' access.log |sort -n -r |uniq -c|wc -l3.列出傳輸最大的幾個exe檔案(分析下載站的時候常用)cat access.log |awk '($7~/\.exe/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -204.列出輸出大於200000byte(約200kb)的exe檔案以及對應檔案發生次數cat access.log |awk '($10 > 200000 && $7~/\.exe/){print $7}'|sort -n|uniq -c|sort -nr|head -1005.如果日誌最後一列記錄的是分頁檔傳輸時間,則有列出到用戶端最耗時的頁面cat access.log |awk '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -1006.列出最最耗時的頁面(超過60秒的)的以及對應頁面發生次數cat access.log |awk '($NF > 60 && $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -1007.列出傳輸時間超過 30 秒的檔案cat access.log |awk '($NF > 30){print $7}'|sort -n|uniq -c|sort -nr|head -208.統計網站流量(G)cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}'9.統計404的串連  www.2cto.com  awk '($9 ~/404/)' access.log | awk '{print $9,$7}' | sort10. 統計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 -rn11.每秒並發:awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}'|sort -k 2 -nr|head -n1012.頻寬統計cat apache.log |awk '{if($7~/GET/) count++}END{print "client_request="count}'cat apache.log |awk '{BYTE+=$11}END{print "client_kbyte_out="BYTE/1024"KB"}'13.統計對象數量及對象平均大小cat access.log |awk '{byte+=$10}END{ print byte/NR/1024,NR}'cat access.log |awk '{if($9~/200|30/)COUNT[$NF]++}END{for( a in COUNT) print a,COUNT[a],NR,COUNT[a]/NR*100"%"}
 14.取5分鐘日誌if [ $DATE_MINUTE != $DATE_END_MINUTE ] ;then #則判斷開始時間戳與結束時間戳記是否相等START_LINE=`sed -n "/$DATE_MINUTE/=" $APACHE_LOG|head -n1` #如果不相等,則取出開始時間戳的行號,與結束時間戳記的行號#END_LINE=`sed -n "/$DATE_END_MINUTE/=" $APACHE_LOG|tail -n1`END_LINE=`sed -n "/$DATE_END_MINUTE/=" $APACHE_LOG|head -n1`sed -n "${START_LINE},${END_LINE}p" $APACHE_LOG > $MINUTE_LOG ##通過行號,取出5分鐘內的日誌內容 存放到 臨時檔案中GET_START_TIME=`sed -n "${START_LINE}p" $APACHE_LOG|awk -F '[' '{print $2}' |awk '{print $1}'|sed 's#/# #g'|sed 's#:# #'` #通過行號擷取取出開始時間戳GET_END_TIME=`sed -n "${END_LINE}p" $APACHE_LOG|awk -F '[' '{print $2}' |awk '{print $1}'|sed's#/# #g'|sed 's#:# #'` #通過行號擷取結束時間戳記
 15.蜘蛛分析查看是哪些蜘蛛在抓取內容/usr/sbin/tcpdump -i eth0 -l -s 0 -w - dst port 80 | strings | grep -i user-agent | grep -i -E 'bot|crawler|slurp|spider'網站日分析2(Squid篇)2.按域統計流量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]}}'
 效率更高的perl版本請到此下載:http://docs.linuxtone.org/soft/tools/tr.pl資料庫篇1.查看資料庫執行的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'系統Debug分析篇1.調試命令strace -p pid2.跟蹤指定進程的PIDgdb -p pid
  作者 yulianliu1218

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.