服务器出现kernel: TCP: time wait bucket table overflow解决

http://blog.sina.com.cn/s/blog_69cdee7f0100yowt.html


#一台Nginx+php-fcgi的服务器做了负载均衡,在主控端发现一直在报错:

viewsource print ?
01 #----------------------------引用文字-开始----------------------------
02 Apr 19 14:48:38chengyongxu.com kernel: TCP: time wait buckettable overflow
03 Apr 19 14:48:44chengyongxu.com kernel: printk: 137 messagessuppressed.
04 Apr 19 14:48:44chengyongxu.com kernel: TCP: time wait buckettable overflow
05 Apr 19 14:48:52chengyongxu.com kernel: printk: 251 messagessuppressed.
06 Apr 19 14:48:52chengyongxu.com kernel: TCP: time wait buckettable overflow
07 Apr 19 14:48:53chengyongxu.com kernel: printk: 51 messages suppressed.
08 Apr 19 14:48:53chengyongxu.com kernel: TCP: time wait buckettable overflow
09 Apr 19 14:48:59chengyongxu.com kernel: printk: 119 messagessuppressed.
10 #----------------------------引用文字-结束----------------------------

#再看80端口连接状态

viewsource print ?
01 netstat-an | grep 80 |awk '{print $6}' |sort | uniq-c | sort -rn
02 #----------------------------引用文字-开始----------------------------
03    4202TIME_WAIT
04      30FIN_WAIT1
05       9ESTABLISHED
06       5SYN_RECV
07       4LISTEN
08       4FIN_WAIT2
09       4CLOSING
10       2CONNECTED
11       2
12 #----------------------------引用文字-结束----------------------------

#根据报错提示,需要更改net.ipv4.tcp_max_tw_buckets这个内核参数。这个参数是系统同时保持timewait套接字的最大数量。如果超过这个数字,time-wait套接字将立刻被清除并打印警告信息。这个限制仅仅是为了防止简单的DoS攻击,你绝对不能过分依靠它或者人为地减小这个值,如果网络实际需要大于缺省值,更应该增加这个值(如果增加了内存之后)。

viewsource print ?
01 vi/etc/sysconfig/sysctl.conf
02 #----------------------------引用文字-开始----------------------------
03 #找到:
04 net.ipv4.tcp_max_tw_buckets = 6000
05 #改为
06 net.ipv4.tcp_max_tw_buckets = 10000
07 #----------------------------引用文字-结束----------------------------
08 #保存并打印设置
09 sysctl -p
10   
11 #再看80端口连接状态
12 netstat-an | grep 80 |awk '{print $6}' |sort | uniq-c | sort -rn
13 #----------------------------引用文字-开始----------------------------
14    5928TIME_WAIT
15      42FIN_WAIT1
16      14ESTABLISHED
17      10FIN_WAIT2
18       6CLOSING
19       4SYN_RECV
20       4LISTEN
21       2CONNECTED
22       2
23 #----------------------------引用文字-结束----------------------------
24 netstat-an | grep 80 |awk '{print $6}' |sort | uniq-c | sort -rn
25 #----------------------------引用文字-开始----------------------------
26    5510TIME_WAIT
27      34FIN_WAIT1
28       9SYN_RECV
29       9ESTABLISHED
30       7FIN_WAIT2
31       6CLOSING
32       4LISTEN
33       2CONNECTED
34       2
35 #----------------------------引用文字-结束----------------------------
36 netstat-an | grep 80 |awk '{print $6}' |sort | uniq-c | sort -rn
37 #----------------------------引用文字-开始----------------------------
38    5687TIME_WAIT
39      38FIN_WAIT1
40      16ESTABLISHED
41      10SYN_RECV
42       6FIN_WAIT2
43       6CLOSING
44       4LISTEN
45       2CONNECTED
46       2
47 #----------------------------引用文字-结束----------------------------
48 netstat-an | grep 80 |awk '{print $6}' |sort | uniq-c | sort -rn
49 #----------------------------引用文字-开始----------------------------
50    5688TIME_WAIT
51      38FIN_WAIT1
52      19ESTABLISHED
53       9SYN_RECV
54       6FIN_WAIT2
55       6CLOSING
56       4LISTEN
57       2CONNECTED
58       2
59 #----------------------------引用文字-结束----------------------------

#再看/var/log/messages和dmesg的信息,已经不再报错了,看来net.ipv4.tcp_max_tw_buckets=10000暂时是够用了



你可能感兴趣的:(服务器运维)