Redis一主三从三哨兵之Docker-compose

Master-Slave:

version: '2'
services:
  master:
    image: redis
    container_name: redis-master
    command: redis-server --requirepass 123456  --masterauth 123456 
    ports:
    - "6379:6379"
  slave1:
    image: redis
    container_name: redis-slave-1
    ports:
    - "6380:6379"
    command: redis-server --slaveof redis-master 6379 --requirepass 123456 --masterauth 123456 
    depends_on:
    - master
  slave2:
    image: redis
    container_name: redis-slave-2
    ports:
    - "6381:6379"
    command: redis-server --slaveof redis-master 6379 --requirepass 123456 --masterauth 123456
    depends_on:
    - master
networks:
  default:
    external:
      name: redis_default 

Sentinel:

version: '2'
services:
  sentinel1:
    image: redis
    container_name: redis-sentinel-1
    ports:
    - "26379:26379"
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
    - "./:/usr/local/etc/redis"
  sentinel2:
    image: redis
    container_name: redis-sentinel-2
    ports:
    - "26380:26379"           
    command: redis-sentinel /usr/local/etc/redis/sentinel2.conf
    volumes:
    - "./:/usr/local/etc/redis"
  sentinel3:
    image: redis
    container_name: redis-sentinel-3
    ports:
    - "26381:26379"           
    command: redis-sentinel /usr/local/etc/redis/sentinel3.conf
    volumes:
    - "./:/usr/local/etc/redis"
networks:
  default:
    external:
      name: redis_default

sentinel.conf:

port 26379
dir /tmp
sentinel monitor mymaster 172.18.0.2 6379 2 # 这里IP填写master的IP
sentinel auth-pass mymaster 123456 
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000  
sentinel deny-scripts-reconfig yes
posted @ 2022-07-04 14:18  HANFAN  阅读(67)  评论(0编辑  收藏  举报