当前位置:网站首页>docker+bridge+redis master-slave+sentry mode
docker+bridge+redis master-slave+sentry mode
2022-08-04 03:05:00 【that's the name】
docker+网桥+redis主从+哨兵模式
I'm experimenting on two servers,一台服务器的ip是192.168.213.144,另一台服务器的ip是192.168.213.145
1. build a bridge
For the first part of building a bridge, you can refer to my blog,will be a little more detailed,https://blog.csdn.net/weixin_45753881/article/details/125973566
1.1 新建网桥
给主机192.168.213.144 The network segment assigned by the bridge is 172.20.144.0/24
给主机192.168.213.145 The network segment assigned by the bridge is 172.20.145.0/24
#在主机144上执行
docker network create --subnet=172.20.144.0/24 --gateway 172.20.144.1 redisbridge
#在主机145上执行
docker network create --subnet=172.20.145.0/24 --gateway 172.20.145.1 redisbridge
1.2 添加路由
#在主机144上执行
route add -net 172.20.144.0/24 gw 172.20.144.1
#在主机145上执行
route add -net 172.20.145.0/24 gw 172.20.145.1
1.3 配置iptables规则
#在主机144上执行
iptables -t nat -I PREROUTING -s 172.20.144.0/24 -d 172.20.145.0/24 -j DNAT --to 172.20.144.1
#在主机145上执行
iptables -t nat -I PREROUTING -s 172.20.145.0/24 -d 172.20.144.0/24 -j DNAT --to 172.20.145.1
2. 配置redis.conf
2.1 下载redis.conf(主机144和主机145都执行)
# 如果没有安装yum,需要先安装yum
yum -y install wget
# 下载redis.conf,下载路径为/root/redis.conf,You can also download to other paths,Remember to run createdocker容器命令(步骤3.1和3.2)Also change it to the address where you downloaded it
wget http://download.redis.io/redis-stable/redis.conf
# 在服务器的/root目录下创建redis.log文件,Other paths are also possible,Remember to run createdocker容器命令(步骤3.1和3.2)Also change it to the address you set
touch redis.log
# 给redis.log赋予权限
chmod 777 redis.log
2.2 配置redis.conf
2.2.1 配置redis主的redis.conf(主机144)
(1)注释 # bind 127.0.0.1
(2)关闭保护模式 protected-mode no
(3)(可选)设定密码 requirepass yourpwd
(4)配置日志路径,为了便于排查问题 logfile “/var/log/redis/redis.log”
# bind 127.0.0.1
protected-mode no
requirepass yourpwd
logfile "/var/log/redis/redis.log"
2.2.2 配置redis从的redis.conf(主机145)
(1)注释 # bind 127.0.0.1
(2)关闭保护模式 protected-mode no
(3)(可选)设定密码 requirepass yourpwd
(4)配置日志路径,为了便于排查问题 logfile “/var/log/redis/redis.log”
(5)配置主库的ip和端口 replicaof 192.xxx.xxx.xxx 6379
192.xxx.xxx.xxx It is the server where the main library is locatedip,6379 是主库redis端口
(6)(视情况而定)If the master library is configured with a password,Then fill in the main library password here;If the main library does not set a password,就不用配 masterauth 主库密码
# bind 127.0.0.1
protected-mode no
requirepass yourpwd
logfile "/var/log/redis/redis.log"
replicaof 192.xxx.xxx.xxx 6379 # Remember to replace hereip
masterauth 主库密码
3. 部署redis主从
3.1 部署redis主节点
# --network redisbridge is the bridge used
# -e TZ=Asia/Shanghai 设置时区
docker run --network redisbridge --name redis_master --restart=always -e TZ=Asia/Shanghai -v /root/redis.conf:/usr/local/etc/redis/redis.conf -v /root/redis.log:/var/log/redis/redis.log -d -p 6379:6379 redis:7.0.4 redis-server /usr/local/etc/redis/redis.conf
3.2 部署redis从节点
docker run --network redisbridge --name redis_slave --restart=always -e TZ=Asia/Shanghai -v /root/redis.conf:/usr/local/etc/redis/redis.conf -v /root/redis.log:/var/log/redis/redis.log -d -p 6379:6379 redis:7.0.4 redis-server /usr/local/etc/redis/redis.conf
3.3 查看主从
# 进入redis从节点
docker exec -it redis_slave redis-cli
# 如果redis配置了密码,Password verification is performed,If the verification is passed, it will be printedOK
auth 密码
# info进行查看
info

4. 配置哨兵
4.1 配置sentinel.conf(Executed on all hosts)
# 下载sentinel.conf到/root路径下,You can also download to other paths,Remember to run createdocker容器命令(步骤4.2.1和4.2.2)Also change it to the address where you downloaded it
wget http://download.redis.io/redis-stable/sentinel.conf
# 在服务器的/root目录下创建sentinel.log文件,Other paths are also possible,Remember to run createdocker容器命令(步骤4.2.1和4.2.2)Also change it to the address you set
touch sentinel.log
# sentinel.log赋予权限
chmod 777 sentinel.log
修改sentinel.conf以下几项
# 编辑sentinel.conf,进行以下配置,这里ip改成自己的服务器地址
sentinel monitor mymaster 192.168.213.144 6379 1
# 修改日志文件的路径
logfile "/var/log/redis/sentinel.log"
# 修改监控的主redis服务器,最后一个1表示,1After each machine determines that the active and passive are offline,就进行failover(故障转移)
sentinel monitor mymaster 192.168.213.144 6379 2
4.2 创建sentinel容器
4.2.1 在redisExecuted on the host where the master node is located
docker run --network redisbridge --name sentinel_master --ip 172.20.144.3 -p 26379:26379 --restart=always -e TZ=Asia/Shanghai -v /root/sentinel.conf:/usr/local/etc/redis/sentinel.conf -v /root/sentinel.log:/var/log/redis/sentinel.log -d redis:7.0.4 redis-sentinel /usr/local/etc/redis/sentinel.conf
4.2.2 在redisExecute from the host where the node is located
docker run --network redisbridge --name sentinel_slave --ip 172.20.145.3 -p 26379:26379 --restart=always -e TZ=Asia/Shanghai -v /root/sentinel.conf:/usr/local/etc/redis/sentinel.conf -v /root/sentinel.log:/var/log/redis/sentinel.log -d redis:7.0.4 redis-sentinel /usr/local/etc/redis/sentinel.conf
4.3 测试哨兵
(1)停掉redis主节点,等30秒后,进入redisUse from nodeinfoCheck whether the slave node is switched to the master node
(2)Also available on the server/root路径下使用cat sentinel.log查看日志(/root/sentinel.logis configured in the previous step)
边栏推荐
- 【指针内功修炼】深度剖析指针笔试题(三)
- 小程序+新零售,玩转行业新玩法!
- 阿里云国际版基于快照与镜像功能迁移云服务器数据
- 单片机C语言->的用法,和意思
- Deep Learning (3) Classification Theory Part
- C语言--环形缓存区
- Simple record of Flink principle flow chart
- Asynchronous programming solution Generator generator function, iterator iterator, async/await, Promise
- flinkcdc 消费 mysql binlog 没有 sqltype=delete 的数据是什么原
- 董明珠直播时冷脸离场,员工频犯低级错误,自家产品没人能弄明白
猜你喜欢

一个属于程序员的七夕节!

y86.第四章 Prometheus大厂监控体系及实战 -- prometheus存储(十七)

【学习笔记之菜Dog学C】动态内存管理

Zabbix设置邮件告警+企业微信告警

全网没有之一的JMeter 接口测试流程详解

深度学习(三)分类 理论部分
编写 BOLL 心得体会

一文看懂推荐系统:召回05:矩阵补充、最近邻查找,工业界基本不用了,但是有助于理解双塔模型

new Date将字符串转化成日期格式 兼容IE,ie8如何通过new Date将字符串转化成日期格式,js中如何进行字符串替换, replace() 方法详解

数据安全峰会2022 | 美创DSM获颁“数据安全产品能力验证计划”评测证书
随机推荐
The keytool command
There are too many systems, how to realize multi-account interworking?
sqoop ETL tool
织梦内核电动伸缩门卷闸门门业公司网站模板 带手机版【站长亲测】
Oracle迁移到瀚高之后,空值问题处理
[QNX Hypervisor 2.2 User Manual] 10.3 vdev gic
0.1 前言
异步编程解决方案 Generator生成器函数、iterator迭代器、async/await、Promise
docker+网桥+redis主从+哨兵模式
uni-app 从零开始-基础模版(一)
How many ways do you know about communication between multiple threads?
KingbaseES数据库启动失败,报“内存段超过可用内存”
yum 仅下载包
【医保科普】维护医保基金安全,我们可以这样做
返回字符串中的最大回文数
Development of Taurus. MVC WebAPI introductory tutorial 1: download environment configuration and operation framework (including series directory).
阿里云国际版基于快照与镜像功能迁移云服务器数据
三分建设,七分管理!产品、系统、组织三管齐下节能降耗
tkmapper的crud示例:
2022焊工(初级)上岗证题目模拟考试平台操作