linux管理员命令,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,state[key]}'/^tcp/滤出tcp开头的记录,屏蔽udp, socket等无关记录。state[]相当于定义了一个名叫state的数组NF表示记录的字段数,如上所示的记录,NF等于6$NF表示某个字段的值,如上所示的记录,$NF也就是$6,表示第6个字段的值,也就是TIME_WAITstate[$NF]表示数组元素的值,如上所示的记录,就是state[TIME_WAIT]状态的连接数++state[$NF]表示把某个数加一,如上所示的记录,就是把state[TIME_WAIT]状态的连接数加一END表示在最后阶段要执行的命令for(key in state)遍历数组print key,"/t",state[key]打印数组的键和值,中间用/t制表符分割,美化一下。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-n10awk'BEGIN{printf ("http_code/tcount_num/n")}{COUNT[$10]++}END{for (a in COUNT) printf a"/t/t"COUNT[a]"/n"}'

2.查找请求数请20个IP(常用于查找攻来源):netstat-anlp|grep80|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 port80-c1000|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|grep80|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-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(code in counts) print code, counts[code]}'cat access.log|awk'{print $9}'|sort|uniq-c|sort-rn

11.每秒并发:awk'{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}'|sort-k2-nr|head-n10

12.带宽统计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"}'

13.统计对象数量及对象平均大小cat access.log|awk'{byte+=$10}END{ print byte/NR/1024,NR}'cat access.log|awk'{if($9~/200|30/)COUNT[$NF]++}END{for( a in COUNT) print a,COUNT

[a],NR,COUNT[a]/NR*100"%"}

14.取5分钟日志if[$DATE_MINUTE!=$DATE_END_MINUTE];then#则判断开始时间戳与结束时间戳是否相等START_LINE=`sed -n "/$DATE_MINUTE/=" $APACHE_LOG|head -n1`#如果不相等,则取出开始时间戳的行号,与结束时间戳的行号#END_LINE=`sed -n "/$DATE_END_MINUTE/=" $APACHE_LOG|tail -n1`END_LINE=`sed -n "/$DATE_END_MINUTE/=" $APACHE_LOG|head -n1`sed-n"${START_LINE},${END_LINE}p"$APACHE_LOG>$MINUTE_LOG##通过行号,取出5分钟内的日志内容 存放到 临时文件中GET_START_TIME=`sed -n "${START_LINE}p" $APACHE_LOG|awk -F '[' '{print $2}' |awk '{print $1}'|

sed 's#/# #g'|sed 's#:# #'`#通过行号获取取出开始时间戳GET_END_TIME=`sed -n "${END_LINE}p" $APACHE_LOG|awk -F '[' '{print $2}' |awk '{print $1}'|sed

's#/# #g'|sed 's#:# #'`#通过行号获取结束时间戳

10.蜘蛛分析

查看是哪些蜘蛛在抓取内容。/usr/sbin/tcpdump-i eth0-l-s0-w-dst port80|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-s0-l-w-dst port3306|strings|egrep-i'SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL'

系统Debug分析篇

1.调试命令

strace -p pid

2.跟踪指定进程的PID

gdb -p pid

更多的请参考:

批量解压tar文件

for tar in *.tar.gz;do tar zxvf $tar;done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值