当前位置: 首页 > news >正文

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

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.mrgr.cn/news/80813.html

相关文章:

  • 为什么要用单例模式?
  • Linux环境下 搭建ELk项目 -单机版练习
  • Avalonia实例实战四:使用AutoCompleteBox自动补全框做用户名输入框
  • 【数据集】50种汽车零件分类识别数据集10382张YOLO+VOC格式(已增强)
  • Arduino ADC模数转换
  • 我们需要什么样的运维:以业务目标为导向的运维体系建设
  • js分页功能
  • 【Python】使用Selenium 操作浏览器 自动化测试 记录
  • regression里面的误差来源
  • Pytorch | 从零构建AlexNet对CIFAR10进行分类
  • Linux函数栈帧
  • windows上安装Redis
  • 对AI现状和未来发展的浅见
  • 关于代码注释
  • 分布式算法(一):从ACID和BASE到CAP
  • 面试题整理6----什么是进程最大数、最大线程数、进程打开的文件数,怎么调整
  • 百度飞桨:零基础入门深度学习
  • cocos creator制作2dTop-down游戏(虚拟摇杆、地图加载)
  • C# 基本信息介绍
  • python之OpenGL应用(1)入门篇
  • TCP拥塞控制
  • 2024年12月英语六级CET6写作与翻译笔记
  • 实现线程同步的方法
  • WSL Ubuntu
  • 1、数据库概念和mysql表的管理
  • AQS源码学习