第一个问题: Increased maximum number of open files to 10032 (it was originally set to 1024).
原因分析:即进程能打开的最大文件描述符太小了。系统默认设置的值一般是 1024 。
解决方法:
1.系统级别,即 linux 内核能分配的最大文件描述符数量(参考:https://www.kernel.org/doc/Documentation/sysctl/fs.txt)。
# vi /etc/sysctl.conf
fs.file-max = 102400
# sysctl -p
查看方法:
# cat /proc/sys/fs/file-max
# sysctl fs.file-max
2.用户级别,即用户进程能打开的最大文件描述符数量(参考 man limits.conf 或者 https://linux.die.net/man/5/limits.conf)。
设置方法:
# vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
查看方法(无需重启系统。当前用户重新登录后生效。或者切换到具体的用户,立刻生效):
# su - username
$ ulimit -Hn
$ ulimit -Sn
注意:
CentOS 还需开启 pam_limits 模块,因为 limits.conf 文件相当于 pam_limits 模块的配置文件。
# vi /etc/pam.d/login
session required pam_limits.so
第二个问题:WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
原因分析:net.core.somaxconn 参数的值太小了。即全连接(即 accept 连接)的最大队列长度太小了。
解决方法:
# vi /etc/sysctl.conf
net.core.somaxconn = 511
# sysctl -p
查看方法:
# cat /proc/sys/net/core/somaxconn
# sysctl net.core.somaxconn
第三个问题:
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
原因分析:vm.overcommit_memory 指的是进程申请的内存大小。当参数值为 0 时,如果一次性申请的内存大小超过了系统总内存,有可能被拒绝。当参数值为 0 时,有可能会导致 redis 执行 bgsave 操作保存 rdb 文件失败。(参考:http://linuxperf.com/?p=102)。
解决方法:
# vi /etc/sysctl.conf
vm.overcommit_memory = 1
# sysctl -p
查看方法:
# cat /proc/sys/vm/overcommit_memory
# sysctl vm.overcommit_memory
第四个问题:
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
原因分析:Transparent Huge Pages (THP) 开启后会使 redis 时延变大和造成内存使用问题(参考:https://redis.io/topics/latency)。
解决方法(CentOS 6.X):
echo never > /sys/kernel/mm/transparent_hugepage/enabled
# vim /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
解决方法(CentOS 7.X):
# vim /etc/systemd/system/disable-transparent-huge-pages.service
[Unit]
Description=Disable Transparent Huge Pages (THP)
DefaultDependencies=no
After=sysinit.target local-fs.target
[Service]
Type=oneshot
ExecStart=/bin/sh -c 'echo never | tee /sys/kernel/mm/transparent_hugepage/enabled > /dev/null'
[Install]
WantedBy=basic.target
# systemctl enable disable-transparent-huge-pages
# systemctl start disable-transparent-huge-pages
查看方法:
# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]