答案1
您可能需要检查netstat
标记为TIME_WAIT
以下是两条建议:
建议 1
尝试让所有 mysqlTIME_WAIT
连接更快地断开
在所有数据库和 Web 服务器上运行这些命令
SEC_TO_TIMEWAIT=0
echo ${SEC_TO_TIMEWAIT} > /proc/sys/net/ipv4/tcp_tw_recycle
echo ${SEC_TO_TIMEWAIT} > /proc/sys/net/ipv4/tcp_tw_reuse
建议 #2
跟踪每个 Web 服务器的所有 mysql 连接
创建一个名为 /root/ShowMySQLConnections.sh 的脚本并包含以下行
netstat | grep mysql > /root/mysql_netstat.txt
cat /root/mysql_netstat.txt | awk '{print $5}' | sed 's/:/ /' | awk '{print $1}' | sort -u | grep -v local > /root/mysql_netstat_iplist.txt
for IP in `cat /root/mysql_netstat_iplist.txt`
do
ESCOUNT=`cat /root/mysql_netstat.txt | grep ESTABLISHED | awk '{print $5}' | grep -c "${IP}"`
TWCOUNT=`cat /root/mysql_netstat.txt | grep TIME_WAIT | awk '{print $5}' | grep -c "${IP}"`
IPPAD=`echo "${IP}........................................" | cut -b -40`
(( ESCOUNT += 1000000 ))
(( TWCOUNT += 1000000 ))
ES=`echo ${ESCOUNT} | cut -b 3-`
TW=`echo ${TWCOUNT} | cut -b 3-`
echo ${IPPAD} : ESTABLISHED:${ES} TIME_WAIT:${TW}
done
echo ; echo
netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n | sed 's/d)/d/'
结语
终止TIME_WAIT
连接后,运行watch /root/ShowMySQLConnections.sh
并查看 TIME_WAIT 是否消失。