当前位置:网站首页>Redis master-slave replication
Redis master-slave replication
2022-07-26 05:37:00 【Life goes on and battles go on】
Concept
Master slave copy , It means to put one Redis Server data , Copy to other Redis The server . The former is called the main node (master/leader), The latter is called the slave node (slave/follower); Data replication is one-way , Only master node to slave node .Master Write first ,Slave Mainly reading .
By default , Each station Redis Servers are all primary nodes ; And a master node can have multiple slave nodes ( Or no slave ), But a slave node can only have one master node .
The main functions of master-slave replication include
- data redundancy : Master-slave replication realizes hot backup of data , It's a way of data redundancy beyond persistence .
- Fault recovery : When there is a problem with the master node , Can be served by a slave node , Fast fault recovery ; It's actually a redundancy of services .
- Load balancing : On the basis of master-slave replication , Configure read-write separation , Write service can be provided by the master node , Read service provided by slave node ( The write Redis Connect master node when data is applied , read Redis Apply connection from node when data ), Share server load ; Especially in the situation of less writing and more reading , Sharing read load through multiple slave nodes , Can be greatly improved Redis Concurrency of servers
- High availability cornerstone : In addition to the above functions , Master slave replication is also the foundation for sentinels and clusters to implement , So master-slave replication is Redis High availability Foundation
Generally speaking , To put Redis Used in engineering projects , Use only one Redis Absolutely not , Here's why :
- Structurally . Single Redis The server will have a single point of failure , And a server needs to handle all the request loads , pressure ;
- In terms of capacity , Single Redis Server memory capacity is limited , Even if it's a Redis The memory capacity of the server is 265G, Nor can all memory be used Redis Storage memory , Generally speaking , A single Redis The maximum suitable memory should not exceed 20G
Products on e-commerce websites , It's usually a upload , Countless times , To be professional is “ Read more and write less ””.
For this scenario , We can use the following architecture :

Environment configuration
Basic configuration
Equipped with slave warehouse, not equipped with master warehouse , Configuration from library :
127.0.0.1:6379> info replication # View the current library information
# Replication
role:master # role master
connected_slaves:0 # No slave
master_failover_state:no-failover
master_replid:5376842b5adf40815bebfb0c9a541f015252b7d8
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
slaveof Main library ip Main library port # Configure master and slave
info replication # Check the information
Every time with master After disconnection , All need to be reconnected , Unless you configure it into redis.conf file
Modify the configuration file
preparation : We configure master-slave replication , At least three... Are needed , One master and two subordinates , Configure three clients
1、 Copy multiple redis.conf file

2、 Designated port 6379, By analogy
3、 Turn on daemonize yes
4、pid File name pidfile /www/server/reids/redis_6379.pid, By analogy
5、Log File name logfile “/www/server/redis/redis_6379.log”, By analogy
6、Dump.rdb File name dbfilename dump6379.rdb, By analogy

After the above configuration is completed ,3 A service passes 33 A different configuration file opens , Our preparation Environment Bureau ok 了

One master and two subordinates
One master and two servants
1、 Environment initialization


By default, all three are Master Master node
2、 Configure as a Master Two Slave

3、 Set the value on the host , You can get it from the slave ! The slave cannot write values !

Layers of links
the previous Slave It could be the next Slave and Master,Slave Can also receive other slaves Connection and synchronization requests for , Then the slave As the next in the chain master', Can effectively reduce master The pressure of writing !

Plot to usurp the throne

The host comes back , It's just a bare pole commander , The slave runs to the new host for normal use !
边栏推荐
- 我又发现了超赞的软硬件项目,全部开源
- You'd better not take this kind of project!
- Hack The Box -SQL Injection Fundamentals Module详细讲解中文教程
- no networks found in /etc/cni/net.d
- Qt编写物联网管理平台47-通用数据库设置
- 517. 超级洗衣机
- Another open source artifact, worth collecting and learning!
- 怎么办理聚合收款码
- Chapter 1 - Construction of development environment
- ES Cluster in Red status: what about write & delete operations?
猜你喜欢

Redis official visualization tool, with high appearance value and powerful functions!

OD-Paper【2】:Fast R-CNN

柠檬班自动化学习毕竟

MySQL optimization

Code audit CMS

SIP账号注册的SIP软电话的使用和常见问题

MBA-day28 数的概念-练习题

Hack The Box - Introduction to Networking Module详细讲解中文教程

520 for what? DIY is a high-value RGB clock that girls want to watch

Redis持久化-RDB
随机推荐
Redis发布订阅
SSTI-payload和各种绕过方法
芯片的翻新和造假,人被坑麻了
SSH Remote Management
How are masters refined?
如何从内存解析的角度理解“数组名实质是一个地址”?
LNMP架构
C语言详解系列——函数的认识(3)形参,实参,嵌套调用和链式访问
高分子物理试题库
Common modules in ansible
Hack the box - Web requests module detailed Chinese tutorial
这种项目,最好别接!
Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
Redis主从复制
开发项目事半功倍,一款开源的stm32驱动库大集合
[cloud native] introduction and use of feign of microservices
QT writing IOT management platform 47 general database settings
Webassembly 01 basic information
STL常用模板库
高效,可靠,安全的串口通讯开源方案