linux系統優化配置

# 2 millions system-wide
sysctl -w fs.file-max=2097152 sysctl -w fs.nr_open=2097152 echo 2097152 > /proc/sys/fs/nr_open

ulimit -n 1048576
ulimit -u 12000

/etc/sysctl.conf

持久化 ‘fs.file-max’ 設置到 /etc/sysctl.conf 文件:網絡

fs.file-max = 1048576 

/etc/systemd/system.conf 設置服務最大文件句柄數:併發

DefaultLimitNOFILE=1048576 

/etc/security/limits.conf

/etc/security/limits.conf 持久化設置容許用戶/進程打開文件句柄數:tcp

*      soft nofile 1048576 * hard nofile 1048576
* soft nproc 12000
* hard nproc 12000

TCP 協議棧網絡參數

併發鏈接 backlog 設置:ide

sysctl -w net.core.somaxconn=32768 sysctl -w net.ipv4.tcp_max_syn_backlog=16384 sysctl -w net.core.netdev_max_backlog=16384 

可用知名端口範圍:spa

sysctl -w net.ipv4.ip_local_port_range='1000 65535' 

TCP Socket 讀寫 Buffer 設置:進程

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_mem='16777216 16777216 16777216' sysctl -w net.ipv4.tcp_rmem='1024 4096 16777216' sysctl -w net.ipv4.tcp_wmem='1024 4096 16777216' 

TCP 鏈接追蹤設置:ip

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 

TIME-WAIT Socket 最大數量、回收與重用設置:it

net.ipv4.tcp_max_tw_buckets=1048576 # 注意: 不建議開啓該設置,NAT模式下可能引發鏈接RST # net.ipv4.tcp_tw_recycle = 1 # net.ipv4.tcp_tw_reuse = 1 

FIN-WAIT-2 Socket 超時設置:io

net.ipv4.tcp_fin_timeout = 15
相關文章
相關標籤/搜索