阿里云国际站代理商:阿里云怎样调整Keepalive超时时间?

简介:TG@luotuoemo

本文由阿里云代理商【聚搜云】撰写

修改TCP Keepalive参数

  1. 编辑配置文件:使用文本编辑器(如vim)打开/etc/sysctl.conf文件。

    bash

    sudo vim /etc/sysctl.conf
    
  2. 添加或修改参数:在文件中添加或修改以下参数:

    bash

    net.ipv4.tcp_keepalive_time = 120
    net.ipv4.tcp_keepalive_intvl = 30
    net.ipv4.tcp_keepalive_probes = 3
    
    • net.ipv4.tcp_keepalive_time:设置连接空闲多长时间后发送第一个Keepalive探测包,单位为秒。建议设置为120秒。
    • net.ipv4.tcp_keepalive_intvl:设置连续发送Keepalive探测包的时间间隔,单位为秒。建议设置为30秒。
    • net.ipv4.tcp_keepalive_probes:设置在放弃连接前发送的Keepalive探测包数量。建议设置为3。
  3. 应用配置:保存文件后,执行以下命令使配置生效。

    bash

    sudo sysctl -p
    
  4. 验证配置:可以通过以下命令查看当前的TCP Keepalive参数设置。

    bash

    sysctl net.ipv4.tcp_keepalive_time
    sysctl net.ipv4.tcp_keepalive_intvl
    sysctl net.ipv4.tcp_keepalive_probes