Linux高并发内核优化-TougheRadius
https://www.cnblogs.com/travis-li/p/12598799.html
linux 内核优化
默认情况下,linux系统有一些限制,并不能直接支持高并发性能,需要做一些内核优化。
1、把以下内容加入 /etc/sysctl.conf
net.ipv4.ip_forward=1 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 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 = 8192 net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.tcp_max_syn_backlog = 65536 net.core.netdev_max_backlog = 32768 net.core.somaxconn = 32768 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_reuse = 1 net.ipv4.tcp_wmem = 8192 436600 873200 net.ipv4.tcp_rmem = 32768 436600 873200 net.ipv4.tcp_mem = 94500000 91500000 92700000 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_fin_timeout = 30 vm.overcommit_memory = 1
执行
sysctl -p
2、修改 /etc/security/limits.conf
加入以下内容至末尾
* soft nproc 40000 * hard nproc 40000 * soft nofile 40000 * hard nofile 40000
3、修改 /etc/pam.d/login
加入以下内容至末尾
session required /lib64/security/pam_limits.so session required pam_limits.so
4、修改 /etc/profile
加入以下指令到末尾
ulimit -n 65535
重启一下系统,执行 ulimit -a 可以看到优化结果,执行 ulimit -n 可以看到最大连接数限制,默认是1024
ulimit -a
========= End