docker-compose安装redis高可用哨兵集群(一主二从三哨兵)

以redis 7.0为例子

直接上代码

docker-compose.yaml

version: '3.3'
services:
  master:
    image: redis:7.0
    container_name: redis-master
    #restart: always
    command: redis-server --port 6379 --requirepass root  --appendonly yes --masterauth root --replica-announce-ip 192.168.2.168 --replica-announce-port 6379
    volumes:
      - ./data/master:/data
    ports:
      - 6379:6379
  slave1:  
    image: redis:7.0
    container_name: redis-slave-1
    #restart: always
    command: redis-server --slaveof 192.168.2.168 6379 --port 6379  --requirepass root --masterauth root  --appendonly yes --replica-announce-ip 192.168.2.168 --replica-announce-port 6380
    volumes:
      - ./data/slave1:/data
    ports:
      - 6380:6379
 
  slave2:
    image: redis:7.0
    container_name: redis-slave-2
    #restart: always
    command: redis-server --slaveof 192.168.2.168 6379 --port 6379  --requirepass root --masterauth root  --appendonly yes --replica-announce-ip 192.168.2.168 --replica-announce-port 6381
    volumes:
      - ./data/slave1:/data
    ports:
      - 6381:6379
 
  sentinel1:
    image: redis:7.0
    container_name: redis-sentinel-1
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    #restart: always
    ports:
      - 26379:26379
    volumes:
      - ./config/sentinel1.conf:/usr/local/etc/redis/sentinel.conf
 
  sentinel2:
    image: redis:7.0
    container_name: redis-sentinel-2
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    #restart: always
    ports:
      - 26380:26379
    volumes:
      - ./config/sentinel2.conf:/usr/local/etc/redis/sentinel.conf
 
  sentinel3:
    image: redis:7.0
    container_name: redis-sentinel-3
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    #restart: always
    ports:
      - 26381:26379
    volumes:
      - ./config/sentinel3.conf:/usr/local/etc/redis/sentinel.conf

ip

端口号说明
192.168.2.1686379
192.168.2.1686380从1
192.168.2.1686381从2
192.168.2.16826379哨兵1
192.168.2.16826380哨兵2
192.168.2.16826381哨兵3

sentinel1.conf

#sentinel1.conf
port 26379
dir /tmp
sentinel monitor mymaster 192.168.2.168 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster root
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
sentinel announce-ip 192.168.2.168
sentinel announce-port 26379

sentinel2.conf

#sentinel2.conf
port 26380
dir /tmp
sentinel monitor mymaster 192.168.2.168 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster root
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
sentinel announce-ip 192.168.2.168
sentinel announce-port 26380

sentinel3.conf

#sentinel3.conf
port 26381
dir /tmp
sentinel monitor mymaster 192.168.2.168 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster root
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
sentinel announce-ip 192.168.2.168
sentinel announce-port 26381

启动docker

docker-compose up -d

校验集群

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

慕菲烟云

坚持原创,希望大家多多交流

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值