标签:
1 [root@ok /]# cat /proc/sys/net/ipv4/tcp_keepalive_time 2 7200 3 如果在该参数指定时间内某条连接处于空闲状态,则内核向远程主机发起探测 4 [root@ok /]# cat /proc/sys/net/ipv4/tcp_keepalive_intvl 5 75 6 内核向远程主机发送的保活探测的时间间隔 7 [root@ok /]# cat /proc/sys/net/ipv4/tcp_keepalive_probes 8 9 9 内核发送保活探测的最大次数,如果探测次数大于这个数,则断定远程主机不可达,则关闭该连接并释放本地资源 10 一个连接7200s空闲后,内核会每隔75秒去重试,若连续9次则放弃。这样就导致一个连接经过2h11min的时间才能被丢弃,降低该值能够尽量减小 11 失效连接所占用的资源,而被新的连接所使用。 12 TCP协议中有长连接和短连接之分。短连接在数据包发送完成后就会自己断开,长连接在发包完毕后,会在一定的时间内保持连接,即我们通常所说的Keepalive(存活定时器)功能。 13 [root@ok etc]# sysctl -w net.ipv4.tcp_keepalive_time=160 14 net.ipv4.tcp_keepalive_time = 160 15 [root@ok etc]# sysctl -w net.ipv4.tcp_keepalive_intvl=30 16 net.ipv4.tcp_keepalive_intvl = 30 17 [root@ok etc]# sysctl -w net.ipv4.tcp_keepalive_probes=2 18 net.ipv4.tcp_keepalive_probes = 2 19 [root@ok etc]# cat /proc/sys/net/ipv4/tcp_keepalive_time 20 160 21 [root@ok etc]# cat /proc/sys/net/ipv4/tcp_keepalive_intvl 22 30 23 [root@ok etc]# cat /proc/sys/net/ipv4/tcp_keepalive_probes 24 2 25 但这种方法从启后,就失效。下面的方法永处保存: 26 直接在/etc/sysctl.conf 中加加入以下参数: 27 [root@ok etc]# cat /etc/sysctl.conf |egrep ‘(keepalive_time|keepalive_intvl|keepalive_probes)‘ 28 net.ipv4.tcp_keepalive_time = 160 29 net.ipv4.tcp_keepalive_intvl = 30 30 net.ipv4.tcp_keepalive_probes = 3 31 然后sysctl -p使参数生效: 32 [root@ok etc]# sysctl -p 33 net.ipv4.ip_forward = 0 34 net.ipv4.conf.default.rp_filter = 1 35 net.ipv4.conf.default.accept_source_route = 0 36 kernel.sysrq = 0 37 kernel.core_uses_pid = 1 38 net.ipv4.tcp_syncookies = 1 39 net.ipv4.tcp_keepalive_time = 160 40 net.ipv4.tcp_keepalive_intvl = 30 41 net.ipv4.tcp_keepalive_probes = 3 42 kernel.msgmnb = 65536 43 kernel.msgmax = 65536 44 kernel.shmmax = 68719476736 45 kernel.shmall = 4294967296
标签:
原文地址:http://www.cnblogs.com/bass6/p/5792877.html