linux sysctl 配置优化SS调优
fs.file-max = 51200
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.core.rmem_default = 65536
net.core.wmem_default = 65536
net.core.netdev_max_backlog = 4096
net.core.somaxconn = 4096
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
net.ipv4.tcp_mtu_probing = 1
# for high-latency network
net.ipv4.tcp_congestion_control = hybla
# for low-latency network, use cubic instead
# net.ipv4.tcp_congestion_control = cubic
100万连接测试所需的Linux内核参数,网络协议栈参数,参数设置如下
fs.file-max=2097152
fs.nr_open=2097152
net.core.somaxconn=32768
net.ipv4.tcp_max_syn_backlog=16384
net.core.netdev_max_backlog=16384
net.ipv4.ip_local_port_range=1024 65535
net.core.rmem_default=262144
net.core.wmem_default=262144
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.core.optmem_max=16777216
net.ipv4.tcp_rmem=1024 4096 16777216
net.ipv4.tcp_wmem=1024 4096 16777216
net.nf_conntrack_max=1000000
net.netfilter.nf_conntrack_max=1000000
net.netfilter.nf_conntrack_tcp_timeout_time_wait=30
net.ipv4.tcp_max_tw_buckets=1048576
net.ipv4.tcp_fin_timeout = 15
# 注意: 不建议开启該设置,NAT模式下可能引起连接RST
# net.ipv4.tcp_tw_recycle = 1
# net.ipv4.tcp_tw_reuse = 1
echo "net.ipv4.tcp_mem = 786432 2097152 3145728" >> /etc/sysctl.conf
LVS长连接优化
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.core.netdev_max_backlog = 250000
net.core.somaxconn = 4096
net.ipv4.tcp_mem = 25600 51200 102400
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_keepalive_time=1800
CentOS7 VPS服务器的配置(1G内存) 20170610
###
--- /etc/sysctl.conf ---
net.ipv6.conf.all.accept_ra = 2
net.ipv6.conf.eth0.accept_ra = 2
net.ipv4.ip_forward = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 4096 65000
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_max_syn_backlog = 4096
net.core.netdev_max_backlog = 10240
net.core.somaxconn = 2048
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_mem = 177945 216076 254208
net.ipv4.tcp_fastopen = 3
fs.file-max = 50000000
------------------------
### 参数详解
net.ipv4.tcp_syncookies = 1 #1是开启SYN Cookies,当出现SYN等待队列溢出时,启用Cookies来处理,可防范少量SYN攻击,默认是0关闭
net.ipv4.tcp_tw_reuse = 1 #1是开启重用,允许将TIME_AIT sockets重新用于新的TCP连接,默认是0关闭
net.ipv4.tcp_tw_recycle = 1 #TCP失败重传次数,默认是15,减少次数可释放内核资源
net.ipv4.ip_local_port_range = 4096 65000 #应用程序可使用的端口范围
net.ipv4.tcp_max_tw_buckets = 5000 #系统同时保持TIME_WAIT套接字的最大数量,如果超出这个数字,TIME_WATI套接字将立刻被清除并打印警告信息,默认180000
net.ipv4.tcp_max_syn_backlog = 4096 #进入SYN包的最大请求队列,默认是1024
net.core.netdev_max_backlog = 10240#允许送到队列的数据包最大设备队列,默认300
net.core.somaxconn = 2048 #listen挂起请求的最大数量,默认128
net.core.wmem_default = 8388608 #发送缓存区大小的缺省值(单位: byte)
net.core.rmem_default = 8388608 #接受套接字缓冲区大小的缺省值(单位: byte)
net.core.rmem_max = 16777216 #最大接收缓冲区大小的最大值(单位: byte)
net.core.wmem_max = 16777216 #发送缓冲区大小的最大值(单位: byte)
net.ipv4.tcp_synack_retries = 2 #SYN-ACK握手状态重试次数,默认5
net.ipv4.tcp_syn_retries = 2 #向外SYN握手重试次数,默认4
net.ipv4.tcp_tw_recycle = 1 #开启TCP连接中TIME_WAIT sockets的快速回收,默认是0关闭
net.ipv4.tcp_max_orphans = 3276800 #系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上,如果超出这个数字,孤儿连接将立即复位并打印警告信息
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_mem[0]: 低于此值,TCP没有内存压力; # 80% Mem
net.ipv4.tcp_mem[1]: 在此值下,进入内存压力阶段; # 90% Mem
net.ipv4.tcp_mem[2]: 高于此值,TCP拒绝分配socket; # 100% Mem
内存单位是页(1页=4kb),可根据物理内存大小进行调整,如果内存足够大的话,可适当往上调.
net.ipv4.tcp_fastopen = 3 # 3.7版本以上的内核才支持,须客户端,服务器同时开启; 多用于shadowsocks