CLOSE_WAIT和TIME_WAIT处理
来源:互联网 发布:caffe bene价格 编辑:程序博客网 时间:2024/05/22 01:26
早上登陆服务器的时候输入netstat -an|grep mysql
发现存在大量TIME_WAIT状态的连接
tcp 0 0 127.0.0.1:3306 127.0.0.1:41378 TIME_WAIT
tcp 0 0 127.0.0.1:3306 127.0.0.1:41379 TIME_WAIT
tcp 0 0 127.0.0.1:3306 127.0.0.1:39352 TIME_WAIT
tcp 0 0 127.0.0.1:3306 127.0.0.1:39350 TIME_WAIT
tcp 0 0 127.0.0.1:3306 127.0.0.1:35763 TIME_WAIT
tcp 0 0 127.0.0.1:3306 127.0.0.1:39372 TIME_WAIT
tcp 0 0 127.0.0.1:3306 127.0.0.1:39373 TIME_WAIT
tcp 0 0 127.0.0.1:3306 127.0.0.1:41176 TIME_WAIT
通过调整内核参数解决
vi /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 = 30
然后执行/sbin/sysctl -p让参数生效。
net.ipv4.tcp_syncookies = 1表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;
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修改系統默认的TIMEOUT时间
修改之后,再用命令查看TIME_WAIT连接数
netstat -ae|grep “TIME_WAIT” |wc –l
发现大量的TIME_WAIT 已不存在,mysql进程的占用率很快就降下来的,网站访问正常。
不过很多时候,出现大量的TIME_WAIT状态的连接,往往是因为网站程序代码中没有使用mysql.colse(),才导致大量的mysql TIME_WAIT.
{
sysctl -w net.ipv4.tcp_keepalive_time=30
sysctl -w net.ipv4.tcp_keepalive_probes=2
sysctl -w net.ipv4.tcp_keepalive_intvl=2
sysctl -w net.ipv4.tcp_fin_timeout=30
sysctl -w net.ipv4.tcp_syncookies=1
sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w net.ipv4.tcp_tw_recycle=1
}
What It Means
"Proto" is short for protocol, which is either TCP or UDP. "Recv-Q" and "Send-Q" mean receiving queue and sending queue. These should always be zero; if they're not you might have a problem. Packets should not be piling up in either queue, except briefly, as this example shows:
tcp 0 593 192.168.1.5:34321 venus.euao.com:smtp ESTABLISHED
That happened when I hit the "check mail" button in KMail; a brief queuing of outgoing packets is normal behavior. If the receiving queue is consistently jamming up, you might be experiencing a denial-of-service attack. If the sending queue does not clear quickly, you might have an application that is sending them out too fast, or the receiver cannot accept them quickly enough.
"Local address" is either your IP and port number, or IP and the name of a service. "Foreign address" is the hostname and service you are connected to. The asterisk is a placeholder for IP addresses, which of course cannot be known until a remote host connects. "State" is the current status of the connection. Any TCP state can be displayed here, but these three are the ones you want to see:
- CLOSE_WAIT和TIME_WAIT处理
- CLOSE_WAIT和TIME_WAIT
- CLOSE_WAIT和TIME_WAIT
- time_wait和close_wait
- TIME_WAIT和CLOSE_WAIT(转)
- time_wait和close_wait
- time_wait和close_wait状态
- 服务器 TIME_WAIT和CLOSE_WAIT
- TIME_WAIT和CLOSE_WAIT
- TIME_WAIT和CLOSE_WAIT
- TIME_WAIT和CLOSE_WAIT
- TIME_WAIT和CLOSE_WAIT
- 应用环境下的TIME_WAIT和CLOSE_WAIT处理
- linxu 中大量的close_wait 和 time_wait 处理
- close_wait状态和time_wait状态
- close_wait状态和time_wait状态
- close_wait状态和time_wait状态
- close_wait状态和time_wait状态
- 应用程序的沙盒,应用程序只能访问该目录下的文件夹!!!
- C#获取MAC地址的几种方法(补充版)
- Linux内核启动流程
- 伪列表元素点击后高亮显示方法
- 开发板2440nor flash与nand flash启动的简单比较
- CLOSE_WAIT和TIME_WAIT处理
- lambda()函数
- 给40亿个不重复的unsigned int的整数,没排过序的,然后再给一个数,如何快速判断这个数是否在那40亿个数当中?
- Android系统默认设置
- C# Word操作(转载)
- Linux下 PHP 安装pecl_http方法
- Asp.net .net(C#) 获取当前命名空间,类名,方法名的方法
- CommandName 和 CommandArgument的区别
- linux内核list实现