Redis 3.0版本启动时出现警告的解决办法

2023-07-29,,

原文:http://m.blog.csdn.net/article/details?id=50864933

Redis 3.0.7版本启动时出现警告解决办法

发表于2016/3/12 12:52:40  508人阅读

分类: Redis

Redis 3.0.7版本启动时出现警告的解决办法

7283:M 12 Mar 12:13:33.749 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7283:M 12 Mar 12:13:33.749 # Server started, Redis version 3.0.7
7283:M 12 Mar 12:13:33.749 # 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.
7283:M 12 Mar 12:13:33.749 * The server is now ready to accept connections on port 6379

第1个警告(WARNING: The TCP backlog setting of 511 ......)解决办法
方法1: 临时设置生效: sysctl -w net.core.somaxconn = 1024
方法2: 永久生效: 修改/etc/sysctl.conf文件,增加一行
net.core.somaxconn= 1024
然后执行命令
sysctl -p

补充:
net.core.somaxconn是linux中的一个kernel参数,表示socket监听(listen)的backlog上限。
backlog是socket的监听队列,当一个请求(request)尚未被处理或建立时,他会进入backlog。
而socket server可以一次性处理backlog中的所有请求,处理后的请求不再位于监听队列中。
当server处理请求较慢,以至于监听队列被填满后,新来的请求会被拒绝。
所以说net.core.somaxconn限制了接收新 TCP 连接侦听队列的大小。
对于一个经常处理新连接的高负载 web服务环境来说,默认的 128 太小了。大多数环境这个值建议增加到 1024 或者更多。

第2个警告(WARNING overcommit_memory is set to 0! ......)同样也有两个解决办法
方法1: 临时设置生效: sysctl -w vm.overcommit_memory = 1
方法2: 永久生效: 修改/etc/sysctl.conf文件,增加一行
vm.overcommit_memory = 1
然后执行命令
sysctl -p
 

第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.

解决方式,禁止通明大页

方法1:临时设置生效 echo never > /sys/kernel/mm/transparent_hugepage/enabled

方法2: 永久生效: 修改vim /etc/rc.local,增加一行(没有测试这个)

echo never > /sys/kernel/mm/transparent_hugepage/enabled #在开机脚本里追加此命令

补充: 
overcommit_memory参数说明:
设置内存分配策略(可选,根据服务器的实际情况进行设置)
/proc/sys/vm/overcommit_memory
可选值:0、1、2。
0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存
注意:redis在dump数据的时候,会fork出一个子进程,理论上child进程所占用的内存和parent是一样的,比如parent占用的内存为8G,这个时候也要同样分配8G的内存给child,如果内存无法负担,往往会造成redis服务器的down机或者IO负载过高,效率下降。所以这里比较优化的内存分配策略应该设置为 1(表示内核允许分配所有的物理内存,而不管当前的内存状态如何)。

Redis 3.0版本启动时出现警告的解决办法的相关教程结束。

《Redis 3.0版本启动时出现警告的解决办法.doc》

下载本文的Word格式文档,以方便收藏与打印。