You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署Redis从节点遇NOAUTH认证错误求助

Redis主从同步认证失败问题

K8s环境中有Redis主集群,地址host.dev.k8s.net,端口6379,密码master-pwd。通过docker-compose部署Redis从节点后,容器日志出现Unexpected reply to PSYNC from master: -NOAUTH Authentication required错误,无法完成主从同步。

相关配置与日志

docker-compose.yml配置

version: '3.8'

networks:
  network_ext:
    external: true

services:
  redis:
    image: redis:latest
    hostname: redis
    ports:
      - '6379:6379'
    networks:
      - network_ext
    command: --slaveof host.dev.k8s.net 30916--slave-announce-ip 127.0.0.1
    environment:
      - REDIS_REPLICATION_MODE=slave
      - REDIS_MASTER_HOST=host.dev.k8s.net 
      - REDIS_MASTER_PORT_NUMBER=30916
      - REDIS_MASTER_PASSWORD=master-pwd
      - REDIS_PASSWORD=redis-pwd

容器运行状态

docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                                       NAMES
c5fa13ec5a90   redis:latest             "docker-entrypoint.s…"   2 seconds ago    Up 2 seconds    0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   service_redis_1

容器日志

docker logs -f c5fa13ec5a90
1:C 03 Aug 2023 14:20:47.603 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 03 Aug 2023 14:20:47.603 # Redis version=7.0.12, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 03 Aug 2023 14:20:47.603 # Configuration loaded
1:S 03 Aug 2023 14:20:47.603 * monotonic clock: POSIX clock_gettime
1:S 03 Aug 2023 14:20:47.604 * Running mode=standalone, port=6379.
1:S 03 Aug 2023 14:20:47.604 # Server initialized
1:S 03 Aug 2023 14:20:47.604 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can 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.
1:S 03 Aug 2023 14:20:47.604 * Ready to accept connections
1:S 03 Aug 2023 14:20:47.605 * Connecting to MASTER host.dev.k8s.net:30916
1:S 03 Aug 2023 14:20:48.062 * MASTER <- REPLICA sync started
1:S 03 Aug 2023 14:20:48.517 * Non blocking connect for SYNC fired the event.
1:S 03 Aug 2023 14:20:48.972 * Master replied to PING, replication can continue...
1:S 03 Aug 2023 14:20:49.410 * (Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.
1:S 03 Aug 2023 14:20:49.410 * (Non critical) Master does not understand REPLCONF ip-address: -NOAUTH Authentication required.
1:S 03 Aug 2023 14:20:49.410 * (Non critical) Master does not understand REPLCONF capa: -NOAUTH Authentication required.
1:S 03 Aug 2023 14:20:49.410 * Partial resynchronization not possible (no cached master)
1:S 03 Aug 2023 14:20:49.877 # Unexpected reply to PSYNC from master: -NOAUTH Authentication required.
1:S 03 Aug 2023 14:20:49.877 * Retrying with SYNC...
1:S 03 Aug 2023 14:20:50.327 # MASTER aborted replication with an error: NOAUTH Authentication required.
1:S 03 Aug 2023 14:20:50.327 * Reconnecting to MASTER host.dev.k8s.net:30916 after failure
解决方案

问题根源

  1. command参数格式错误:--slaveof host.dev.k8s.net 30916--slave-announce-ip 127.0.0.1中,端口30916与--slave-announce-ip之间缺少空格,导致Redis无法正确解析参数;同时自定义command会覆盖官方镜像的entrypoint逻辑,使得环境变量中的认证配置未生效。
  2. 主从认证配置未正确传递:从节点连接主节点时,未在启动参数中指定主节点密码,同步请求被主节点拒绝。

修复步骤

方式一:使用环境变量配置(推荐)

删除自定义的command字段,让官方镜像的entrypoint自动处理环境变量,完成主从同步和认证配置:

version: '3.8'

networks:
  network_ext:
    external: true

services:
  redis:
    image: redis:latest
    hostname: redis
    ports:
      - '6379:6379'
    networks:
      - network_ext
    environment:
      - REDIS_REPLICATION_MODE=slave
      - REDIS_MASTER_HOST=host.dev.k8s.net 
      - REDIS_MASTER_PORT_NUMBER=30916
      - REDIS_MASTER_PASSWORD=master-pwd
      - REDIS_PASSWORD=redis-pwd

方式二:使用command参数手动配置

若需保留自定义command,需修正参数格式并添加主节点认证密码:

version: '3.8'

networks:
  network_ext:
    external: true

services:
  redis:
    image: redis:latest
    hostname: redis
    ports:
      - '6379:6379'
    networks:
      - network_ext
    command: --slaveof host.dev.k8s.net 30916 --slave-announce-ip 127.0.0.1 --requirepass redis-pwd --masterauth master-pwd

验证修复

  1. 重新部署容器:docker-compose down && docker-compose up -d
  2. 查看容器日志:docker logs -f service_redis_1,确认出现MASTER <-> REPLICA sync: Finished with success字样
  3. 进入从节点容器验证:docker exec -it service_redis_1 redis-cli -a redis-pwd,执行INFO replication,查看master_link_status是否为up

内容的提问来源于stack exchange,提问作者emoleumassi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 00:45:27