KeepAlive
這裏的keepalive是TCP的探活機制:shell
[root@ ~]# sysctl -a |grep tcp_keepalive net.ipv4.tcp_keepalive_time = 1200 net.ipv4.tcp_keepalive_probes = 9 net.ipv4.tcp_keepalive_intvl = 75
參數解釋:後端
- tcp_keepalive_time 1200 ,tcp創建連接後1200 秒若是無數據傳輸,則會發出探活數據包
- tcp_keepalive_probes 9 , 共發送9次
- tcp_keepalive_intvl 75 ,每次間隔75秒
KeepAlive並非默認開啓的,在Linux系統上沒有一個全局的選項去開啓TCP的KeepAlive。須要開啓KeepAlive的應用必須在TCP的socket中單獨開啓。服務器
TCP socket也有三個選項和內核對應,經過setsockopt系統調用針對單獨的socket進行設置:socket
- TCPKEEPCNT: 覆蓋 tcpkeepaliveprobes
- TCPKEEPIDLE: 覆蓋 tcpkeepalivetime
- TCPKEEPINTVL: 覆蓋 tcpkeepalive_intvl
Nginx
server { listen 127.0.0.1:3306 so_keepalive=on; proxy_pass 172.17.0.3:3306; #創建鏈接時間 proxy_connect_timeout 5s; #保持鏈接時間 proxy_timeout 3600s; error_log /data/logs/my.log info;
so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]tcp
- on: 開啓,探測參數更加系統默認值
- off: 關閉
- keepidle: 等待時間
- keepintvl: 發送探測報文間隔
- keepcent: 探測報文發送次數
proxy_timeout:建連後無數據時與後端服務器鏈接保持時間,默認75s。spa
proxy_connect_timeout:與後端服務器創建鏈接的超時, 不超過75s。code
proxy_send_timeout:向後端服務器組發出write請求後,等待響應的超時間,默認爲60秒。server
proxy_read_timeout:向後端服務器組發出read請求後,等待響應的超時間,默認爲60秒。ip