MySQLの大量TIME_WAIT現象を解決する方法
1.エラー現象
MySQLがよく落ちた、netstatを実行
[admin@server5 ~]$ netstat -an | grep 3306 | grep 'ESTABLISHED’|wc -l
33
[admin@server5 ~]$ netstat -an | grep 3306 | grep 'TIME_WAIT’|wc -l
1677
2.Linuxサーバーにログインして、MySQLプロセスを調べる
netstat -ae |grep mysql
tcp 0 0 aaaa:53045 192.168.12.25:mysql TIME_WAIT root 0
tcp 0 0 aaaa:53044 192.168.12.25:mysql TIME_WAIT root 0
tcp 0 0 aaaa:53051 192.168.12.25:mysql TIME_WAIT root 0
tcp 0 0 aaaa:53050 192.168.12.25:mysql TIME_WAIT root 0
tcp 0 0 aaaa:53049 192.168.12.25:mysql TIME_WAIT root 0
tcp 0 0 aaaa:53048 192.168.12.25:mysql TIME_WAIT root 0
tcp 0 0 aaaa:53055 192.168.12.25:mysql TIME_WAIT root 0
tcp 0 0 aaaa:53054 192.168.12.25:mysql TIME_WAIT root 0
……省略…….
3.解決対策
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 」を実行して、設定は有効にする
修正後
netstat -ae|grep mysql
tcp 0 0 aaaa:50408 192.168.12.25:mysql ESTABLISHED nobody 3224651
tcp 0 0 aaaa:50417 192.168.12.25:mysql ESTABLISHED nobody 3224673
tcp 0 0 aaaa:50419 192.168.12.25:mysql ESTABLISHED nobody 3224675