【redis学习笔记】哨兵节点编排

编写 docker-compose.yml

创建 /root/redis-sentinel/docker-compose.yml , 同时 cd 到 yml 所在⽬录中;
注意: 每个⽬录中只能存在⼀个 docker-compose.yml ⽂件.

bash 复制代码
version: '3.7'
services:
 sentinel1:
 image: 'redis:5.0.9'
 container_name: redis-sentinel-1
 restart: always
 command: redis-sentinel /etc/redis/sentinel.conf
 volumes:
 - ./sentinel1.conf:/etc/redis/sentinel.conf
 ports:
 - 26379:26379
 sentinel2:
 image: 'redis:5.0.9'
 container_name: redis-sentinel-2
 restart: always
 command: redis-sentinel /etc/redis/sentinel.conf
 volumes:
 - ./sentinel2.conf:/etc/redis/sentinel.conf
 ports:
 - 26380:26379
 sentinel3:
 image: 'redis:5.0.9'
 container_name: redis-sentinel-3
 restart: always
 command: redis-sentinel /etc/redis/sentinel.conf
 volumes:
 - ./sentinel3.conf:/etc/redis/sentinel.conf
 ports:
 - 26381:26379

创建配置⽂件

创建 sentinel1.conf sentinel2.conf sentinel3.conf 三份⽂件的内容是完全相同的;都放到 /root/redis-sentinel/ ⽬录中.

bash 复制代码
bind 0.0.0.0
port 26379
sentinel monitor redis-master redis-master 6379 2
sentinel down-after-milliseconds redis-master 1000

启动所有容器

bash 复制代码
docker-compose up -d

查看运⾏⽇志

bash 复制代码
docker-compose logs

观察 redis-sentinel 的配置 rewrite

再次打开哨兵的配置⽂件, 发现⽂件内容已经被⾃动修改了

bash 复制代码
bind 0.0.0.0
port 26379
sentinel myid 4d2d562860b4cdd478e56494a01e5c787246b6aa
sentinel deny-scripts-reconfig yes
# Generated by CONFIG REWRITE
dir "/data"
sentinel monitor redis-master 172.22.0.4 6379 2
sentinel down-after-milliseconds redis-master 1000
sentinel config-epoch redis-master 1
sentinel leader-epoch redis-master 1
sentinel known-replica redis-master 172.22.0.2 6379
sentinel known-replica redis-master 172.22.0.3 6379
sentinel known-sentinel redis-master 172.22.0.7 26379 f718caed536d178f5ea6d1316d
sentinel known-sentinel redis-master 172.22.0.5 26379 2ab6de82279bb77f8397c309d3
sentinel current-epoch 1
相关推荐
零度@11 分钟前
SQL 调优全解:从 20 秒到 200 ms 的 6 步实战笔记(附脚本)
数据库·笔记·sql
im_AMBER1 小时前
Leetcode 78 识别数组中的最大异常值 | 镜像对之间最小绝对距离
笔记·学习·算法·leetcode
其美杰布-富贵-李1 小时前
HDF5文件学习笔记
数据结构·笔记·学习
嘻哈baby3 小时前
Redis高可用部署与集群管理实战
数据库·redis·bootstrap
d111111111d3 小时前
在STM32函数指针是什么,怎么使用还有典型应用场景。
笔记·stm32·单片机·嵌入式硬件·学习·算法
静小谢3 小时前
前后台一起部署,vite配置笔记base\build
前端·javascript·笔记
ask_baidu4 小时前
Doris笔记
android·笔记
嗷嗷哦润橘_4 小时前
AI Agent学习:MetaGPT之我的工作
人工智能·学习·flask
知识分享小能手4 小时前
CentOS Stream 9入门学习教程,从入门到精通,Linux日志分析工具及应用 —语法详解与实战案例(17)
linux·学习·centos
IMPYLH5 小时前
Lua 的 IO (输入/输出)模块
开发语言·笔记·后端·lua