回顾了下,关于Linux 的内核相关 TCP 参数的文章,因为是几年前写的,有些地方需要更新,所以重新测试、修改了一下文章,并附上自用的配置文件,供大家参考:
vi /etc/sysctl.conf
#需配合修改 open files 参数,才有效
#fs.file-max = 655360
#开启bbr
net.ipv4.tcp_congestion_control = bbr
net.core.default_qdisc = fq
#关闭rp_filter
#net.ipv4.conf.all.rp_filter = 0
#SSR 对于会出现突发空闲的长周期 TLS 连接有很大影响,所以关闭
net.ipv4.tcp_slow_start_after_idle = 0
#设置为1,当检测到 ICMP 黑洞时启用
net.ipv4.tcp_mtu_probing = 1
#启用fastopen,跳过tcp3次握手
#net.ipv4.tcp_fastopen = 3
#ARP缓存的过期时间(单位毫秒)
#net.ipv4.neigh.default.base_reachable_time_ms = 600000
#在把记录标记为不可达之前,用多播/广播方式解析地址的最大次数
#net.ipv4.neigh.default.mcast_solicit = 20
#重发一个ARP请求前等待毫秒数
#net.ipv4.neigh.default.retrans_time_ms = 250
#Socket缓存配置
net.ipv4.tcp_rmem = 8192 262144 536870912
net.ipv4.tcp_wmem = 4096 16384 536870912
#TCP窗口大小,接收缓冲区可用buffer
net.ipv4.tcp_adv_win_scale = -2
#限制写入队列中未发送字节的大小
net.ipv4.tcp_notsent_lowat = 131072
#关闭IPv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
参考文章:
https://hostalk.net/posts/linux_sysctl.html
https://blog.cloudflare.com/optimizing-tcp-for-high-throughput-and-low-latency