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

在这里插入图片描述


版权声明:本文为luomo0203原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。