您的位置:首页 > 其它

web故障排查常用命令

2017-01-19 19:28 405 查看
整理总结了一些常用分析网站的命令方便大家快速定位故障所在排除故障,最小化的减少故障给业务带来的影响。

端口连接类

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 -n 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


7.查看http的并发请求数及其TCP连接状态

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


8.查看连接某服务端口最多的的IP地址

netstat -an -t | grep ":80" | grep ESTABLISHED | awk '{printf "%s %s\n",$5,$6}' | sort


9.查看Apache的并发请求数及其TCP连接状态

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


Web日志类

1.获得访问前10位的ip地址

cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -n 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 -n 20


3.列出传输最大的几个rar文件

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


4.列出输出大于200000byte(约200kb)的rar文件以及对应文件发生次数

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


5.如果日志最后一列记录的是页面文件传输时间,则有列出到客户端最耗时的页面

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


6.列出最最耗时的页面(超过60秒的)的以及对应页面发生次数

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


7.列出传输时间超过 30 秒的文件

cat access.log |awk '($NF > 30){print $7}'|sort -n|uniq -c|sort -nr|head -n 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(code in counts) print code, counts
}'
cat access.log |awk '{print $9}'|sort|uniq -c|sort -rn


11.查看是哪些爬虫在抓取内容。

tcpdump -i eth0 -l -s 0 -w - dst port 80 | strings | grep -i user-agent | grep -i -E 'bot|crawler|slurp|spider'


12.按域统计流量

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


13.查看数据库执行的sql语句

tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | egrep -i 'SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL'


14.调试命令

strace -p pid


15. 简单web

python -m SimpleHTTPServer [port] //默认8000端口


16.统计一下服务器下面所有jpg文件的大小

find / -name *.jpg -exec wc -c {} \;|awk '{print $1}'|awk '{a+=$1}END{print a}'


进程类

1.进程总数

ps aux | wc -l


2.清除僵死进程

ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9


3.杀掉80端口相关的进程

lsof -i :80|grep -v "PID"|awk '{print "kill -9",$2}'|sh


4.检查是否有异常错误记录

grep -i error /var/log/messages
grep -i fail /var/log/messages


5.跟踪指定进程的PID

gdb -p pid


文件类

1.列出当前目录中今天修改的文件

find . -maxdepth 1 -mmin -$((`date +%H`*60+`date +%M`))

find . -maxdepth 1 -newermt $(date --date='now' '+%Y-%m-%d')


2.列出3天内修改的文件

find . -mtime -3 -print

find / -mtime  +/- 数字 执行之前或之内的几天


3.找出2017-01-01这一天修改的文件,当前目录

find . -maxdepth 1 -newermt "2017-01-01"


其他

如何在编写SHELL显示信息,用EOF

cat << EOF
+--------------------------------------------------------------+
| === Welcome to opdev.me  ===                                |
+--------------------------------------------------------------+
EOF


[code] http://www.opdev.me/php-performance-improvement-opcache.html[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: