#num1 1. 编写监控脚本 tcp_statistics.sh echo `date +"%F %H:%M:%S"` "TCP-ALL" `netstat -anotp |awk '/tcp/ {print $6}'|wc -l` >> tcp_count.txt echo `date +"%F %H:%M:%S"` "TCP-LISTEN" `netstat -anotp|grep "LISTEN" |wc -l` >>tcp_count.txt echo `date +"%F %H:%M:%S"` "TCP-ESTABLISHED" `netstat -anotp | grep "ESTABLISHED" |wc -l ` >> tcp_count.txt echo `date +"%F %H:%M:%S"` "TCP_TIME_WAIT" `netstat -anotp |grep "TIME_WAIT" |wc -l ` >> tcp_count.txt echo `date +"%F %H:%M:%S"` "TCP_CLOSE_WAIT" `netstat -anotp |grep "CLOSE_WAIT" |wc -l` >> tcp_count.txt 2. 更改文件权限 chmod 777 tcp_statistics.sh 3. 加入定时任务 crontab -e */1 * * * * sh /root/tcp_statistics.sh 3. 重启定时服务 service crond restart ------------------------------ #num2 ss监控 /usr/sbin/ss state all | awk '{++S[$1]} END {for (a in S) {printf "%11-s %s\n",a,S[a]}}' LISTEN 9 ESTAB 1 State 1 TIME-WAIT 110 ----------------------------- #num3 netstat监控 /bin/netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}' LISTEN 9 ESTABLISHED 1 SYN_SENT 1 TIME_WAIT 126 ---------------------------- #num4 脚本监控