当前位置:网站首页>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
边栏推荐
- 五、品达通用权限系统__pd-tools-xxs(防跨站脚本攻击)
- [MAIXPY]kpu: load error:2005, ERR_READ_FILE: read file failed问题解决
- 立创EDA——我为什么要学EDA
- Share | intelligent fire emergency management platform solution (PDF attached)
- C#Socket
- [ManageEngine] value brought by Siem to enterprises
- Array of arm disassembly
- [database] index
- 狗粮的成分
- mysql8.0 mha实现高可用《mha》
猜你喜欢

腾讯云数据库的可信可控之路

Lichuang EDA -- creation of devices 01 resistance (II)

Ijcai2022 meeting! Microsoft and other tutorials on domain generalization

How to solve the problem of high concurrency and large traffic with PHP

Detailed explanation of Ag search tool parameters

CNN structural design skills: taking into account speed accuracy and engineering implementation

Pyg tutorial (8): calculate a more efficient sparse matrix form

Creation and destruction of function stack frames

Idea resolves the prompt of profile properties disappear
![[redis underlying parsing] linked list type](/img/e8/c192629dce1a958155a562d216d532.png)
[redis underlying parsing] linked list type
随机推荐
工作面试总遇秒杀? 看了京东 T8 大咖私藏的秒杀系统笔记, 已献出膝盖
On Web Performance Optimization (1)
Experience sharing of system architecture designers preparing for the exam: from point to surface
[leetcode ladder] linked list · 876 find the middle node of the linked list
The inexplicability of Intel disassembly
H5 realize the animation effect of a scratch card
[database] conceptual design, logical design, relational database design theory
[MAIXPY]kpu: load error:2005, ERR_ READ_ File: read file failed problem solving
Mysql8.0 MHA to achieve high availability "MHA"
Excuse me, how to deal with repeated consumption of MySQL data
[interview: concurrent 25: multithreading: volatile] visibility
JMeter distributed pressure measurement
Create EDA - why should I learn EDA
Idea resolves the prompt of profile properties disappear
Reading the pointpillar code of openpcdet -- Part 3: Calculation of loss function
es6--解构赋值
Simple use of protobuf
【面试:并发篇23:多线程:join】join再理解
Autojs learning - file depth search
Database SQL statement exercise "suggestions collection"