docker-compose安装redis哨兵

docker-compose安装redis哨兵

写docker-compose.yml

version: '3.8'
services:
  redismaster:
    image: redis:6.2.5
    container_name: redis-master
    restart: always
    command: redis-server  --requirepass 123456  --masterauth 123456 --protected-mode no
    networks:
      redisconfig:
        ipv4_address: 172.16.238.4
    ports:
      - 6379:6379
    volumes:
      - /docker/redis-master/conf/redis.conf:/etc/redis/redis.conf
      - /docker/redis-master/data/:/data
  redisslave:
    image: redis:6.2.5
    container_name: redis-slave
    restart: always
    command: redis-server --slaveof 172.16.238.1 6379 --port 6380 --requirepass 123456 --masterauth 123456 --protected-mode no
    ports:
      - 6380:6380
    networks:
      redisconfig:
        ipv4_address: 172.16.238.2
    volumes:
      - /docker/redis-slave/conf/redis.conf:/etc/redis/redis.conf
      - /docker/redis-slave/data/:/data
  redisslave01:
    image: redis:6.2.5
    container_name: redis-slave01
    restart: always
    command: redis-server --slaveof 172.16.238.1 6379 --port 6381 --requirepass 123456 --masterauth 123456 --protected-mode no
    ports:
      - 6381:6381
    networks:
      redisconfig:
        ipv4_address: 172.16.238.3
    volumes:
      - /docker/redis-slave01/conf/redis.conf:/etc/redis/redis.conf
      - /docker/redis-slave01/data/:/data
  sentinel1:
    image: redis
    container_name: redis-sentinel-1
    command: redis-sentinel /home/ec2-user/dockerfile/sentinel/sentinel.conf
    restart: always
    ports:
      - 16379:16379
    volumes:
      - /docker/sentinel1/sentinel1.conf:/home/ec2-user/dockerfile/sentinel/sentinel.conf
      - /docker/sentinel1/log/:/var/log/redis/
    networks:
      redisconfig:
        ipv4_address: 172.16.238.5
  sentinel2:
    image: redis
    container_name: redis-sentinel-2
    command: redis-sentinel /home/ec2-user/dockerfile/sentinel/sentinel.conf
    restart: always
    ports:
      - 16380:16380
    volumes:
      - /docker/sentinel2/sentinel2.conf:/home/ec2-user/dockerfile/sentinel/sentinel.conf
      - /docker/sentinel2/log/:/var/log/redis/
    networks:
      redisconfig:
        ipv4_address: 172.16.238.6
  sentinel3:
    image: redis
    container_name: redis-sentinel-3
    command: redis-sentinel /home/ec2-user/dockerfile/sentinel/sentinel.conf
    restart: always
    ports:
      - 16381:16381
    volumes:
      - /docker/sentinel3/sentinel3.conf:/home/ec2-user/dockerfile/sentinel/sentinel.conf
      - /docker/sentinel3/log/:/var/log/redis/
    networks:
      redisconfig:
        ipv4_address: 172.16.238.7
networks:
  redisconfig:
    ipam:
      config:
        - subnet: 172.16.238.0/24

增加sentinel1.conf,sentinel2.conf, sentinel3.conf

port 16379
daemonize no
pidfile /var/run/redis-sentinel.pid
logfile "/var/log/redis/sentinel.log"
dir /tmp
sentinel monitor mymaster 172.16.238.4 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 60000
sentinel deny-scripts-reconfig yes

sentinel2.conf

port 16380
daemonize no
pidfile /var/run/redis-sentinel.pid
logfile "/var/log/redis/sentinel.log"
dir /tmp
sentinel monitor mymaster 172.16.238.4 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 60000
sentinel deny-scripts-reconfig yes

sentinel2.conf

port 16381
daemonize no
pidfile /var/run/redis-sentinel.pid
logfile "/var/log/redis/sentinel.log"
dir /tmp
sentinel monitor mymaster 172.16.238.4 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 24000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 60000
sentinel deny-scripts-reconfig yes

你可能感兴趣的:(redis,docker)