以前一直对tcp keepalive选项理解有误,html
觉得经过setsockopt函数设置SO_KEEPALIVE和相关参数后该socket则使用设置的keepalive相关参数redis
不然使用系统默认的:keepalive配置(以下)服务器
root@xxx-KVM:/# sysctl -a | grep keep
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_time = 90socket
今天忽然发现redis服务器上存在大量死连接(不少都是几个月前的链接),检查配置,未设置keepalive选项,系统默认(7200,9,75)tcp
通过google查询出keepalive选项开启才行,系统默认的只是keepalive默认开启后配置值;函数
"Remember that keepalive support, even if configured in the kernel, is not the default behavior in Linux. Programs must request keepalive control for their sockets using the setsockopt interface. There are relatively few programs implementing keepalive, but you can easily add keepalive support for most of them following the instructions explained later in this document."this
详细介绍请看:http://tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/google