问题描述:启动redis时,告警日志中出现“The TCP backlog setting of 511……”以及“overcommit_memory is set to 0…..”警告,如下所示:
系统:rhel 7.9
数据库:redis 6.2.6
1、异常重现
[root@leo-redis626-a redis-6.2.6]# redis-server redis6379.conf
[root@leo-redis626-a redis-6.2.6]# tail -5000f redis.log
2685:C 03 Apr 2023 17:52:14.825 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2685:C 03 Apr 2023 17:52:14.825 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=2685, just started
2685:C 03 Apr 2023 17:52:14.825 # Configuration loaded
2685:M 03 Apr 2023 17:52:14.829 * Increased maximum number of open files to 10032 (it was originally set to 1024).
2685:M 03 Apr 2023 17:52:14.829 * monotonic clock: POSIX clock_gettime
2685:M 03 Apr 2023 17:52:14.830 * Running mode=standalone, port=6379.
2685:M 03 Apr 2023 17:52:14.831 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2685:M 03 Apr 2023 17:52:14.831 # Server initialized
2685:M 03 Apr 2023 17:52:14.831 # 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.
2685:M 03 Apr 2023 17:52:14.831 * Loading RDB produced by version 6.2.6
2685:M 03 Apr 2023 17:52:14.831 * RDB age 962 seconds
2685:M 03 Apr 2023 17:52:14.832 * RDB memory usage when created 2.05 Mb
2685:M 03 Apr 2023 17:52:14.832 # Done loading RDB, keys loaded: 1, keys expired: 0.
2685:M 03 Apr 2023 17:52:14.832 * DB loaded from disk: 0.001 seconds
2685:M 03 Apr 2023 17:52:14.832 * Ready to accept connections
2、解决过程
2.1、警告1
警告原因:该警告表示无法强制设置TCP backlog为511,因为/proc/sys/net/core/somaxconn设置为较低的值128。
解决方法:
A、echo 511 > /proc/sys/net/core/somaxconn,注意此命令只是暂时生效,重启后会失效。
B、编辑/etc/sysctl.conf,添加net.core.somaxconn = 1024,然后执行sysctl -p使其永久生效。
实施过程:
[root@leo-redis626-a redis-6.2.6]# cat <<EOF>>/etc/sysctl.conf
net.core.somaxconn = 1024
EOF
[root@leo-redis626-a ~]# /sbin/sysctl -p
net.core.somaxconn = 1024
2.2、警告2
警告原因:
overcommit_memory设置为0,在内存不足的情况下,后台保存可能失败。
解决方法:
--执行命令进行配置
[root@leo-redis626-a redis-6.2.6]# echo 1 > /proc/sys/vm/overcommit_memory
说明:此后重启redis,告警日志不在报错.
相关值的介绍:
0:表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则内存申请失败,并把错误返回给应用进程。
1:表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2:表示内核允许分配超过所有物理内存和交换空间总和的内存。
参考网址:
https://blog.csdn.net/afreon/article/details/118727725
https://blog.csdn.net/u013131716/article/details/118938471
标签:03,set,17,..,overcommit,Apr,52,2023,2685
From: https://blog.51cto.com/u_12991611/6167501