以前一直對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