docker 搭建 redis 集群(哨兵模式)
2024-09-03 18:16:00
文件结构
1. redis-sentinel
1-1. docker-compose.yml
1-2. sentinel
1-2-1 docker-compose.yml
1-2-2 sentinel.conf
1-2-3 sentinel1.conf
1-2-4 sentinel2.conf
1-2-5 sentinel3.conf
1、docker-compose 文件实现一主两从
编写docker-compose.yml文件,内容如下:
version: '3.7'
services:
master:
image: redis
container_name: redis-master
restart: always
command: redis-server --requirepass GaosiDev --masterauth GaosiDev
ports:
- 6380:6379
slave1:
image: redis
container_name: redis-slave-1
restart: always
command: redis-server --slaveof redis-master 6379 --requirepass GaosiDev --masterauth GaosiDev
ports:
- 6381:6379
slave2:
image: redis
container_name: redis-slave-2
restart: always
command: redis-server --slaveof redis-master 6379 --requirepass GaosiDev --masterauth GaosiDev
ports:
- 6382:6379
docker-compose 文件实现 sentinel
version: '2'
services:
sentinel1:
image: redis ## 镜像
container_name: redis-sentinel-1
ports:
- "26379:26379"
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- "./sentinel1.conf:/usr/local/etc/redis/sentinel.conf"
sentinel2:
image: redis ## 镜像
container_name: redis-sentinel-2
ports:
- "26380:26379"
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- "./sentinel2.conf:/usr/local/etc/redis/sentinel.conf"
sentinel3:
image: redis ## 镜像
container_name: redis-sentinel-3
ports:
- "26381:26379"
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
volumes:
- ./sentinel3.conf:/usr/local/etc/redis/sentinel.conf
networks:
default:
external:
name: redis-sentinel_default ##通过(docker inspect 主节点容器id)来查看,对应 NetworkMode
编辑 sentinel.conf 文件
port 26379
dir /tmp
#172.18.0.3填写自己的主节点ip,通过(docker inspect 主节点容器id)来查看,对应 IPAddress
sentinel monitor mymaster 172.17.0.4 6379 2
sentinel auth-pass mymaster GaosiDev
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000
sentinel deny-scripts-reconfig yes
参考链接
https://www.cnblogs.com/ruiyeclub/p/12355073.html
https://www.cnblogs.com/JulianHuang/p/12650721.html
最新文章
- XML和JSON数据格式对比
- Oracle GoldenGate 12c (12.1.2.0.1) for IBM DB2 iSeries
- php文本操作方法集合比较
- hadoop2.6.0汇总:新增功能最新编译 32位、64位安装、源码包、API下载及部署文档
- yii中的自定义组件
- 【转】【opencv】仿射变换
- 对于方法 String.Contains,只支持可在客户端上求值的参数。
- iOS推送证书p12转成pem
- Spring+SpringMVC+MyBatis+easyUI整合基础篇(六)maven整合SSM
- 面向对象编程思想(前传)--你必须知道的javascript
- 移动开发必须要弄明白的问题】详解Eclipse转Android Studio
- 为什么用CDN给你网站加速?
- Scala - 快速学习04 - 求值策略
- java学习笔记37(sql工具类:JDBCUtils)
- ubuntu6.4系统安装JIRA-7.8
- Zookeeper中Session Timeout的那些事
- 2. Python3输入与输出
- js 字符中 带 函数 再传对象参数
- echarts一些笔记
- OpenStack入门篇(一)之云计算的概念