0

Redis Docekr WARNING Memory overcommit must be enabled! Without it, a background...

 2 months ago
source link: https://www.cnblogs.com/tinywan/p/18048071
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Redis Docekr WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition

Docker 容器

ssr-redis    | 1:C 01 Mar 2024 22:00:46.869 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
ssr-redis    | 1:C 01 Mar 2024 22:00:46.869 # Redis version=7.0.10, bits=64, commit=00000000, modified=0, pid=1, just started
ssr-redis    | 1:C 01 Mar 2024 22:00:46.869 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
ssr-redis    | 1:M 01 Mar 2024 22:00:46.869 * monotonic clock: POSIX clock_gettime
ssr-redis    | 1:M 01 Mar 2024 22:00:46.870 * Running mode=standalone, port=6379.
ssr-redis    | 1:M 01 Mar 2024 22:00:46.870 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
ssr-redis    | 1:M 01 Mar 2024 22:00:46.870 # Server initialized
ssr-redis    | 1:M 01 Mar 2024 22:00:46.870 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.

您的 Redis 容器日志中的警告信息指出了内存超分配(overcommit)的设置问题。在 Linux 系统中,内存超分配是一种内核行为,允许进程分配超出物理内存大小的虚拟内存。对于 Redis,这是一个重要的设置,尤其是当执行如 RDB 快照或 AOF 日志重写等内存密集型操作时。

警告信息的含义

  • Redis 需要内存超分配(vm.overcommit_memory)被设置为 1。这意味着操作系统将始终允许分配所有请求的内存,这对于 Redis 的某些操作至关重要。
  • 如果没有正确设置,当 Redis 尝试创建快照或进行某些类型的复制时,可能会因为内存不足而失败。这可能导致数据丢失或其他问题。

您需要在宿主机(运行 Docker 的服务器)上设置 vm.overcommit_memory 参数。这通常涉及两个步骤:

临时更改

在宿主机上执行以下命令:

sudo sysctl vm.overcommit_memory=1

永久更改

编辑 /etc/sysctl.conf 文件(或在某些系统上,可能是 /etc/sysctl.d/ 目录下的文件)。添加或修改以下行:

vm.overcommit_memory = 1

保存文件并重新启动系统,或者运行 sudo sysctl -p 来立即应用更改。

再次重启,问题解决

1021265-20240301221007631-124086375.png

作者:Tinywan

本文版权归作者和博客园共有。欢迎转载,但必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

欢迎关注个人微信公众号,一起进步!扫描左方二维码即可


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK