docker-compose 部署 Redis 的一些警告

背景

内核参数 overcommit_memory警告

# WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it 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.

 

内核参数 overcommit_memory,它是内存分配的策略,可选值有:0、1、2。

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

第一步:
修改配置文件 vim /etc/sysctl.conf, 写入下面内容(注意是宿主机)

...
vm.overcommit_memory = 1

第二步:
使配置生效:

sysctl -p

 

TCP 连接数异常

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

解决办法:

需要修改docker-compose.yml,添加:

sysctls:
    - net.core.somaxconn=65535

重启容器。

posted @ 2024-12-03 10:22  cnkker.com  阅读(421)  评论(0)    收藏  举报