当前位置:网站首页>redis主从、哨兵主备切换搭建一步一步图解实现
redis主从、哨兵主备切换搭建一步一步图解实现
2022-07-07 15:38:00 【诗风雅韵】
- Redis支持主从复用。数据可以从主服务器向任意数量的从服务器上同步,同步使用的是发布/订阅机制。Mater Slave的模式,从Slave向Master发起SYNC命令。
- 可以是1 Master 多Slave,可以分层,Slave下可以再接Slave,可扩展成树状结构。
- 因为没有两台电脑,所以只能在一台机器上搭建两个Redis服务端。
- 这里使用单机来模拟redis 主从服务器 ,实现读写分离配置。
文章目录
创建三个目录(数据文件、日志文件、配置文件)
复制redis.conf至/opt/redis/conf目录下
修改redis-common.conf公共配置文件
注释掉bind 127.0.0.1
关闭保护模式,修改为no
注释公共配置端口
修改为后台启动
注释进程编号记录文件
注释公共配置数据文件、修改数据文件路径
在默认情况下,Redis 将数据库快照保存在名字为 dump.rdb 的二进制文件中。当然,这里可以通过修改redis.conf 配置文件来对数据存储条件进行定义,规定在“ N 秒内数据集至少有 M 个改动”这一条件被满足时,自动保存一次数据集。也可以通过调用save 或bgsave ,手动让Redis进行数据集保存操作dbfilename和dir组合使用,dbfilename找dir路径生成数据文件
添加从服务器访问主服务器认证
添加访问认证
注释公共配置追加文件
添加3个服务的私有配置文件
touch 或者 vi 都可以创建空白文件
touch 直接创建空白文件, vi 创建并且进入编辑模式, :wq 创建成功,否则不创建
redis-6379.conf
#引用公共配置
include /opt/redis/conf/redis-common.conf
#进程编号记录文件
pidfile /var/run/redis-6379.pid
#进程端口号
port 6379
#日志记录文件
logfile "/opt/redis/log/redis-6379.log"
#数据记录文件
dbfilename dump-6379.rdb
#追加文件名称
appendfilename "appendonly-6379.aof"
#下面的配置无需在6379里配置
#备份服务器从属于6379推荐配置配局域网IP
slaveof 192.168.10.100 6379
redis-6380.conf
#引用公共配置
include /opt/redis/conf/redis-common.conf
#进程编号记录文件
pidfile /var/run/redis-6380.pid
#进程端口号
port 6380
#日志记录文件
logfile "/opt/redis/log/redis-6380.log"
#数据记录文件
dbfilename dump-6380.rdb
#追加文件名称
appendfilename "appendonly-6380.aof"
#下面的配置无需在6379里配置
#备份服务器从属于6379推荐配置配局域网IP
slaveof 192.168.32.200 6379
redis-6381.conf
include /opt/redis/conf/redis-common.conf
#进程编号记录文件
pidfile /var/run/redis-6381.pid
#进程端口号
port 6381
#日志记录文件
logfile "/opt/redis/log/redis-6381.log"
#数据记录文件
dbfilename dump-6381.rdb
#追加文件名称
appendfilename "appendonly-6381.aof"
#下面的配置无需在6379里配置
#备份服务器从属于6379推荐配置配局域网IP
slaveof 192.168.32.200 6379
运行3个redis进程
查看redis服务器主从状态
redis-6379
redis-6380
redis-6381
哨兵配置
主从节点redis.conf配置
参照 读写分离 的相应配置
修改sentinel-common.conf 哨兵公共配置文件
从redis解压目录下复制sentinel.conf至/opt/redis/conf/
修改名字
修改配置信息
注释哨兵监听进程端口号
要配局域网IP,否则远程连不上
设置master和slaves的密码
关闭保护模式,修改为no
修改为后台启动
添加3个哨兵的私有配置文件
touch 或者 vi 都可以创建空白文件
touch 直接创建空白文件, vi 创建并且进入编辑模式, :wq 创建成功,否则不创建
sentinel-26379.conf
#引用公共配置
include /opt/redis/conf/sentinel-common.conf
#进程端口号
port 26379
#进程编号记录文件
pidfile /var/run/sentinel-26379.pid
#日志记录文件(为了方便查看日志,先注释掉,搭好环境后再打开)
logfile "/opt/redis/log/sentinel-26379.log"
复制 sentinel-26379.conf 的内容至 sentinel-26380.conf , sentinel-26381.conf 并且修改其内容,将26379
替换即可。
启动测试
启动3个redis服务
启动3个哨兵服务
查看哨兵是否完成
边栏推荐
- DNS 系列(一):为什么更新了 DNS 记录不生效?
- 【图像传感器】相关双采样CDS
- 【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
- rpcms获取指定分类下的文章的方法
- Nerf: the ultimate replacement for deepfake?
- [image sensor] correlated double sampling CDs
- Test case management tool recommendation
- [source code interpretation] | source code interpretation of livelistenerbus
- QML初学
- QT picture background color pixel processing method
猜你喜欢
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
Sator推出Web3遊戲“Satorspace” ,並上線Huobi
DevOps 的运营和商业利益指南
Mrs offline data analysis: process OBS data through Flink job
SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
QT 图片背景色像素处理法
Arduino 控制的双足机器人
SlashData开发者工具榜首等你而定!!!
随机推荐
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
[Huang ah code] Why do I suggest you choose go instead of PHP?
LeetCode 1155. N ways to roll dice one question per day
Jenkins发布uniapp开发的H5遇到的问题
【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)
如何在软件研发阶段落地安全实践
Module VI
Arduino 控制的双足机器人
【Seaborn】组合图表:PairPlot和JointPlot
Pychart ide Download
LeetCode 1186. Delete once to get the sub array maximum and daily question
LeetCode 1186. 删除一次得到子数组最大和 每日一题
如何在博客中添加Aplayer音乐播放器
SlashData开发者工具榜首等你而定!!!
Lowcode: four ways to help transportation companies enhance supply chain management
赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
MRS离线数据分析:通过Flink作业处理OBS数据
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
电脑无法加域,ping域名显示为公网IP,这是什么问题?怎么解决?
LeetCode 1986. The minimum working time to complete the task is one question per day