Linux内核参数优化

1、调整sysctl.conf文件参数:

[root@localhost /]# vim /etc/sysctl.conf
# 定义系统中每一个端口最大的监听队列的长度:
net.core.somaxconn = 2048

# 一个进程可以拥有的VMA(虚拟内存区域)的数量:
vm.max_map_count=262144

# 允许系统内核分配所有的物理内存:
vm.overcommit_memory = 1

# 调用虚拟内存的阈值数:
vm.swappiness=1
[root@localhost /]# sysctl -p

2、调整 / 每个进程最多允许同时打开文件数 / 每个进程最多可以同时建立TCP连接数: 

sed -i 's/# End of file//g' /etc/security/limits.conf
sed -i '$a *           soft  nofile  409600' /etc/security/limits.conf
sed -i '$a *           hard  nofile  409600' /etc/security/limits.conf
sed -i '$a *           soft  nproc   204800' /etc/security/limits.conf
sed -i '$a *           hard  nproc   204800' /etc/security/limits.conf
sed -i '$a # End of file' /etc/security/limits.conf

注:mongodb系统要求nofile = noroc*2

系统重启后生效:

# reboot

验证设置:

[root@localhost /]# ulimit -a | grep "open files"
open files                      (-n) 131070

查看一个进程的limit设置:

cat /proc/YOUR-PID/limits

3、禁用Transparent Huge Pages(THP):

vim /etc/rc.local

添加如下内容:

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi

if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi 

  注:CentOS7系统/etc/rc.local默认没有执行权限,需要自己添加权限

chmod +x /etc/rc.d/rc.local

[THE END]

原文地址:https://www.cnblogs.com/configure/p/6733187.html