解决redis启动时的警告

如果我们什么都不修改,redis启动时会有三个警告

解决redis启动时的警告

警告1 : WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128

解释:上面写的很清晰,意思是配置 /proc/sys/net/core/somaxconn的值是128,虽然redis.conf中配置的是511,但是linux内核会以无提示的方式将其截断为128。在一个高并发的环境下,128是远远不够的,所以我们要改大一些

办法:net.core.somaxconn = 1024添加到/etc/sysctl.conf中,然后执行sysctl -p 生效配置,如下图

解决redis启动时的警告

警告2: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

解释:overcommit_memory 表内存分配策略,可选值:0、1、2

0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存

办法:vm.overcommit_memory = 1添加到/etc/sysctl.conf中,然后执行sysctl -p生效配置,如下图(由于刚执行了第一个警告的修复,所以两条命令都有)

解决redis启动时的警告

警告3: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

解释:THP(透明大页)的知识请参考这篇博客 https://www.cnblogs.com/kerrycode/p/4670931.html

redis建议我们关掉THP,还给出的具体的操作办法,注意必须使用root来操作,否则会失败的

办法:执行命令 echo never > /sys/kernel/mm/transparent_hugepage/enabled

            并把命令 echo never > /sys/kernel/mm/transparent_hugepage/enabled 写入到 /etc/rc.local 中

            执行命令 source /etc/rc.local

全部修复后,启动redis,已经不报任何警告了,如下图

解决redis启动时的警告