数据库
首页 > 数据库> > redis哨兵模式(一主二从三哨兵)

redis哨兵模式(一主二从三哨兵)

作者:互联网

 首先 准备一个配置文件路径 

mkdir /usr/local/etc/redis/sentinel/sentinel -p
 
cd /usr/local/etc/redis/sentinel/sentinel

配置三个哨兵的配置文件 我们设置端口 号 26379、26380 、26381

 

 

 

 配置主机点  

 

从节点的 配置 

 

 

 

 

 

 

 

运行 compose.yml 文件

文件存在  

cd /usr/local/etc/redis/sentinel/sentinel
 
vi docker-compose.yml






version: '3'
2
3
services:
4
  redis-sentinel-1:
5
    image: redis
6
    container_name: redis-sentinel-1
7
    restart: always
8
    # 为了规避Docker中端口映射可能带来的问题
9
    # 这里选择使用host网络
10
    network_mode: host
11
    volumes:
12
      - ./redis-sentinel-1.conf:/usr/local/etc/redis/redis-sentinel.conf
13
    # 指定时区,保证容器内时间正确
14
    environment:
15
      TZ: "Asia/Shanghai" 
16
    command: ["redis-sentinel", "/usr/local/etc/redis/redis-sentinel.conf"]
17
  redis-sentinel-2:
18
    image: redis
19
    container_name: redis-sentinel-2
20
    restart: always
21
    network_mode: host
22
    volumes:
23
      - ./redis-sentinel-2.conf:/usr/local/etc/redis/redis-sentinel.conf
24
    environment:
25
      TZ: "Asia/Shanghai" 
26
    command: ["redis-sentinel", "/usr/local/etc/redis/redis-sentinel.conf"]
27
  redis-sentinel-3:
28
    image: redis
29
    container_name: redis-sentinel-3
30
    restart: always
31
    network_mode: host
32
    volumes:
33
      - ./redis-sentinel-3.conf:/usr/local/etc/redis/redis-sentinel.conf
34
    environment:
35
      TZ: "Asia/Shanghai"
36
    command: ["redis-sentinel", "/usr/local/etc/redis/redis-sentinel.conf"]


在dockers 里面 运行 启动

cd /usr/local/etc/redis/sentinel/server
docker-compose up -d
cd /usr/local/etc/redis/sentinel/sentinel
 
docker-compose up -d
 
#查看主从信息
info replication
 
测试 
 
停止主节点
 
docker stop redis-server-master
 
 
#进入从1redis-server-slave-1查看角色是否被修过为主节点
 
docker exec -it redis-server-slave-1 /bin/bash
 
redis-cli -p 6380 -a 123456
 
info replication
 
 
#进入从1redis-server-slave-2查看角色是否被修过为主节点
 
docker exec -it redis-server-slave-2 /bin/bash
 
redis-cli -p 6381 -a 123456
 
info replication
 




























 

标签:redis,哨兵,etc,usr,conf,sentinel,local,一主二
来源: https://www.cnblogs.com/jasontarry/p/14747817.html