15秒搭建一个redis哨兵集群

一、 使用docker-compose搭建redis哨兵集群(一主二从三哨兵)

1.1 配置一主二次(网络模式必须是host,否则会出现节点找不到的情况)
version: '3'
services:
  master:
    image: redis
    container_name: redis-master
    command: redis-server --port 6379  --requirepass 123456 --masterauth 123456
    network_mode: "host"
  slave1:
    image: redis
    container_name: redis-slave-1
    command:  redis-server --port 6380  --slaveof 192.168.164.128 6380 --requirepass 123456 --masterauth 123456
    network_mode: "host"
  slave2:
    image: redis
    container_name: redis-slave-2
    network_mode: "host"
    command: redis-server --port 6381   --slaveof 192.168.164.128 6380 --requirepass 123456 --masterauth 123456

docker-compose up

1.2 配置哨兵节点
#sentinel1.conf
port 26379
dir /tmp
sentinel monitor mymaster 192.168.164.128  6379 2
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
[root@localhost sentinel]# cat sentinel2.conf 

#sentinel1.conf
port 26380
dir /tmp
sentinel monitor mymaster 192.168.164.128  6379 2
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
[root@localhost sentinel]# cat sentinel3.conf 

#sentinel1.conf
port 26381
dir /tmp
sentinel monitor mymaster 192.168.164.128  6379 2
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

docker-compose.yml (哨兵compose文件)

version: '3'
services:
  sentinel1:
    image: redis
    container_name: redis-sentinel-1
    network_mode: "host"
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
      - ./sentinel1.conf:/usr/local/etc/redis/sentinel.conf
  sentinel2:
    image: redis
    container_name: redis-sentinel-2
    network_mode: "host"
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
      - ./sentinel2.conf:/usr/local/etc/redis/sentinel.conf
    depends_on:
    -  sentinel1
  sentinel3:
    image: redis
    container_name: redis-sentinel-3
    network_mode: "host"
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
      - ./sentinel3.conf:/usr/local/etc/redis/sentinel.conf
    depends_on:
    -  sentinel2

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值