Linux运维知识之Linux Web服务器网站故障分析常用的命令
小标 2019-01-16 来源 : 阅读 1167 评论 0

摘要:本文主要向大家介绍了Linux运维知识之Linux Web服务器网站故障分析常用的命令,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。

本文主要向大家介绍了Linux运维知识之Linux Web服务器网站故障分析常用的命令,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。

系统连接状态篇:


1.查看TCP连接状态


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端口的访问看看谁最高


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.根据端口列进程


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


网站日志分析篇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.访问次数最多的文件或页面,取前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文件以及对应文件发生次数


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秒的)的以及对应页面发生次数


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.统计网站流量(G)


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


9.统计404的连接


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


10. 统计http status


cat access.log |awk ‘{counts[$(9)]+=1}; END {for(coolcode in counts) print coolcode, counts}’

cat access.log |awk ‘{print $9}’|sort|uniq -c|sort -rn


10.蜘蛛分析,查看是哪些蜘蛛在抓取内容。


/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篇)按域统计流量


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]}}’


数据库篇


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 pid

2.跟踪指定进程的PID

gdb -p pid

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注系统运维Linux频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程