在 CentOS 7 上如何以及在哪里配置 TCP keepalive?
我试图找到它:
[michael@devserver ~]$ cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
[michael@devserver ~]$ cat /usr/lib/sysctl.d/* | grep keep
[michael@devserver ~]$ cat /run/sysctl.d/* | grep keep
cat: /run/sysctl.d/*: No such file or directory
[michael@devserver ~]$ cat /etc/sysctl.d/* | grep keep
[michael@devserver ~]$ cat /usr/lib/sysctl.d/* | grep keep
[michael@devserver ~]$ ls /proc/sys/net/ipv4/ | grep tcp_keep
tcp_keepalive_intvl
tcp_keepalive_probes
tcp_keepalive_time
[michael@devserver ~]$ cat /proc/sys/net/ipv4/tcp_keep*
75
9
7200
[michael@devserver ~]$ whereis tcp_keepalive
tcp_keepalive:[michael@devserver ~]$ whereis tcp_keepalived
tcp_keepalived:[michael@devserver ~]$ whereis keepalive
keepalive:[michael@devserver ~]$ whereis keepalived
keepalived:[michael@devserver ~]$ ls /etc | grep keep
[michael@greenbeantech ~]$
答案1
这TCP 保活指南指配置TCP keepalive的两种方法:
procfs 接口
系统控制接口
正如您已经发现的,您可以通过将新数字写入相应的 /proc 文件来更新这些值,例如:
echo 600 > /proc/sys/net/ipv4/tcp_keepalive_time
或通过 sysctl:
sysctl -w net.ipv4.tcp_keepalive_time=600
... 虽然两者都不其中的更改在重新启动后仍然有效。
为了使更改在重新启动后持续存在,您需要将这些值放置在(或通过)中/etc/sysctl.conf
。我面前没有 CentOS 系统,但 /etc/sysctl.conf 可能是从/etc/sysctl.d/
.
我的建议是在 /etc/sysctl.d/ 中创建一个文件,其内容格式如下:
net.ipv4.tcp_keepalive_time=7200
net.ipv4.tcp_keepalive_intvl=75
net.ipv4.tcp_keepalive_probes=9
sysctl 文件按数字顺序读取,因此如果您希望您的值优先,请注意您已经看到的警告:
要仅覆盖特定设置,请在 /etc/sysctl.d/ 中添加一个按词法命名的文件,并在其中放置新设置。