服务器中的 docker 容器被莫名关闭 ,于是打开docker中 redis容器的log 发现很多警告:
docker inspect 65a6eddd4b2f(容器id)找到 logpath的 日志 打开
"LogPath": "/var/lib/docker/containers/65a6eddd4b2f7fbc655a2035d04cb085dc860538e8c1bcfa8be74964449e16ba/65a6eddd4b2f7fbc655a2035d04cb085dc860538e8c1bcfa8be74964449e16ba-json.log"
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.
The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
Redis must be restarted after THP is disabled.
you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue 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 thesetting after a reboot. Redis must be restarted after THP is disabled.
针对第一条警告:
whereis sysctl 找到配置文件
/etc/sysctl.conf
两个方式解决(overcommit_memory)
1. echo "vm.overcommit_memory=1" > /etc/sysctl.conf 或 vi /etcsysctl.conf , 然后reboot重启机器
2. echo 1 > /proc/sys/vm/overcommit_memory 不需要启机器就生效
sysctl -p使配置生效
针对第二条 :
修改参数值的语法
# sysctl -w net.core.somaxconn=32768
以上命令将kernel参数net.core.somaxconn的值改成了32768。这样的改动虽然可以立即生效,但是重启机器后会恢复默认值。
为了永久保留改动,需要用vi在/etc/sysctl.conf中增加一行
net.core.somaxconn= 4000
然后执行命令
# sysctl -p
第三条:大概意思 你使用的是透明大页,可能导致redis延迟和内存使用问题。执行 echo never > /sys/kernel/mm/transparent_hugepage/enabled 修复该问题。
临时解决方法:
echo never > /sys/kernel/mm/transparent_hugepage/enabled。
永久解决方法:
将其写入开机脚本 /etc/rc.local文件中。
echo never > /sys/kernel/mm/transparent_hugepage/enabled
# sysctl -a
会显示所有的kernel参数及值。
参考地址:https://segmentfault.com/a/1190000006619753