首页 > 解决方案 > 将 redis 与 docker-compose 一起使用:MISCONF Redis 配置为保存 RDB 快照,但目前无法持久保存在磁盘上

问题描述

我相信这个问题在这里有些答案:MISCONF Redis is configured to save RDB snapshots

我目前正在运行一个 Redis docker 容器,它不时返回以下错误:

MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.

结合:

redis_1        | 4410:C 06 Feb 2020 23:50:57.045 # Failed opening the RDB file crontab (in server root dir /etc) for saving: Permission denied

这是因为redis的空间不足吗?我可以做些什么来清理redis吗?我只使用redis作为消息传递层,所以数据并不是真的需要被持久化......

我还看到WARNINGS来自 redis 容器的以下内容:

# WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
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.
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.

我觉得也许这个问题是向 redis/devops 专家询问使用 docker-compose 配置 redis 的最佳方法的绝佳机会,我目前有:

  redis:
    build:
      context: ./redis
      dockerfile: Dockerfile
    ports:
      - '6379:6379'
    volumes:
        - ./redis.conf:/usr/local/etc/redis/redis.conf
    sysctls:
      net.core.somaxcomm: '511'
    restart: on-failure

如果有什么更好的可以做,那将是惊人的和感激的。

标签: dockerredis

解决方案


更新: 使用暴露而不是ports因此该服务仅可用于链接服务

公开端口而不将它们发布到主机 - 它们只能被链接服务访问。只能指定内部端口。

expose
 - 6379

原始答案: 您的 redis 实例可能对互联网开放。您可以使用redis.conftobind 127.0.0.1仅允许本地连接。

在此处查看详细答案


推荐阅读