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
重啟容器。

浙公網安備 33010602011771號