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

可以正常连接

边栏推荐
- GCC【6】- 编译的4个阶段
- [R language data science]: cross validation and looking back
- 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
- Basic mode of service mesh
- 1200. Minimum absolute difference
- 吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
- Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
- 使用默认路由作为指向Internet的路由
- 硬件基础知识-二极管基础
- LiveData
猜你喜欢

The font of markdown grammar is marked in red

Unity Shader学习(三)试着绘制一个圆

Summary of recent days (non-technical article)

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

【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法

MySQL之详解索引
![[FAQ] Huawei Account Service Error Report 907135701 Common reasons Summary and Solutions](/img/43/1a9786c89a5ab21d1fb8903cb7b77e.png)
[FAQ] Huawei Account Service Error Report 907135701 Common reasons Summary and Solutions

Install MySQL

使用默认路由作为指向Internet的路由

TestSuite and testrunner in unittest
随机推荐
【FAQ】華為帳號服務報錯 907135701的常見原因總結和解决方法
Understand chisel language thoroughly 09. Chisel project construction, operation and testing (I) -- build and run chisel project with SBT
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
安装Mysql
2022游戏出海实用发行策略
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
基于PaddleX的智能零售柜商品识别
MongoDB常用28条查询语句(转)
Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
Code hoof collection of wonderful secret place
瑞吉外卖笔记
find命令报错: paths must precede expression(转)
QT how to detect whether the mouse is on a control
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
Programmer anxiety
海外游戏代投需要注意的
IDEA快捷键大全
常见 content-type对应表