1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 服务器系统日志有哪些centos CentOS 分析服务器日志命令

服务器系统日志有哪些centos CentOS 分析服务器日志命令

时间:2023-09-01 01:09:54

相关推荐

服务器系统日志有哪些centos CentOS 分析服务器日志命令

# 分析日志文件下 -05-04 访问页面最高 的前20个 URL 并排序

cataccess.log |grep '04/May/'| awk '{print $11}'|sort|uniq -c|sort -nr|head -20

# 查询受访问页面的URL地址中 含有 网址的 IP 地址

cataccess_log | awk '($11~//){print $1}'|sort|uniq -c|sort -nr

# 获取访问最高的10个IP地址 同时也可以按时间来查询

catlinewow-access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10

# 时间段查询日志时间段的情况

catlog_file | egrep '15/Aug/|16/Aug/' |awk '{print $1}'|sort|uniq -c|sort -nr|head -10

# 分析/8/15 到 /8/16 访问"/index.php?g=Member&m=Public&a=sendValidCode"的IP倒序排列

catlog_file | egrep '15/Aug/|16/Aug/' | awk '{if($7 == "/index.php?g=Member&m=Public&a=sendValidCode") print $1,$7}'|sort|uniq -c|sort -nr

# ($7~/.php/) $7里面包含.php的就输出,本句的意思是最耗时的一百个PHP页面

catlog_file |awk '($7~/.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100

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

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

# 统计网站流量(G)

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

# 统计404的连接

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

# 统计http status

cataccess.log |awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}'

cataccess.log |awk '{print $9}'|sort|uniq -c|sort -rn

# 每秒并发

watch "awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' log_file|sort -k 2 -nr|head -n10"

# 带宽统计

catapache.log |awk '{if($7~/GET/) count++}END{print "client_request="count}'

catapache.log |awk '{BYTE+=$11}END{print "client_kbyte_out="BYTE/1024"KB"}'

# 找出某天访问次数最多的10个IP

cat /tmp/access.log | grep "20/Mar/" |awk '{print $3}'|sort |uniq -c|sort -nr|head

# 当天ip连接数最高的ip都在干些什么

cataccess.log | grep "10.0.21.17" | awk '{print $8}' | sort | uniq -c | sort -nr | head -n 10

# 小时单位里ip连接数最多的10个时段

awk -vFS="[:]" '{gsub("-.*","",$1);num[$2" "$1]++}END{for(i in num)print i,num[i]}' log_file | sort -n -k 3 -r | head -10

# 找出访问次数最多的几个分钟

awk '{print $1}' access.log | grep "20/Mar/" |cut -c 14-18|sort|uniq -c|sort -nr|head

# 取5分钟日志

if [ $DATE_MINUTE != $DATE_END_MINUTE ] ;then

# 则判断开始时间戳与结束时间戳是否相等

START_LINE=sed -n "/$DATE_MINUTE/=" $APACHE_LOG|head -n1

# 如果不相等,则取出开始时间戳的行号,与结束时间戳的行号

# 查看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

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

awk 'BEGIN{printf ("http_codetcount_numn")}{COUNT[$10]++}END{for (a in COUNT) printf a"tt"COUNT[a]"n"}'

# 查找请求数前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

# 用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

# 查找较多time_wait连接

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

# 找查较多的SYN连接

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

# 根据端口列进程

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

# 查看了连接数和当前的连接数

netstat -ant | grep $ip:80 | wc -l

netstat -ant | grep $ip:80 | grepEST | wc -l

# 查看IP访问次数

netstat -nat|grep ":80"|awk '{print $5}' |awk -F: '{print $1}' | sort| uniq -c|sort -n

# Linux命令分析当前的链接状况

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

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

# 通过watch可以一直监控

LAST_ACK 5

# 关闭一个TCP连接需要从两个方向上分别进行关闭,双方都是通过发送FIN来表示单方向数据的关闭,当通信双方发送了最后一个FIN的时候,发送方此时处于LAST_ACK状态,当发送方收到对方的确认(Fin的Ack确认)后才真正关闭整个TCP连接

SYN_RECV 30

# 表示正在等待处理的请求数

ESTABLISHED 1597

# 表示正常数据传输状态

FIN_WAIT1 51

# 表示server端主动要求关闭tcp连接

FIN_WAIT2 504

# 表示客户端中断连接

TIME_WAIT 1057

# 表示处理完毕,等待超时结束的请求数

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。