当前位置:网站首页>redis主从架构锁失效问题(主从)
redis主从架构锁失效问题(主从)
2022-07-25 21:43:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
一、准备 1、修改pidfile 和端口
2、关闭RDB持久化修改持久化文件的保存位置
3、启动Redis
redis-server /etc/redis.conf4、使用客户端连接Redis
redis-cli二、主从复制(读写分离) redis的主从复制功能非常强大,一个master可以拥有多个slave,而一个slave又可以拥有多个slave,如此下去,形成了强大的多级服务器集群架构.可以避免redis单点故障,构建读写分离架构,满足读多写少的应用场景. 1、主从复制原理
①slave发起请求和master建立连接,master验证通过后即可建立连接。 ②slave发送同步sync的命令,这时主库会新起一个子进程,以快照的方式把数据导入到rdb文件中,并传输给从库 ③从库将rdb文件导入到数据库中,并加载到内存 ④在后面做同步的时候,master会把所有命令先buffer起来,不会往磁盘写,直接给slave。 备注:如果master重启,备份数据会重新dump。
2、Redis复制功能的几个重要方面
①一个Master可以有多个Slave; ②Redis使用异步复制。从2.8开始,Slave会周期性(每秒一次)发起一个Ack确认复制流(replication stream)被处理进度; ③不仅主服务器可以有从服务器,从服务器也可以有自己的从服务器,多个从服务器之间可以构成一个图状结构 ④复制在Master端是非阻塞模式的,这意味着即便是多个Slave执行首次同步时,Master依然可以提供查询服务; ⑤复制在Slave端也是非阻塞模式的:如果你在redis.conf做了设置,Slave在执行首次同步的时候仍可以使用旧数据集提供查询;你也可以配置为当Master与Slave失去联系时,让Slave返回客户端一个错误提示; ⑥当Slave要删掉旧的数据集,并重新加载新版数据时,Slave会阻塞连接请求(一般发生在与Master断开重连后的恢复阶段); ⑦复制功能可以单纯地用于数据冗余(dataredundancy),也可以通过让多个从服务器处理只读命令请求来提升扩展性(scalability):比如说,繁重的 SORT 命令可以交给附属节点去运行。 ⑧可以通过修改Master端的redis.config来避免在Master端执行持久化操作(Save),由Slave端来执行持久化。
三、主从架构
1、准备3个配置文件端口分别为
6379 (Master)
6380 (Slave)
6381 (Slave)2、修改原来的redis.conf文件 ,拷贝出2个redis.conf文件
mv /etc/redis.conf /etc/redis.6379.conf
cp /etc/redis.6379.conf /etc/redis.6380.conf
cp /etc/redis.6379.conf /etc/redis.6381.conf3、修改6380 和 6381 配置文件 vim /etc/redis.6380.conf
通过命令替换 6379 为 6380
:%s/6379/6380/g最底下出现
表示修改成功, wq退出并保存
4、用一样的方式修改6381 的配置文件 5、启动3个redis实例
redis-server /etc/redis.6379.conf
redis-server /etc/redis.6380.conf
redis-server /etc/redis.6381.conf6、通过ps 命令查看redis进程
ps -ef | grep redis7、主从的配置有2种方法: ①在所有从节点的redis.conf(redis.6380.conf和redis.6381.conf)中设置 slaveof
②使用redis-cli客户端连接到Redis服务中,执行slaveof命令 这种方式在重启之后就会失去主从复制关系
8、查看主从信息:INFO replication ①主库查询
②从库显示的信息
③测试主从关系 在主库写入数据 ,然后在从库读取数据
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/127911.html原文链接:https://javaforall.cn
边栏推荐
- C#Socket
- Unity metaverse (II), mixamo & animator hybrid tree and animation fusion
- CNN structural design skills: taking into account speed accuracy and engineering implementation
- IJCAI2022开会了! 微软等《领域泛化Domain Generalization》教程
- Protobuf的简单使用
- 919. Complete binary tree inserter: simple BFS application problem
- 性能调试 -- Chrome Performance
- Pyg tutorial (8): calculate a more efficient sparse matrix form
- 919. 完全二叉树插入器 : 简单 BFS 运用题
- ORIGYN基金会正式启动$OGY Staking,引领新一轮生态利好
猜你喜欢
![[interview: concurrent Article 23: multithreading: Join] re understanding of join](/img/ee/5160a55e776336ba844abe8e9db72a.png)
[interview: concurrent Article 23: multithreading: Join] re understanding of join

【leetcode天梯】链表 · 021 合并两个有序链表

Web3 entrepreneurship has all the elements of explosive growth of innovation

Zero basic learning canoe panel (17) -- panel CAPL function

Creation and destruction of function stack frames

Ijcai2022 meeting! Microsoft and other tutorials on domain generalization

Babbitt | metauniverse daily must read: the popularity of virtual people has decreased, and some "debut is the peak", and the onlookers have dispersed

Idea resolves the prompt of profile properties disappear

Face and key point detection: yolo5face practice

分享|智慧消防应急管理平台解决方案(附PDF)
随机推荐
When facing complex problems, systematic thinking helps you understand the essence of the problem
Fusing and degrading Sentinel
C#Socket
ag 搜索工具参数详解
GPON introduction and Huawei OLT gateway registration and configuration process
函数栈帧的创建和销毁
腾讯云数据库的可信可控之路
Composition of dog food
IJCAI2022开会了! 微软等《领域泛化Domain Generalization》教程
[introduction to C language] zzulioj 1016-1020
浅谈web性能优化(一)
【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
【面试:并发篇25:多线程:volatile】可见性
919. 完全二叉树插入器 : 简单 BFS 运用题
SSH private key realizes login to remote target server
Blood spitting finishing nanny level series tutorial - playing Fiddler bag capturing tutorial (7) - Fiddler status panel -quickexec command line
分享|智慧消防应急管理平台解决方案(附PDF)
The inexplicability of Intel disassembly
Job interviews are always a second kill? After reading the seckill system notes secretly stored by JD T8, I have given my knees
[interview: concurrent Article 23: multithreading: Join] re understanding of join