上篇 这次主要是说,优化网络。一般就是两个点:

  • 优化limit
  • 优化socket状态

首先是修改 /etc/security/limits.conf

在文件中增加:

* soft nofile 20480
* hard nofile 20480
* - memlock unlimited

然后是修改 /etc/sysctl.conf

kernel.shmall = 4294967296
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216

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 = 1024 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_max_orphans = 3276800

net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
fs.file-max = 1048576