linux内核参数优化脚本,适应高并发场景

直接贴脚本,centos系统root用户执行即可,一步到位

#修改内核配置
mv /etc/sysctl.conf /etc/sysctl.conf.bak
cat >/etc/sysctl.conf << end
# # Controls the maximum size of a message, in bytes
kernel.msgmax = 65536
#
# # Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736
#
# # Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
#当物理内存可用率低于10%时使用Swap
vm.swappiness = 20
#配置可用的端口范围
net.ipv4.ip_local_port_range = 1024 65000
#避免nat后面的client出问题,net.ipv4.tcp_tw_recycle = 0,同时,忽略TIME_WAIT多的问题,设置过小会有副作用,
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
#配置ip_conntrack,ip_conntrack 的作用和副作用
net.nf_conntrack_max = 655360
net.netfilter.nf_conntrack_max = 655360
nf_conntrack_buckets = 163840
net.ipv4.tcp_syncookies = 1
net.core.somaxconn = 262144
net.ipv4.tcp_max_syn_backlog = 262144
#禁用ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
#允许进程打开的最大文件句柄数
fs.file-max = 752461
end
sysctl -p >/dev/null 2>&1
#允许用户打开的文件描述符数
sed -i '/session required pam_limits.so/d' /etc/pam.d/login
echo "session required pam_limits.so" >> /etc/pam.d/login
sed -i '/[a-zA-Z]\+ nofile/d' /etc/security/limits.conf
echo "
* soft nofile 300612
* hard nofile 300612
" >> /etc/security/limits.conf
 

end

发表评论

邮箱地址不会被公开。 必填项已用*标注