TCP keepalive状态监控

# 查看当前TCP状态
netstat -an | awk '/^tcp/ {++y[$NF]} END {for(w in y) print w, y[w]}'
# 查看keepalive的三个属性
sysctl -a | grep keepalive

# 默认值(可根据具体情况调优)
net.ipv4.tcp_keepalive_time = 7200 # 存活时间
net.ipv4.tcp_keepalive_probes = 9  # 试探次数
net.ipv4.tcp_keepalive_intvl = 75  # 试探间隔

# 更改命令
sysctl -w net.ipv4.tcp_keepalive_time=1800
echo 1800 >/proc/sys/net/ipv4/tcp_keepalive_time # 功能同上

若希望永久生效

vim /etc/sysctl.conf 

# 加入如下命令
net.ipv4.tcp_keepalive_time = 1800 
net.ipv4.tcp_keepalive_probes = 3 
net.ipv4.tcp_keepalive_intvl = 30

编辑完 /etc/sysctl.conf,要重启network 才会生效

# 重启命令
/etc/rc.d/init.d/network restart 

service network restart

你可能感兴趣的:(Linux)