当前位置:网站首页>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为例,填写对应信息

可以正常连接

边栏推荐
- JVM memory layout detailed, illustrated, well written!
- Gorm data insertion (transfer)
- mac redis安装与使用,连接远程服务器 redis
- 国内酒店交易DDD应用与实践——代码篇
- The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
- 吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
- Introducing testfixture into unittest framework
- 【C 题集】of Ⅶ
- 数据仓库面试问题准备
- sharding key type not supported
猜你喜欢

硬件基础知识-二极管基础

Understand chisel language thoroughly 05. Chisel Foundation (II) -- combinational circuits and operators

Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc

吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行

Install MySQL
![[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

Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test

自主工业软件的创新与发展

为什么图片传输要使用base64编码

華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
随机推荐
锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
如何游戏出海代运营、游戏出海代投
MySQL8版本免安装步骤教程
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
The font of markdown grammar is marked in red
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布
vscode 常用插件汇总
读取 Excel 表数据
【C 题集】of Ⅶ
LifeCycle
常见 content-type对应表
吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
BLOB,TEXT GEOMETRY or JSON column 'xxx' can't have a default value query 问题
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
Install MySQL
The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"