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: redis6
container_name: redis-sentinel-17
restart: always8
# 为了规避Docker中端口映射可能带来的问题9
# 这里选择使用host网络10
network_mode: host11
volumes:12
- ./redis-sentinel-1.conf:/usr/local/etc/redis/redis-sentinel.conf13
# 指定时区,保证容器内时间正确14
environment:15
TZ: "Asia/Shanghai"16
command: ["redis-sentinel", "/usr/local/etc/redis/redis-sentinel.conf"]17
redis-sentinel-2:18
image: redis19
container_name: redis-sentinel-220
restart: always21
network_mode: host22
volumes:23
- ./redis-sentinel-2.conf:/usr/local/etc/redis/redis-sentinel.conf24
environment:25
TZ: "Asia/Shanghai"26
command: ["redis-sentinel", "/usr/local/etc/redis/redis-sentinel.conf"]27
redis-sentinel-3:28
image: redis29
container_name: redis-sentinel-330
restart: always31
network_mode: host32
volumes:33
- ./redis-sentinel-3.conf:/usr/local/etc/redis/redis-sentinel.conf34
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