当前位置:网站首页>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个哨兵服务
查看哨兵是否完成
边栏推荐
- LeetCode 1696. 跳跃游戏 VI 每日一题
- Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
- Matplotlib绘制三维图形
- Seaborn data visualization
- 【源码解读】| LiveListenerBus源码解读
- LeetCode 1626. The best team without contradiction
- A tour of gRPC:03 - proto序列化/反序列化
- [image sensor] correlated double sampling CDs
- [video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
- 科普达人丨一文弄懂什么是云计算?
猜你喜欢
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
Nerf: the ultimate replacement for deepfake?
如何在博客中添加Aplayer音乐播放器
DevOps 的运营和商业利益指南
Shallow understanding Net core routing
Sator推出Web3游戏“Satorspace” ,并上线Huobi
Arduino 控制的双足机器人
正在准备面试,分享面经
Sator launched Web3 game "satorspace" and launched hoobi
麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
随机推荐
自定义View必备知识,Android研发岗必问30+道高级面试题
skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
【饭谈】如何设计好一款测试平台?
DNS 系列(一):为什么更新了 DNS 记录不生效?
Sator推出Web3游戏“Satorspace” ,并上线Huobi
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
QML beginner
LeetCode 1986. The minimum working time to complete the task is one question per day
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
LeetCode 1155. N ways to roll dice one question per day
Sator推出Web3遊戲“Satorspace” ,並上線Huobi
【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid
LeetCode 120. 三角形最小路径和 每日一题
LeetCode 1186. Delete once to get the sub array maximum and daily question
The computer cannot add a domain, and the Ping domain name is displayed as the public IP. What is the problem? How to solve it?
mysql实现两个字段合并成一个字段查询
Notes on installing MySQL in centos7
鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
[fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
【Seaborn】组合图表:PairPlot和JointPlot