Docker下docker-compose配置启动Redis时提示WARNING问题解决[ can’t open config file、overcommit_memory is set to 0.]

前言:

文章内容:docker-compose 部署redis服务时,出现的问题。

查看redis启动日志:

1、查看容器ID
docker ps --4c496505d71e
2、执行命令查看 --4c496505d71e redis容器ID
docker logs --tail 50 4c496505d71e【CONTAINER ID】

问题 1:Fatal error, can’t open config file ‘/etc/conf/redis.conf’

Fatal error, can’t open config file ‘/etc/conf/redis.conf’

解释:不能读取配置文件,可能原因:
1、查看宿主机挂载目录是否存在redis.conf文件
2、权限问题

解决:

权限问题就不说了 命令 chmod

原来配置是这样
 - ./conf:/etc/conf/redis.conf

更改如下:
 volumes:
      # 设置容器时区与宿主机保持一致
      - /etc/localtime:/etc/localtime:ro
      - ./data/redis:/data
      - ./conf/redis.conf:/etc/conf/redis.conf
      - ./logs:/logs

问题 2: overcommit_memory is set to 0! Background save may fail under low memory condition.

其实问题也就是答案

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.
解释:

警告:overcommit_memory设置为0!在内存不足的情况下,后台保存可能失败。要解决这个问题,添加‘vm’。overcommit_memory = 1’ /etc/sysctl.conf,然后重启或执行’sysctl vm. conf '命令。overcommit_memory=1’让它生效。

解决:

1、编辑文件
vi /etc/sysctl.conf

2、添加参数 vm.overcommit_memory = 1
3、执行sysctl -p 生效

问题 3: you have Transparent Huge Pages (THP) support enabled in your kernel.

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue 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 the setting after a reboot. Redis must be restarted after THP is disabled.
解释:
在您的内核中启用了透明的大页面(THP)支持。这会造成Redis的延迟和内存使用问题。要解决这个问题,以root用户的身份运行命令’echo never > /sys/kernel/mm/transparent_hugepage/enabled’,并将其添加到/etc/rc.本地,以便在重新启动后保留设置。禁用THP后,必须重启Redis。

解决:

1、执行 echo never > /sys/kernel/mm/transparent_hugepage/enabled
2、并添加到 /etc/rc.local
vi /etc/rc.local
3、执行 source /etc/rc.local 使配置生效

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

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

The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
解释:
由于/proc/sys/net/core/somaxconn被设置为较低的值128,TCP backlog设置511无法执行。

解决:

1、 vi /etc/sysctl.conf
2、 添加 net.core.somaxconn = 1024
3、执行 sysctl -p生效

问题5: Failed opening the RDB file admin (in server root dir /etc/cron.d) for saving: Permission denied

Background saving started by pid 3751
3751:C 24 Dec 10:46:38.017 # Failed opening the RDB file admin (in server root dir /etc/cron.d) for saving: Permission denied
解释:
后台保存开始由pid 3751
打开RDB文件admin(服务器根目录为/etc/cron.d)保存失败:权限被拒绝
原因:
Background saving这个是Redis用来保存以RDB模式运行的当前快照的线程所写入的日志.
redis的不安全访问,导致配置被修改.
攻击者想利用redis直接修改crontab配置,实现一些定时任务写入,从而去执行一些"特殊"命令(比如,挖矿等),甚至掌控服务器.

解决:

1、编辑配置文件 redis.conf
2、requirepass foobared # foobared 换成你的密码
补充:
或者更安全的做法.redis3.2后可用.
bind 0.0.0.0 # 绑定到具体地址
设置外部网络连接redis服务
protected-mode yes # 开启保护模式,该模式将需配置bind ip或者设置访问密码
参考自:
https://blog.csdn.net/weixin_46080554/article/details/103678056

-Ending.-

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值