六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 34|回复: 0

Linux 网站维护常用命令

[复制链接]

升级  45.33%

30

主题

30

主题

30

主题

秀才

Rank: 2

积分
118
 楼主| 发表于 2013-1-26 12:44:11 | 显示全部楼层 |阅读模式
系统连接状态篇: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 -c2.查找请求数请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 -n205.找查较多的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网站日志分析篇1(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.访问次数最多的文件或页面,取前20cat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -203.列出传输最大的几个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的连接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 -rn10.蜘蛛分析查看是哪些蜘蛛在抓取内容。/usr/sbin/tcpdump -i eth1 -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 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表