qq_43530416
喝咖啡的睡眠族
2021-01-24 18:04

奇闻: docker搭建的redis哨兵集群会导致redis集群的master服务死掉

  • redis

我在docker上通过docker-compose搭建了一个一主二从的redis集群.搭建成功后集群正常运行

version: '2'
services:
  master:
    image: redis
    container_name: redis-1
    command: redis-server --requirepass 123456 --masterauth 123456
    ports:
      - 6379:6379
    volumes:
      - /opt/soft/health-care/redis/redis-1/data:/data
      - /opt/soft/health-care/redis/redis-1/conf:/etc/redis/conf
  slave1:
    image: redis
    container_name: redis-2
    ports:
      - 6380:6379
    volumes:
      - /opt/soft/health-care/redis/redis-2/data:/data
      - /opt/soft/health-care/redis/redis-2/conf:/etc/redis/conf
    command: redis-server --slaveof redis-1 6379 --requirepass 123456 --masterauth 123456
  slave2:
    image: redis
    container_name: redis-3
    ports:
      - 6381:6379
    volumes:
      - /opt/soft/health-care/redis/redis-3/data:/data
      - /opt/soft/health-care/redis/redis-3/conf:/etc/redis/conf
    command: redis-server --slaveof redis-1 6379 --requirepass 123456 --masterauth 123456

通过docker inspect redis-1查询得知redis-1的ip为

之后,又通过docker-compose搭建了三个哨兵组成的哨兵集群

version: '2'
services:
  sentinel1:
    image: redis
    container_name: redis-sentinel-1
    ports:
      - 26379:26379
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
      - /opt/soft/health-care/redis-sentinel/sentinel-1/conf/sentinel.conf:/usr/local/etc/redis/sentinel.conf
  sentinel2:
    image: redis
    container_name: redis-sentinel-2
    ports:
    - 26380:26379
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
      - /opt/soft/health-care/redis-sentinel/sentinel-2/conf/sentinel.conf:/usr/local/etc/redis/sentinel.conf
  sentinel3:
    image: redis
    container_name: redis-sentinel-3
    ports:
      - 26381:26379
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
      - /opt/soft/health-care/redis-sentinel/sentinel-3/conf/sentinel.conf:/usr/local/etc/redis/sentinel.conf
networks:
  default:
    external:
      name: docker-compose_default

哨兵配置文件如下:

port 26379
dir /tmp
# 172.19.0.4-> 是redis集群的master服务ip
sentinel monitor mymaster 172.19.0.4 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

问题出现在哨兵集群的启动:

哨兵集群启动之后,会导致redis集群的master状态变为:  master_link_status:down

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答