服务器 es 或增加 nginx 要想增加处理能力,调整 TCP 连接数可以通过修改操作系统的TCP参数来实现,以下是具体操作步骤,在此做下记录:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
net.ipv4.tcp_max_tw_buckets = 5000-->50000 net.ipv4.tcp_max_syn_backlog = 128--> 4096 net.core.somaxconn = 128-->4096 net.ipv4.tcp_tw_reuse = 0-->1 net.ipv4.tcp_timestamps =0--> 1 net.ipv4.tcp_tw_recycl net.ipv4.ip_local_port_range =默认--》 15000 65000 DefaultLimitNOFILE=1024-->102400 此外,如果用的是Nginx,尝试参考下面修改一下 worker_connections 1024-->10240; worker_processes 1-->16; worker_rlimit_nofile 1024-->102400;
示例如下:
net.ipv4.tcp_max_tw_buckets = 50000 net.ipv4.tcp_max_syn_backlog = 4096 net.core.somaxconn = 4096 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_timestamps = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.tcp_wmem = 4096 87380 4161536 net.ipv4.tcp_rmem = 4096 87380 4161536 net.ipv4.tcp_mem = 786432 2097152 3145728 fs.file-max = 1000000 #DefaultLimitNOFILE=102400
DefaultLimitNOFILE=150000 DefaultLimitNPROC=150000
cat /proc/sys/fs/file-max
session required /lib/security/pam_limits.so
lsof -p xx | wc -l
* soft nofile 1000000 * hard nofile 1000000 * soft nproc 1000000 * hard nproc 1000000
ethtool -l eth0