同事说系统越来越慢,出现一堆TIME_WAIT,是以前的几十倍,是否跟这个有关系。
上去看看什么情况。
[[email protected] ~]$ netstat -ntal #一堆TIME_WAIT没释放,几乎由程序本身发起。 tcp 0 0 ::ffff:127.0.0.1:60110 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60303 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60329 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60088 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60044 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60359 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60132 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60306 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60061 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60101 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60083 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60243 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60035 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60080 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60198 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60151 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60003 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60070 ::ffff:127.0.0.1:28080 TIME_WAIT tcp 0 0 ::ffff:127.0.0.1:60189 ::ffff:127.0.0.1:28080 TIME_WAIT [[email protected] ~]$ netstat -ntal |awk ‘{print $6}‘|sort |uniq -c |sort -nr 10558 TIME_WAIT #这个数量多的不太正常。 23 ESTABLISHED #这里连接数少是做了缓存,命中率达98%以上,很少穿透进来。 [[email protected] ~]$ cat /etc/issue #操作系统版本不一样,内核参数也有些变化。 CentOS release 6.3 (Final) Kernel \r on an \m
/etc/sysctl.conf 配置文件末尾添加如下3个参数,然后执行 /sbin/sysctl -p
让参数生效。
net.ipv4.tcp_tw_reuse = 1 #允许TIME-WAIT sockets重新用于新的TCP连接,默认为0。 net.ipv4.tcp_tw_recycle = 1 #开启TCP连接中TIME-WAIT sockets的快速回收,默认为0。 net.ipv4.tcp_fin_timeout = 20 #修改默认的 TIMEOUT 时间。
接着看下TIME_WAIT数量,恢复正常。
[[email protected] ~]$ netstat -ntal |awk ‘{print $6}‘|sort |uniq -c |sort -nr 54 TIME_WAIT 25 ESTABLISHED
现在访问系统变得非常快。
现将这3个参数加入系统初始化脚本,但以后程序出现这种情况不易被发现,如何监控值得考虑。
能不动内核参数,最好别动,很多情况下默认已够用,切忌为了优化而优化。目前这只是暂时解决问题,治标不治本。
最后还需联系开发一起排查问题原因~
TIME_WAIT导致系统越来越慢,布布扣,bubuko.com
时间: 2024-07-31 14:34:43