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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值