默认的 Linux 内核参数不符合 web 服务器高并发的要求,Nginx 作为静态 web 内容服务器、反向代理服务器或者提供压缩服务的服务器时,内核参数的调整是不一样的,下面是针对更多并发请求的 TCP 网络做的参数优化
优化内核参数
https://blog.csdn.net/bytxl/article/details/46437363
修改/etc/sysctl.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| fs.file-max = 1000000 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_keepalive_time = 600 net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.tcp_rmem = 10240 87380 12582912 net.ipv4.tcp_wmem = 10240 87380 12582912 net.core.netdev_max_backlog = 8096
net.core.rmem_default = 6291456 net.core.wmem_default = 6291456 net.core.rmem_max = 12582912 net.core.wmem_max = 12582912
net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_max_syn_backlog = 8192 net.ipv4.tcp_tw_recycle = 1 net.core.somaxconn=262114 net.ipv4.tcp_max_orphans=262114
|
张 sir:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| net.ipv4.tcp_max_syn_backlog = 8192 net.ipv4.tcp_syn_retries = 3 tcp_retries1 = 3 tcp_retries2 = 15
net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.tcp_max_orphans= 262114 net.ipv4.tcp_synack_retries= 1 net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 300 net.ipv4.tcp_keepalive_intvl = 30 net.ipv4.tcp_keepalive_probes = 3 net.ipv4.ip_local_port_range = 10001 65000
vm.overcommit_memory = 0 vm.swappiness = 0
|
PAM 资源限制优化
在/etc/security/limits.conf
最后增加:
1 2 3 4
| * soft nofile 65535 * hard nofile 65535 * soft nproc 65535 * hard nproc 65535
|
1 2 3 4 5 6
| root soft core unlimited root hard core unlimited root soft nproc 65535 root hard nproc 65535 root soft nofile 65535 root hard nofile 65535
|