当前位置:网站首页>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 !
边栏推荐
- 高手是怎样炼成的?
- Common modules in ansible
- Three graduates, three years of experience in embedded software
- Use playbook in ansible
- nn.Moudle模块-创建神经网络结构需要注意的细节
- TZC 1283: simple sort Bubble Sort
- 攻防世界--easy_web
- Unity Profiler
- Yuancosmos provides a digital social platform for fashion design display
- Yolov3 preparatory work
猜你喜欢

10. Regular expression matching

OD-Paper【1】:Rich feature hierarchies for accurate object detection and semantic segmentation

High frequency electronic circuit review examination questions and answers

一招教你轻松看懂波特图

攻防世界-FlatScience

Common modules in ansible

Usage and common problems of SIP softphone registered with SIP account

Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output

Efficient, reliable and safe open source solution for serial communication

How students apply for free idea
随机推荐
Use latex to typeset multiple-choice test paper
Go exceed API source code reading (VI) -- deletesheet (sheet string)
轻量级单片机命令行交互项目,全部开源
IVR在voip电话系统的应用与价值
高分子物理知识点
MBA-day29 算术-绝对值初步认识
Usage and common problems of SIP softphone registered with SIP account
Hack The Box - Introduction to Networking Module详细讲解中文教程
高手是怎样炼成的?
It's enough for newcomers to learn how to do functional tests
C language explanation series -- understanding of functions (3) formal parameters, arguments, nested calls and chain access
Nn.moudle module - details of creating neural network structure
No EGL Display 报错解决
MBA-day28 数的概念-练习题
You'd better not take this kind of project!
Hack The Box -SQL Injection Fundamentals Module详细讲解中文教程
How to conduct test case review
MongoDB 常用命令
Thread三种实现方式 和 Handler的用法
Chinese character style transfer --- learn the conversion and generation of one to many programmed Chinese characters through generation confrontation network