Transferred from Sir Zhang's blog: http://freeze.blog.51cto.com/1846439/829728
System Connection Status Chapter:
1. View 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]}‘ 或
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. Find the number of requests 20 IP (commonly used to find the source of attack):
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 80-port access with tcpdump to see who is the tallest
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. Check for more SYN connections
netstat -an | grep SYN | awk ‘{print $5}‘ | awk -F: ‘{print $1}‘ | sort | uniq -c | sort -nr | more
6. Depending on the port column process
netstat -ntlp | grep 80 | awk ‘{print $7}‘ | cut -d/ -f1
Website Log Analysis 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. Most visited files or pages, take the top 20
cat access.log|awk ‘{print $11}‘|sort|uniq -c|sort -nr|head -20
3. List the maximum number of EXE files to be transmitted (commonly used when analyzing the download station)
cat access.log |awk ‘($7~/.exe/){print $10 " " $1 " " $4 " " $7}‘|sort -nr|head -20
4. list exe files with output greater than 200000byte (approx. 200kb) and the number of corresponding file occurrences
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 paging file transfer time, there are the most time-consuming pages listed to the client
cat access.log |awk ‘($7~/.php/){print $NF " " $1 " " $4 " " $7}‘|sort -nr|head -100
6. List the most time-consuming pages (more than 60 seconds) and the number of corresponding page occurrences
cat access.log |awk ‘($NF > 60 && $7~/.php/){print $7}‘|sort -n|uniq -c|sort -nr|head -100
7. List files that have been transmitted for longer than 30 seconds
cat access.log |awk ‘($NF > 30){print $7}‘|sort -n|uniq -c|sort -nr|head -20
8. Statistics website Traffic (G)
cat access.log |awk ‘{sum+=$10} END {print sum/1024/1024/1024}‘
9. Statistics 404 of the Connection
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
10. Spider analysis to see which spiders are crawling 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‘
Database Chapter
1. View SQL executed by the database
/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 Chapter
1. Debug commands
strace -p pid
2. Tracking the PID of the specified process
gdb -p pid
awk high-end applications in the production environment