当前位置:网站首页>redis 集群一 · 主从模式
redis 集群一 · 主从模式
2022-04-22 05:49:00 【疯飙的蜗牛】
redis有三种集群模式,分别是 主从模式、Sentinel(哨兵)模式、 Cluster模式
主从模式:最简单的机构,分为主数据库Master和从数据库Slave。
1、特点如下:
1、主数据库进行读写操作,当数据变化时会自动将数据同步给从数据库
2、从数据库只读,并且接收主数据库同步过来的数据
3、一个Master可以拥有多个slave,但是一个slave只能对应一个Master
4、slave挂了不影响其它slave的读和master的读写,重新启动后会将数据从Master同步过来
5、master挂了以后,不影响slave的读,但是redis不再提供写服务,master重启后redis将重新对外提供写服务
6、Master挂了以后,不会在slave节点中重新选一个Master
2、工作机制:
当slave启动后,主动向Master发送SYNC命令。
Master接收到SYNC命令后在后台保存快照(RDB持久化)和缓存保存快照这段时间的命令,
然后将保存的快照文件和缓存的命令发送给slave。slave接收到快照文件和命令后加载快照文件和缓存的执行命令。
复制初始化后,Master每次接收到的写命令都会同步发送给slave,保证主从数据一致性。
3、缺点:
master节点是主从模式中唯一,若master挂掉,则redis无法对外提供写服务
4、主从模式搭建
Master 10.2.33.102
slave 10.2.33.103
slave 10.2.33.104
Master配置简介
yum -y install redis
vim /etc/redis.conf
logfile /var/log/redis/redis.log #日志路径
daemonize yes #允许后台启动
bind 0.0.0.0 #监听ip,多个ip用空格分隔
dir /var/lib/redis #数据库备份文件存放目录
masterauth redis123456 #slave连接master密码,可省略
requirepass redis123456 #设置连接密码,slave可省略
appendonly yes #在备份目录生成appendonly.aof文件,将每次操作请求追加到文件
slave(2台配置一样就行)
yum -y install redis
vim /etc/redis.conf
daemonize yes
logfile /var/log/redis/redis.log
dir /var/lib/redis
slaveof 10.2.33.102 6379
requirepass redis123456
masterauth redis123456
appendonly yes
启动服务,并查看集群状态
10.2.33.102:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=10.2.33.103,port=6379,state=online,offset=7154,lag=1
slave0:ip=10.2.33.104,port=6379,state=online,offset=7154,lag=1
master_replid:c3971bcba023986c77ebf98ed01696ebfcced9ac
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:7270
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:7270
版权声明
本文为[疯飙的蜗牛]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zhangxueleishamo/article/details/121470922
边栏推荐
- On the relationship between the Euler angle of RT matrix and the type of pose in Halcon in hand eye calibration
- pip freeze 导出含有路径 (@ file:///) 问题小记
- Jeecgboot online development 2
- Automatically obtain the specified path folder and delete the folder and sub files
- 2021-10-25
- ROG攻击
- 利用 PHP POST 临时文件机制实现任意文件上传
- Pytest(二)
- Failed to execute ‘insertBefore‘ on ‘Node‘: The node before which the new node is to ... report errors
- Redis指令
猜你喜欢
随机推荐
Heap basic operation source code Bing
vector与arrange的异同(小记)
Redis指令
qt中ShellExecute、ShellExecuteEx和WinExec的用法和区别
qt.qpa.plugin: Could not find the Qt platform plugin “xcb“ in ““
Fastapi (II)
uniapp 热更新带进度条
解决js计算精度问题
数据/组件绑定的各种情况
Analysis of Modbus Protocol in TCP communication
搞懂Promise async await 之间的联系
QWebsocket通信
转义符\ 数据格式的拼接
JS逆向实战:有道翻译接口分析
发布你自己的轮子 - PyPI打包上传实践
Detailed description of log4j configuration file
Single and multi-channel image contrast processing
qt Debug版本运行正常Release版本运行奔溃
协程future对象及concurrent.futures
关于常量指针、指针常量的使用--练习题(记录)









