当前位置:网站首页>docker-compose公网部署redis哨兵模式
docker-compose公网部署redis哨兵模式
2022-07-04 12:51:00 【mp9105】
docker-compose公网部署redis哨兵模式
这里使用云服务搭建redis哨兵集群,并且暴露给公网,这里仅供测试使用,生产不要暴露到公网
网上关于redis哨兵及集群的docker有很多部署教程,参考如下
https://segmentfault.com/a/1190000040755506
https://cloud.tencent.com/developer/news/688466
这些部署教程在内网是可以使用的,但是公网下会连接不上,对主要的差异做一点记录
1 启动redis主从节点
编写reids主从docker-compose.yml
version: '3.8'
services:
master:
image: redis:6.0.8
container_name: redis-master
privileged: true
restart: always
# 注意这里 --cluster-announce-ip 指定暴露的地址,这里填写公网地址
# 这里很多部署都没有指定--masterauth,master节点重启后会无法加入到集群中
command: redis-server --port 6380 --requirepass redispwd --masterauth redispwd --appendonly yes --cluster-announce-ip xxx.xxx.xxx.xxx --cluster-announce-port 6380 --cluster-announce-bus-port 16380
ports: # 与上面指定的--port一致
- 6380:6380
volumes:
- ./data1:/data
slave1:
image: redis:6.0.8
container_name: redis-slave-1
privileged: true
restart: always
# 这里有个坑,--slaveof不要直接写redis-master,否则会被识别为内网IP
command: redis-server --port 6381 --slaveof xxx.xxx.xxx.xxx 6380 --requirepass redispwd --masterauth redispwd --appendonly yes --cluster-announce-ip xxx.xxx.xxx.xxx --cluster-announce-port 6381 --cluster-announce-bus-port 16381
ports: # 与上面指定的--port一致
- 6381:6381
volumes:
- ./data2:/data
slave2:
image: redis:6.0.8
container_name: redis-slave-2
privileged: true
restart: always
command: redis-server --port 6382 --slaveof xxx.xxx.xxx.xxx 6380 --requirepass redispwd --masterauth redispwd --appendonly yes --cluster-announce-ip xxx.xxx.xxx.xxx --cluster-announce-port 6382 --cluster-announce-bus-port 16382
ports: # 与上面指定的--port一致
- 6382:6382
volumes:
- ./data3:/data
networks:
default:
external:
name: redis_default
进入redis对应的docker-compose.yml的目录,执行命令:
# 创建网络,有的话就不需要创建了
docker network create redis_default
# -d表示后台运行
docker-compose up -d
2 哨兵文件准备
编写docker-compose.yml
version: '3.8'
services:
sentinel1:
image: redis:6.0.8
container_name: redis-sentinel-1
privileged: true
restart: always
ports:
- 26380:26380
volumes:
- ./sentinel1.conf:/usr/local/etc/redis/sentinel.conf
command: bash -c "redis-sentinel /usr/local/etc/redis/sentinel.conf && chmod 777 /usr/local/etc/redis/sentinel.conf"
sentinel2:
image: redis:6.0.8
container_name: redis-sentinel-2
privileged: true
restart: always
ports:
- 26381:26380
volumes:
- ./sentinel2.conf:/usr/local/etc/redis/sentinel.conf
command: bash -c "redis-sentinel /usr/local/etc/redis/sentinel.conf && chmod 777 /usr/local/etc/redis/sentinel.conf"
sentinel3:
image: redis:6.0.8
container_name: redis-sentinel-3
privileged: true
ports:
- 26382:26380
volumes:
- ./sentinel3.conf:/usr/local/etc/redis/sentinel.conf
command: bash -c "redis-sentinel /usr/local/etc/redis/sentinel.conf && chmod 777 /usr/local/etc/redis/sentinel.conf"
networks:
default:
external:
name: redis_default
编写 sentinel.conf 配置文件
# mymaster是自定义集群名
# xxx.xxx.xxx.xxx 主节点IP的公网地址
# 6380 为 redis-master 的端口,2 为最小投票数(因为有 3 台 Sentinel 所以可以设置成 2)
port 26380
dir /tmp
# protected-mode no
# bind 0.0.0.0
sentinel monitor mymaster xxx.xxx.xxx.xxx 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
# 密码与上面保持一致
sentinel auth-pass mymaster redispwd
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
将上述文件分别拷贝3份分别命名为sentinel1.conf、sentinel2.conf、sentinel3.conf与docker-compose.yml中的配置文件对应,然后放置和哨兵的docker-compose.yml在同一目录
3 启动哨兵
# 进入docker-compose.yml所在文件夹执行
docker-compose up -d
4 测试连接
以ARDM为例,填写对应信息

可以正常连接

边栏推荐
- 常见 content-type对应表
- 学内核之三:使用GDB跟踪内核调用链
- 吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
- Fs4059c is a 5V input boost charging 12.6v1.2a. Inputting a small current to three lithium battery charging chips will not pull it dead. The temperature is 60 ° and 1000-1100ma is recommended
- 读取 Excel 表数据
- What is the real meaning and purpose of doing things, and what do you really want
- [antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
- 为什么图片传输要使用base64编码
- 海外游戏代投需要注意的
- TestSuite and testrunner in unittest
猜你喜欢

MySQL5免安装修改
![[FAQ] summary of common causes and solutions of Huawei account service error 907135701](/img/43/1a9786c89a5ab21d1fb8903cb7b77e.png)
[FAQ] summary of common causes and solutions of Huawei account service error 907135701

【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value

Innovation and development of independent industrial software

C# wpf 实现截屏框实时截屏功能

JVM memory layout detailed, illustrated, well written!
![递增的三元子序列[贪心训练]](/img/92/7efd1883c21c0e804ffccfb2231602.png)
递增的三元子序列[贪心训练]

吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest

Deming Lee listed on Shenzhen Stock Exchange: the market value is 3.1 billion, which is the husband and wife of Li Hu and Tian Hua

国内酒店交易DDD应用与实践——代码篇
随机推荐
The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
gorm 之数据插入(转)
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
Common content type correspondence table
德明利深交所上市:市值31亿 为李虎与田华夫妻档
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
MySQL5免安装修改
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
MySQL version 8 installation Free Tutorial
测试流程整理(3)
go vendor 项目迁移到 mod 项目
MATLAB中tiledlayout函数使用
2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
How to package QT and share exe
Error in find command: paths must precede expression (turn)
Gorm data insertion (transfer)
Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
Understand chisel language thoroughly 08. Chisel Foundation (V) -- wire, REG and IO, and how to understand chisel generation hardware