网站故障排查常用命令

默北 Linux 运维工具 运维案例网站故障排查常用命令已关闭评论16,319字数 2838阅读9分27秒阅读模式

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

1.查看TCP连接状态文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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(常用于查找攻来源):文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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端口的访问看看谁最高文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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连接文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

5.找查较多的SYN连接文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

6.根据端口列进程文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

7.获得访问前10位的ip地址文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

8.访问次数最多的文件或页面,取前20文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

cat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -n 20

9.列出传输最大的几个rar文件文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

10.列出输出大于200000byte(约200kb)的rar文件以及对应文件发生次数文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

11.如果日志最后一列记录的是页面文件传输时间,则有列出到客户端最耗时的页面文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

12.列出最最耗时的页面(超过60秒的)的以及对应页面发生次数文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

13.列出传输时间超过 30 秒的文件文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

14.统计网站流量(G)文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

15.统计404的连接文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

16. 统计http status.文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

17.查看是哪些爬虫在抓取内容。文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

18.按域统计流量文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

19.查看数据库执行的sql语句文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

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

20.调试命令文章源自运维生存时间-https://www.ttlsa.com/linux/site-troubleshooting-common-commands/

strace -p pid

21.跟踪指定进程的PID

 gdb -p pid

22. 简单web

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

转载请注明出处:网站故障排查常用命令 https://www.ttlsa.com/html/1682.html

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 20/07/2013 22:38:15
  • 转载请务必保留本文链接:https://www.ttlsa.com/linux/site-troubleshooting-common-commands/
  • tcpdump
  • 网站故障常用命令