查看服务器的TCP状态(连接状态数据统计):

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

修改系统配置文件sysctl.conf,减少TCP连接中的TIME-WAIT

vim /etc/sysctl.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 5

net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000

#使配置生效
/sbin/sysctl -p

处理TCP连接中的大量CLOSE-WAIT连接

查看CLOSE-WAIT连接

netstat -tulnap | grep CLOSE_WAIT | sed -e 's/::ffff://g' | awk '{print $4,$5}' | sed 's/:/ /g'

1).杀进程

netstat -nap |grep :8888|grep CLOSE_WAIT | awk -F"\/" '{print $1}' |awk '!a[$1]++'  |xargs kill 

2).重启服务

PS:第二种更有效