Redis教程

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哨兵模式(一主二从三哨兵)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!