基于DockerCompose搭建Redis主从哨兵模式

embedded/2024/12/20 8:07:27/

linux目录结构

内网配置

哨兵配置文件如下,创建3个哨兵配置文件

# sentinel26379.conf  sentinel26380.conf  sentinel26381.conf 内容如下
protected-mode no
sentinel monitor mymaster redis-master 6379 2
sentinel down-after-milliseconds mymaster 60000
sentinel failover-timeout mymaster 180000
sentinel parallel-syncs mymaster 1

docker-compose.yaml


version: '3'services:redis-master:image: redis:4.0.8container_name: redis-masterports:- "6379:6379"volumes:- redis-master-data:/datacommand: ["redis-server", "--appendonly", "yes"]redis-slave1:image: redis:4.0.8container_name: redis-slave1ports:- "6380:6379"volumes:- redis-slave1-data:/datacommand: ["redis-server", "--slaveof", "redis-master", "6379", "--appendonly", "yes"]depends_on:- redis-masterredis-slave2:image: redis:4.0.8container_name: redis-slave2ports:- "6381:6379"volumes:- redis-slave2-data:/datacommand: ["redis-server", "--slaveof", "redis-master", "6379", "--appendonly", "yes"]depends_on:- redis-masterredis-sentinel-1:image: redis:4.0.8container_name: redis-sentinel-1ports:- "26379:26379"volumes:- ./sentinel26379.conf:/usr/local/etc/redis/sentinel.confcommand: ["redis-sentinel", "/usr/local/etc/redis/sentinel.conf"]depends_on:- redis-master- redis-slave1- redis-slave2redis-sentinel-2:image: redis:4.0.8container_name: redis-sentinel-2ports:- "26380:26379"volumes:- ./sentinel26380.conf:/usr/local/etc/redis/sentinel.confcommand: ["redis-sentinel", "/usr/local/etc/redis/sentinel.conf"]depends_on:- redis-master- redis-slave1- redis-slave2redis-sentinel-3:image: redis:4.0.8container_name: redis-sentinel-3ports:- "26381:26379"volumes:- ./sentinel26381.conf:/usr/local/etc/redis/sentinel.confcommand: ["redis-sentinel", "/usr/local/etc/redis/sentinel.conf"]depends_on:- redis-master- redis-slave1- redis-slave2volumes:redis-master-data:redis-slave1-data:redis-slave2-data:

host版本

version: '3'services:redis-master:image: redis:4.0.8container_name: redis-masternetwork_mode: hostports:- "17000:17000"volumes:- redis-master-data:/datacommand: ["redis-server", "--appendonly", "yes","--port","17000"]redis-slave1:image: redis:4.0.8container_name: redis-slave1network_mode: hostports:- "17001:17001"volumes:- redis-slave1-data:/datacommand: ["redis-server", "--slaveof", "192.168.0.203", "17000", "--appendonly", "yes","--port","17001"]depends_on:- redis-masterredis-slave2:image: redis:4.0.8container_name: redis-slave2network_mode: hostports:- "17002:17002"volumes:- redis-slave2-data:/datacommand: ["redis-server", "--slaveof", "192.168.0.203", "17000", "--appendonly", "yes","--port","17002"]depends_on:- redis-masterredis-sentinel-1:image: redis:4.0.8container_name: redis-sentinel-1network_mode: hostports:- "16000:16000"volumes:- ./sentinel16000.conf:/usr/local/etc/redis/sentinel.confcommand: ["redis-sentinel", "/usr/local/etc/redis/sentinel.conf"]depends_on:- redis-master- redis-slave1- redis-slave2redis-sentinel-2:image: redis:4.0.8container_name: redis-sentinel-2network_mode: hostports:- "16001:16001"volumes:- ./sentinel16001.conf:/usr/local/etc/redis/sentinel.confcommand: ["redis-sentinel", "/usr/local/etc/redis/sentinel.conf"]depends_on:- redis-master- redis-slave1- redis-slave2redis-sentinel-3:image: redis:4.0.8container_name: redis-sentinel-3network_mode: hostports:- "16002:16002"volumes:- ./sentinel16002.conf:/usr/local/etc/redis/sentinel.confcommand: ["redis-sentinel", "/usr/local/etc/redis/sentinel.conf"]depends_on:- redis-master- redis-slave1- redis-slave2volumes:redis-master-data:redis-slave1-data:redis-slave2-data:

 

protected-mode no
sentinel myid d1ccb49b4c07533de9e7357402dcb79e2f4a4458
sentinel monitor mymaster 192.168.0.203 17000 2
sentinel down-after-milliseconds mymaster 60000
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
port 16000
dir "/data"
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 192.168.0.203 17002
sentinel known-slave mymaster 192.168.0.203 17001
sentinel known-sentinel mymaster 192.168.0.203 16000 840260e3bf0730f1f8747114e28b8d8001967fe7
sentinel known-sentinel mymaster 192.168.0.203 16002 2aaaf350c4f5cd2baf5471b6c48b71c288b61a70
sentinel current-epoch 0
############################################################
protected-mode no
sentinel myid d1ccb49b4c07533de9e7357402dcb79e2f4a4458
sentinel monitor mymaster 192.168.0.203 17000 2
sentinel down-after-milliseconds mymaster 60000
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
port 16001
dir "/data"
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 192.168.0.203 17002
sentinel known-slave mymaster 192.168.0.203 17001
sentinel known-sentinel mymaster 192.168.0.203 16000 840260e3bf0730f1f8747114e28b8d8001967fe7
sentinel known-sentinel mymaster 192.168.0.203 16002 2aaaf350c4f5cd2baf5471b6c48b71c288b61a70
sentinel current-epoch 0
############################################################
protected-mode no
sentinel myid d1ccb49b4c07533de9e7357402dcb79e2f4a4458
sentinel monitor mymaster 192.168.0.203 17000 2
sentinel down-after-milliseconds mymaster 60000
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
port 16002
dir "/data"
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 192.168.0.203 17002
sentinel known-slave mymaster 192.168.0.203 17001
sentinel known-sentinel mymaster 192.168.0.203 16000 840260e3bf0730f1f8747114e28b8d8001967fe7
sentinel known-sentinel mymaster 192.168.0.203 16002 2aaaf350c4f5cd2baf5471b6c48b71c288b61a70
sentinel current-epoch 0


http://www.ppmy.cn/embedded/147226.html

相关文章

《Vue进阶教程》第十三课:实现依赖收集

往期内容: 《Vue进阶教程》第三课:Vue响应式原理 《Vue进阶教程》第四课:reactive()函数详解 《Vue进阶教程》第五课:ref()函数详解(重点) 《Vue进阶教程》第六课:computed()函数详解(上) 《Vue进阶教程》第七课&…

Oracle 中什么情况下 可以使用 EXISTS 替代 IN 提高查询效率

为什么 EXISTS 更高效? EXISTS 提前终止: EXISTS 一旦在子查询中找到第一个匹配项,就会立即返回 TRUE,不再继续扫描子查询中的其他记录。IN 必须扫描整个子查询的结果集,将所有结果与主查询的每一行进行对比。大数据集…

WebRTC服务质量(04)- 重传机制(01) RTX NACK概述

WebRTC服务质量(01)- Qos概述 WebRTC服务质量(02)- RTP协议 WebRTC服务质量(03)- RTCP协议 WebRTC服务质量(04)- 重传机制(01) RTX NACK概述 WebRTC服务质量(…

智能光学计算成像技术与应用

智能光学计算成像是一个将人工智能(AI)与光学成像技术相结合的前沿领域,它通过深度学习、光学神经网络、超表面光学(metaphotonics)、全息技术和量子光学等技术,推动光学成像技术的发展。以下是智能光学计算…

springcloud-gateway获取应用响应信息乱码

客户端通过springcloud gateway跳转访问tongweb上的应用,接口响应信息乱码。使用postman直接访问tongweb上的应用,响应信息显示正常。 用户gateway中自定义了实现GlobalFilter的Filter类,在该类中获取了上游应用接口的响应信息,直…

BlueLM:以2.6万亿token铸就7B参数超大规模语言模型

一、介绍 BlueLM 是由 vivo AI 全球研究院自主研发的大规模预训练语言模型,本次发布包含 7B 基础 (base) 模型和 7B 对话 (chat) 模型,同时我们开源了支持 32K 的长文本基础 (base) 模型和对话 (chat) 模型。 更大量的优质数据 :高质量语料…

推动数字金融高质量发展行动方案之数据安全解读

一、《方案》中的数据安全要求 2024年11月27日,中国人民银行等七部门联合印发《推动数字金融高质量发展行动方案》(以下简称《方案》),明确提出系统推进金融机构数字化转型、运用数字技术提升重点领域金融服务质效、夯实数字金融发展基础、完善数字金融治理体系等方面的重…

网络安全(4)_网络层安全IPSec

5. 网络层安全IPSec 5.1 IPSec协议 (1)前面使用Outlook进行数字签名和数字加密是应用层实现的安全。安全套接字实现的安全是在应用层和传输层之间插入了一层来实现数据通信安全。而IPSec是网络层实现的安全。不需要应用程序的支持,只要配置…