久久99国产精品尤物|久久黄色视频二区|三级在线播放试看无码一区二区|国产综合在线观看精品12

電話:+86 574 88168918 郵箱(xiang):sales@aliance.cn

首頁-新聞動態-新聞詳情

shell在手 分析服務器日志不愁

發布時間:作(zuo)者:科博綜合布線瀏(liu)覽:225次來(lai)源:
CobiNet(寧波)推薦文章:

自己(ji)的小(xiao)網站跑在阿里云的ECS上面,偶爾也去(qu)分(fen)析分(fen)析自己(ji)網站服(fu)務器(qi)日(ri)志,看(kan)(kan)看(kan)(kan)網站的訪問量。看(kan)(kan)看(kan)(kan)有沒(mei)有黑(hei)闊搞(gao)破壞!于是(shi)收集,整理一(yi)些服(fu)務器(qi)日(ri)志分(fen)析命令,大家可以(yi)試試!

1、查看有多少個IP訪問(wen):

awk '{print $1}' log_file|sort|uniq|wc -l

2、查看某(mou)一個頁面被訪(fang)問的(de)次數:

grep "/index.php" log_file | wc -l

3、查看每(mei)一個(ge)IP訪問了多少個(ge)頁面:

awk '{++S[$1]} END {for (a in S) print a,S[a]}' log_file log.txt

sort -n -t ' ' -k 2 log.txt 配合sort進一步排序

4、將每個IP訪問的頁面數(shu)進行從小到大排序(xu):

awk '{++S[$1]} END {for (a in S) print S[a],a}' log_file | sort -n

5、查看某一(yi)個(ge)IP訪(fang)問了(le)哪些(xie)頁面:

grep ^111.111.111.111 log_file| awk '{print $1,$7}'

6、去(qu)掉搜索引擎統計(ji)的頁面:

awk '{print $12,$1}' log_file | grep ^\"Mozilla | awk '{print $2}' |sort | uniq | wc -l

7、查看(kan)2015年(nian)8月16日14時(shi)這(zhe)一個小時(shi)內有多少IP訪問:

awk '{print $4,$1}' log_file | grep 16/Aug/2015:14 | awk '{print $2}'| sort | uniq | wc -l

8、查(cha)看訪問前十個ip地址

awk '{print $1}' |sort|uniq -c|sort -nr |head -10 access_log

uniq -c 相當于分組統計并把(ba)統計數放在最前(qian)面(mian)

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}

9、訪問次數(shu)最(zui)多的10個(ge)文(wen)件或頁面

cat log_file|awk '{print $11}'|sort|uniq -c|sort -nr | head -10

cat log_file|awk '{print $11}'|sort|uniq -c|sort -nr|head -20

awk '{print $1}' log_file |sort -n -r |uniq -c | sort -n -r | head -20

訪問(wen)量最大的前20個ip

10、通過子域名訪問次數,依據referer來計算,稍(shao)有(you)不準

cat access.log | awk '{print $11}' | sed -e ' s/http:\/\///' -e ' s/\/.*//' | sort | uniq -c | sort -rn | head -20

11、列出(chu)傳輸大小最大的(de)幾個文件

cat www.access.log |awk '($7~/\.php/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -100

12、列出輸(shu)出大于200000byte(約200kb)的(de)頁(ye)面以(yi)及對應頁(ye)面發生次(ci)數

cat www.access.log |awk '($10 200000 $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100

13、如果日(ri)志最后一列(lie)記錄的(de)是頁面(mian)文件傳輸時間(jian),則有列(lie)出到客戶端最耗時的(de)頁面(mian)

cat www.access.log |awk '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100

14、列(lie)出最最耗時的(de)頁面(超過(guo)60秒的(de))的(de)以及對(dui)應頁面發(fa)生次(ci)數(shu)

cat www.access.log |awk '($NF 60 $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100

15、列出傳輸時(shi)間超(chao)過 30 秒的文件

cat www.access.log |awk '($NF 30){print $7}'|sort -n|uniq -c|sort -nr|head -20

16、列(lie)(lie)出當前(qian)服務(wu)器每一(yi)進程運(yun)行(xing)的數量,倒序排列(lie)(lie)

ps -ef | awk -F ' ' '{print $8 " " $9}' |sort | uniq -c |sort -nr |head -20

17、查看(kan)apache當前(qian)并發訪問數(shu)

對比httpd.conf中MaxClients的數字(zi)差距多少

netstat -an | grep ESTABLISHED | wc -l

18、可以(yi)使(shi)用如下(xia)參數查(cha)看數據

ps -ef|grep httpd|wc -l

1388

統(tong)計(ji)httpd進(jin)程數,連個請求會啟動(dong)一個進(jin)程,使用于Apache服務(wu)器。

表示Apache能夠處理1388個并發請求,這個值(zhi)Apache可根據負載情況自動調整

netstat -nat|grep -i "80"|wc -l

4341

netstat -an會打印系統當前網絡鏈接(jie)狀(zhuang)態,而grep -i "80"是用來提取與80端口有關的連接(jie)的,wc -l進(jin)行連接(jie)數統計(ji)。

最終(zhong)返(fan)回的數字就是當前(qian)所(suo)有80端口的請求總(zong)數

netstat -na|grep ESTABLISHED|wc -l

376

netstat -an會打印系統(tong)當前網絡(luo)鏈接狀態,而(er)grep ESTABLISHED 提取出已(yi)建立連接的信息。 然后wc -l統(tong)計

最終返回(hui)的數字就是當前所有80端口的已建立連接的總數。

netstat -nat||grep ESTABLISHED|wc

可查看所有建(jian)立(li)連接的詳細記錄

19、輸出每個ip的(de)連接數,以及總(zong)的(de)各個狀態的(de)連接數

netstat -n | awk '/^tcp/ {n=split($(NF-1),array,":");if(n =2)++S[array[(1)]];else++S[array[(4)]];++s[$NF];++N} END {for(a in S){printf("%-20s %s\n", a, S[a]);++I}printf("%-20s %s\n","TOTAL_IP",I);for(a in s) printf("%-20s %s\n",a, s[a]);printf("%-20s %s\n","TOTAL_LINK",N);}'

20、其他的收集

分析日志文件下 2012-05-04 訪問頁面最高 的前20個 URL 并(bing)排(pai)序

cat access.log |grep '04/May/2012'| awk '{print $11}'|sort|uniq -c|sort -nr|head -20

查詢受訪問頁面的URL地址(zhi)(zhi)中 含(han)有 www.abc.com 網(wang)址(zhi)(zhi)的 IP 地址(zhi)(zhi)

cat access_log | awk '($11~/\www.abc.com/){print $1}'|sort|uniq -c|sort -nr

獲取(qu)訪問最高的10個(ge)IP地(di)址 同時也(ye)可以按時間來(lai)查(cha)詢

cat linewow-access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10

時間(jian)段查詢日志時間(jian)段的情況

cat log_file | egrep '15/Aug/2015|16/Aug/2015' |awk '{print $1}'|sort|uniq -c|sort -nr|head -10

分析2015/8/15 到 2015/8/16 訪(fang)問"/index.php?g=Member m=Public a=sendValidCode"的IP倒序排列

cat log_file | egrep '15/Aug/2015|16/Aug/2015' | awk '{if($7 == "/index.php?g=Member m=Public a=sendValidCode") print $1,$7}'|sort|uniq -c|sort -nr

(7~/.php/)7 /.php/)7里(li)面(mian)包含(han).php的就(jiu)輸(shu)出(chu),本句的意思(si)是(shi)最耗時的一百個PHP頁面(mian)

cat log_file |awk '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100

列(lie)出最最耗時的頁(ye)面(超過60秒的)的以及對應(ying)頁(ye)面發生次數

cat access.log |awk '($NF 60 $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100

統計網站流量(G)

cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}'

統計404的連接

awk '($9 ~/404/)' access.log | awk '{print $9,$7}' | sort

統計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

每秒并發

watch "awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' log_file|sort -k 2 -nr|head -n10"

帶寬統計

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"}'

找出某天(tian)訪問次數最多的10個(ge)IP

cat /tmp/access.log | grep "20/Mar/2011" |awk '{print $3}'|sort |uniq -c|sort -nr|head

當天ip連接數最(zui)高的ip都在干些什么

cat access.log | grep "10.0.21.17" | awk '{print $8}' | sort | uniq -c | sort -nr | head -n 10

小時(shi)單(dan)位里ip連接數(shu)最多的10個(ge)時(shi)段

awk -vFS="[:]" '{gsub("-.*","",$1);num[$2" "$1]++}END{for(i in num)print i,num[i]}' log_file | sort -n -k 3 -r | head -10

找出訪問次數(shu)最多的(de)幾個分鐘

awk '{print $1}' access.log | grep "20/Mar/2011" |cut -c 14-18|sort|uniq -c|sort -nr|head

取5分鐘日志

if [ $DATE_MINUTE != $DATE_END_MINUTE ] ;then #則判斷開(kai)始時間戳與結束時間戳是否(fou)相等

START_LINE=sed -n "/$DATE_MINUTE/=" $APACHE_LOG|head -n1 #如果不(bu)相等,則取出(chu)開(kai)始時間戳(chuo)的行號,與結束時間戳(chuo)的行號

查看tcp的鏈(lian)接狀態(tai)

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

netstat -ant|awk '/ip:80/{split($5,ip,":");++S[ip[1]]}END{for (a in S) print S[a],a}' |sort -n

netstat -ant|awk '/:80/{split($5,ip,":");++S[ip[1]]}END{for (a in S) print S[a],a}' |sort -rn|head -n 10

awk 'BEGIN{printf ("http_code\tcount_num\n")}{COUNT[$10]++}END{for (a in COUNT) printf a"\t\t"COUNT[a]"\n"}'

查找(zhao)請(qing)求(qiu)數前20個IP(常用于查找(zhao)攻來源):

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

用tcpdump嗅探80端口的訪(fang)問看看誰最高

tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20

查找較多time_wait連接(jie)

netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20

找查較多的SYN連接

netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more

根據端口列進程

netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1

查(cha)看了連接數和(he)當前的連接數

netstat -ant | grep $ip:80 | wc -l

netstat -ant | grep $ip:80 | grep EST | wc -l

查看IP訪問次數

netstat -nat|grep ":80"|awk '{print $5}' |awk -F: '{print $1}' | sort| uniq -c|sort -n

Linux命(ming)令分析(xi)當前的鏈接狀況

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

watch "netstat -n | awk '/^tcp/ {++S[\$NF]} END {for(a in S) print a, S[a]}'" # 通過watch可以一直監控

LAST_ACK 5 #關閉(bi)一個TCP連接(jie)需要從兩個方(fang)向(xiang)上分別(bie)進行(xing)關閉(bi),雙方(fang)都是通(tong)過發送FIN來表示單(dan)方(fang)向(xiang)數(shu)據(ju)的關閉(bi),當(dang)通(tong)信雙方(fang)發送了最后一個FIN的時候,發送方(fang)此時處于LAST_ACK狀態,當(dang)發送方(fang)收到對(dui)方(fang)的確(que)認(Fin的Ack確(que)認)后才(cai)真正(zheng)關閉(bi)整個TCP連接(jie);

SYN_RECV 30 # 表示正在等待處理(li)的請求數;

ESTABLISHED 1597 # 表示正常(chang)數(shu)據傳(chuan)輸(shu)狀態;

FIN_WAIT1 51 # 表示server端主(zhu)動要求關閉tcp連接;

FIN_WAIT2 504 # 表示客戶端(duan)中(zhong)斷連(lian)接;

TIME_WAIT 1057 # 表(biao)示處(chu)理完畢,等待(dai)超時結束的請求數(shu);


文章編輯:CobiNet(寧波)  
本公司專注于電訊配件,銅纜綜合布線系列領域產品研發生產超五類,六類,七類屏蔽網線/屏蔽模塊及相關模塊配件, 光纖及配件,我們是萬兆屏蔽模塊10G屏蔽模塊屏蔽線生產廠家(jia),綜合布線實(shi)施(shi)公(gong)司。

 歡迎來電咨(zi)詢0574 88168918,郵箱sales@aliance.cn,網址aliance.cn

相關新聞

 

?2016-2019寧波科博通(tong)信技術有限公司版權所(suo)有