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

server/2024/12/20 18:55:51/

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"
############################################################
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"
############################################################
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"


http://www.ppmy.cn/server/151759.html

相关文章

Redis篇-15--数据结构篇7--Sorted Set内存模型(有序集合,跳跃表skip list,压缩列表ziplist)

1、概述 Redis的Sorted Set是一种有序集合,它不仅存储唯一的元素,还为每个元素关联一个分数(score),用于对元素进行排序。为了在保证高效性能的同时节省内存,Redis对Sorted Set 的底层实现进行了多种优化。…

spring实例化对象的几种方式(使用XML配置文件)

前言 Spring框架作为一个轻量级的控制反转(IoC)容器,为开发者提供了多种对象实例化的策略。通过这些策略,开发者可以更加灵活地控制对象的生命周期和依赖关系。无论是通过XML配置、注解配置还是Java配置,Spring都能…

Swagger自动文档工具以及gin-swagger的使用

什么是 Swagger? Swagger 是一个开源的 API 设计和文档工具,旨在帮助开发者更高效地设计、构建、记录和测试 RESTful API。它基于 OpenAPI 规范(前身为 Swagger 规范),通过自动化的方式生成交互式 API 文档、客户端 S…

docker入门实践---虚拟机环境配置

文章目录 1.检查内核版本2.确定centos7可以上网3.关闭防火墙4.关闭防火墙5.更换阿里云6.安装gcc7.设置镜像仓库(阿里云)8更新软件包9.安装docket-ce10.启动docker11.普通用户权限设置 1.检查内核版本 2.确定centos7可以上网 3.关闭防火墙 下面的这个表示…

汽车故障码B100016解析及消除方法

汽车故障码B100016解析 1. 故障码含义 汽车故障码B100016通常与汽车电池系统或发动机相关的问题有关。具体而言,该故障码指示了电池电压过低、电池电流异常或发动机火花塞出现问题。 2. 可能原因 电池电压过低:电池老化或电池充电不足,导致电压低于正常范围。电池电流异常…

js的?. 和??和||有什么区别

let a 0; let b null; let c Hello;console.log(a ?? default); // 0 console.log(b ?? default); // "default" console.log(c ?? default); // "Hello"console.log(a || default); // "default" (因为 0 是假值) console.log(b |…

Intel(R) Iris(R) Xe Graphics安装Anaconda、Pytorch(CPU版本)

一、Intel(R) Iris(R) Xe Graphics安装Anaconda 下载网址:https://repo.anaconda.com/archive/ 双击Anaconda3-2024.10-1-Windows-x86_64,一直下一步,选择安装的路径位置,一直下一步就安装完成了。打开Anaconda PowerShell Promp…

省略内容在句子中间

一、使用二分查找法 每次查找时,将查找范围分成两半,并判断目标值位于哪一半,从而逐步缩小查找范围。 循环查找 计算中间位置 mid Math.floor((low high) / 2)。比较目标值 target 和中间位置的元素 arr[mid]: 如果 target ar…