CentOS solves the problem of a large number of time_wait servers. centostime_wait

Source: Internet
Author: User

CentOS solves the problem of a large number of time_wait servers. centostime_wait

Recently, a large number of time_wait TCP connections have occurred on the server, resulting in excessive server connections, which eventually leads to tomcat suspended. The following message is displayed when you view the number of connections on the server.

[root@test apache-tomcat-7.0.53]# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' TIME_WAIT 14434FIN_WAIT2 6ESTABLISHED 133
Obviously, requests are too frequent, mainly because the backend servers call each other through rest requests, while the java Server recycles tcp threads slowly, although the connection has been closed explicitly

Connection recovery is slow. The way to solve this problem through java APIs is blocked.

Later, I went to the server to check a large amount of information and considered modifying the Linux kernel to solve the problem. The solution is as follows:

vi /etc/sysctl.conf

Add configuration information

# Enable SYN Cookies. When a SYN wait queue overflows, cookies are enabled to prevent a small number of SYN attacks. The default value is 0, indicating to disable net. ipv4.tcp _ syncookies = 1 #. This indicates to Enable reuse of tcp connections. Allow TIME-WAIT sockets to be re-used for a New TCP connection. The default value is 0, indicating to disable net. ipv4.tcp _ tw_reuse = 1 #. This indicates to enable the fast recovery of TIME-WAIT sockets in TCP connections. The default value is 0, indicating that net is disabled. ipv4.tcp _ tw_recycle = 1 # indicates that if the socket is disabled by the local end, this parameter determines the time for it to remain in the FIN-WAIT-2 state. net. ipv4.tcp _ fin_timeout = 30
Make the parameter configuration take effect

/sbin/sysctl -p
Returned results


Perfect solution:

[root@test apache-tomcat-7.0.53]# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' TIME_WAIT 96FIN_WAIT2 3ESTABLISHED 141


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.