1. 设置sysctl参数
代码语言:javascript复制echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
echo "vm.swappiness=1" >> /etc/sysctl.conf
/sbin/sysctl -p
2. 关闭透明大页
echo never > /sys/kernel/mm/transparent_hugepage/enabled
让其重启依然生效
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >>/etc/rc.local
chmod x /etc/rc.local
3. 增加redis资源限制
代码语言:javascript复制echo "redis soft nofile 2048" >> /etc/security/limits.conf
echo "redis hard nofile 65536" >> /etc/security/limits.conf
4. 调低OOM优先级
代码语言:javascript复制echo {score} > /proc/{pid}/oom_adj
5. TCP Backlog
默认值是511,如果Linux的tcp-backlog小于Redis设置的tcp-backlog,那么在redis启动的时候会看到如下日志:
WARNING: The TCP backlog setting of 511 cannot beenforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
查看方法:
代码语言:javascript复制cat/proc/sys/net/core/somaxconn
修改它:
代码语言:javascript复制echo 511 > /proc/sys/net/core/somaxconn