当前位置:网站首页>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为例,填写对应信息
可以正常连接
边栏推荐
- 2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
- 学内核之三:使用GDB跟踪内核调用链
- Summary of recent days (non-technical article)
- Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
- golang fmt.printf()(转)
- IP 实验室月复盘 · 第 5 期
- Assertion of unittest framework
- Unity shader learning (3) try to draw a circle
- 吃透Chisel语言.04.Chisel基础(一)——信号类型和常量
- 吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
猜你喜欢
Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
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
1200. Minimum absolute difference
[matlab] summary of conv, filter, conv2, Filter2 and imfilter convolution functions
Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
392. Judgement subsequence
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
随机推荐
2022 practice questions and mock exams for the main principals of hazardous chemical business units
10.(地图数据篇)离线地形数据处理(供Cesium使用)
吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
Assertion of unittest framework
中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
Worried about "cutting off gas", Germany is revising the energy security law
吃透Chisel语言.03.写给Verilog转Chisel的开发者(没有Verilog基础也可以看看)
吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
The font of markdown grammar is marked in red
R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
sharding key type not supported
Golang uses JSON unmarshal number to interface{} number to become float64 type (turn)
DDD application and practice of domestic hotel transactions -- Code
golang fmt.printf()(转)
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
IDEA快捷键大全
[R language data science]: cross validation and looking back
JVM memory layout detailed, illustrated, well written!
gorm 之数据插入(转)
TestSuite and testrunner in unittest