在默认安装的apache中,keepalive部分没有On,每次请求都要建立新的tcp连接,也不能及时的释放连接,增加了很多time_wait的状态并且系统没有重用,apache进程总数比较大,导致默认安装的服务器压力很大,几近假死!
修改内核参数:/etc/sysctl.conf
net.ipv4.tcp_syncookies = 1
开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;
net.ipv4.tcp_tw_reuse = 1
允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
net.ipv4.tcp_tw_recycle = 1
开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭。
net.ipv4.tcp_fin_timeout=15
如果套接字由本端要求关闭,此参数决定了它保持在FIN-WAIT-2状态的时间。
net.ipv4.tcp_keepalive_probes=2
TCP发送keepalive探测以确定该连接已经断开的次数。可以设置为5左右
net.ipv4.tcp_keepalive_intvl=2
当探测没有确认时,重新发送探测的频度。可以设置为15左右
对apache加以修改:
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 2000
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15
/proc/sys/net/ipv4下可以看到可以修改的内核参数,不懂的可以直接复制参数名称,google之。
专注于 服务器运维与web架构
E-mail:venus#rootop.org