Linux Web server site failure analysis common command

  • 2020-05-12 06:40:03
  • OfStack

Linux Web server site failure analysis, the details are as follows

System connection status:

1. Check the TCP connection status


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]}'  or 
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. The number of search requests is 20 IP (often used to find attack sources) :


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. Sniff port 80 access with tcpdump to see who is the highest

tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20

4. Find more time_wait connections

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

5. Look for the most frequent SYN connection

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

6. Process by port

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

Blog analysis part 1 (Apache) :

1. Get access to the top 10 ip addresses


cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10
cat access.log|awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}'


2. Take the top 20 files or pages with the most visits

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

3. List the largest exe files to transfer (often used when analyzing download sites)

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

4. List the exe files with output greater than 200000byte(about 200kb) and the corresponding file occurrence times

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

5. If the last column of the log records the page file transfer time, then the most time-consuming pages to the client are listed

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

6. List the most time-consuming pages (those over 60 seconds) and the number of page occurrences

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

7. List files that took more than 30 seconds to transfer

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

8. Website traffic statistics (G)

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

Count 404 connections

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

10. Statistics 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. Spider analysis to see which spiders are grabbing the content.

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

Daily site analysis 2(Squid) counts traffic by domain

zcat squid_access.log.tar.gz| awk '{print $10,$7}' |awk 'BEGIN{FS="[ /]"}{trfc[$4]+=$1}END{for(domain in trfc){printf "%st%dn",domain,trfc[domain]}}'

Database article

1. View sql for database execution

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

System Debug analysis

1. Debug commands

strace -p pid

2. Track PID of the specified process

gdb -p pid


Related articles: