在做压力测试的时候,客户端连接服务器,在连接超过1024的时候,剩下的就连接不上了,后来各种搜索才知道原来linux对tcp的最大连接数是有限制的。
查询连接数
[root@localhost ~]# ulimit -n
1024
修改连接数,修改完需要重启
[root@localhost ~]# vim /etc/security/limits.conf
* soft nofile 1048576
* hard nofile 1048576
查看最大打开文件数
[root@localhost ~]# sysctl -a|grep file-max
fs.file-max = 1048576
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.enp0s31f6.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
sysctl: reading key "net.ipv6.conf.virbr0.stable_secret"
sysctl: reading key "net.ipv6.conf.virbr0-nic.stable_secret"
修改最大打开文件数
[root@localhost ~]# vim /etc/sysctl.conf
fs.file-max = 1048576
调整其他网络和TCP设置
[root@localhost ~]#
sysctl -w net.core.somaxconn=32768
sysctl -w net.ipv4.tcp_max_syn_backlog=16384
sysctl -w net.core.netdev_max_backlog=16384
sysctl -w net.ipv4.ip_local_port_range='1000 65535'
sysctl -w net.core.rmem_default=262144
sysctl -w net.core.wmem_default=262144
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
sysctl -w net.core.optmem_max=16777216
sysctl -w net.ipv4.tcp_rmem='1024 4096 16777216'
sysctl -w net.ipv4.tcp_wmem='1024 4096 16777216'
sysctl -w net.nf_conntrack_max=1000000
sysctl -w net.netfilter.nf_conntrack_max=1000000
sysctl -w net.netfilter.nf_conntrack_tcp_timeout_time_wait=30
sysctl -w net.ipv4.tcp_max_tw_buckets=1048576
sysctl -w net.ipv4.tcp_fin_timeout=15
立即生效
sysctl -p
网友评论