Solution to apache time_wait problem of too many connections

  • 2020-05-10 23:18:02
  • OfStack

Recently, it was found that there were too many connections between apache and load balancer, and most of them were time_wait. After adjusting apache2.conf, there was no effect.

By adjusting the kernel parameters:


vi /etc/sysctl.conf

Edit the file to add the following:


net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

Then, execute /sbin/ sysctl-p for the parameters to take effect.

net.ipv4.tcp_syncookies = 1 means syn cookies is turned on. When syn waiting queue overflow occurs, cookies is enabled for processing, which can prevent a small number of syn attacks. The default value is 0, indicating shutdown.


net.ipv4.tcp_tw_reuse = 1 Represents enabling reuse. Allows you to time-wait sockets Reapply to new tcp Connection, default is 0 Is closed;
net.ipv4.tcp_tw_recycle = 1 According to open tcp In the connection time-wait sockets Quick recycle, default is 0 , means closed.
net.ipv4.tcp_fin_timeout Modify the line jin's default timeout time

This solves the problem of too many connections to apache time_wait.


Related articles: