How to solve the problem of a large number of TIME WAIT under linux
Today Xiaobian to share with you a lot of TIME WAIT under linux how to solve the problem of related knowledge points, detailed content, clear logic, I believe that most people are still too familiar with this knowledge, so share this article for everyone to refer to, I hope you read this article after some harvest, let's learn about it together.
Problem Description:
In a highly concurrent squid server in linux, the number of tcp time_wait sockets often reaches twenty or thirty thousand, and the server is easily dragged to death.
Solution:
By modifying linux kernel parameters, you can reduce the number of ime_wait sockets on linux servers.
vi /etc/sysctl.conf
Add the following lines:
The copy code is as follows:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
Description:
net.ipv4.tcp_syncookies = 1 means syn cookies are turned on. When syn waiting queue overflow occurs, enable cookies to handle, can prevent a small number of syn attacks, default is 0, means closed;
net.ipv4.tcp_tw_reuse = 1 means reuse is enabled. Allow time-wait sockets to be reused for new tcp connections. Default is 0, which means closed.
net.ipv4.tcp_tw_recycle = 1 means to enable quick recycling of time-wait sockets in tcp connections, default is 0, means to disable.
net.ipv4.tcp_fin_timeout = 30 indicates that this parameter determines how long the socket stays in fin-wait-2 if it is requested to be closed locally.
net.ipv4.tcp_keepalive_time = 1200 indicates how often tcp sends keepalive messages when keepalive is active. The default is 2 hours, changed to 20 minutes.
net.ipv4.ip_local_port_range = 1024 65000 indicates the range of ports used for outbound connections. Small by default: 32768 to 61000, changed to 1024 to 65000.
net.ipv4.tcp_max_syn_backlog = 8192 indicates the length of the syn queue, the default is 1024, increase the queue length to 8192, can accommodate more network connections waiting for connection.
net.ipv4.tcp_max_tw_buckets = 5000 indicates the maximum number of time_wait sockets that the system can hold at a time. If this number is exceeded, the time_wait socket will be immediately cleared and a warning message will be printed. Default is 180000, changed to 5000. For apache, nginx and other servers, the parameters in the first few lines can reduce the number of time_wait sockets very well, but for squid, the effect is not great. This parameter controls the maximum number of time_wait sockets to prevent squid servers from being dragged down by a large number of time_wait sockets.
Execute the following command to make the configuration effective:
/sbin/sysctl -p
The above is "how to solve a lot of TIME WAIT problems under linux" all the contents of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.