Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the characteristics of the master-slave replication architecture in Redis6

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "what are the characteristics of the master-slave replication architecture in Redis6". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Introduction of master-slave replication

Master-slave replication refers to copying the data from one Redis server to another Redis server. The former master node (master), the latter becomes the slave node (slave); data replication is one-way, only from the master node to the slave node. By default, each Redis server is a master node, and a master node can have multiple slave nodes (or no slave nodes), but a slave node can have only one master node.

The advantage of using master-slave replication: read-write separation, which can expand the reading ability of the master node and share the pressure on the master node. Disaster recovery, once the master node is down, the backup of the slave node as the master node can be topped up at any time.

Architecture introduction

The data of the master node is copied from the slave node, and after copying, we can do a read-write separation. If it is a single node, the application's requests are concentrated on the master node, but with the slave node, it can bear some of the read pressure. The master node can do read and write operations, while the slave node can only do read operations. This will share the pressure on the master node.

Redis master-slave replication, one master and two slaves architecture environment preparation

Having said so many concepts, let's start deploying the master-slave replication architecture of Redis, this time we are deploying an one-master-two-slave architecture.

# create file mkdir-p / data/redis/master/datamkdir-p / data/redis/slave1/datamkdir-p / data/redis/slave2/data# enable read-only mode (default) replica-read-only yes# slave node access master node password, and requirepass sample masterauth 123456 # which master node enters replication replicaof 8.129.113.233 6379

First create a master node, touch a redis.conf file in the data/redis/master/data directory, and edit the redis.conf file

Bind 0.0.0.0port 6379daemonize yesrequirepass "123456" logfile "usr/local/redis/log/redis1.log" dbfilename "xdclass1.rdb" dir "/ usr/local/redis/data" appendonly yesappendfilename "appendonly1.aof" masterauth "123456"

Then create slave node 1 and build redis.conf under the data/redis/slave1/data directory

Bind 0.0.0.0port 6380daemonize yesrequirepass "123456" logfile "/ usr/local/redis/log/redis2.log" dbfilename "xdclass2.rdb" dir "/ usr/local/redis/data" appendonly yesappendfilename "appendonly2.aof" replicaof 8.129.113.233 6379masterauth "123456"

Create slave node 2 and create redis.conf under the data/redis/slave2/data directory

Bind 0.0.0.0port 6381daemonize yesrequirepass "123456" logfile "/ usr/local/redis/log/redis3.log" dbfilename "xdclass3.rdb" dir "/ usr/local/redis/data" appendonly yesappendfilename "appendonly3.aof" replicaof 8.129.113.233 6379masterauth "123456"

Note: the firewall should be turned off and the Ali CVM should remember to open the network security group.

Start the configured node after it has been created

Startup mode:

# start master. / redis-server/data/redis/master/data/redis.conf# launch slave 1./redis-server/data/redis/slave1/data/redis.conf# launch slave 2./redis-server/data/redis/slave2/data/redis.conf

Use info replication to view the status of the current node

Master-slave replication and read-write verification

1. Create a keyset name jack2 on the primary node. Test whether you can get the data get name3 of the master node in two slave nodes. Set key fails on slave nodes because only read operations are supported on slave nodes

Redis6 Master-Slave Architecture-Analysis of the principle of replication read-write Separation

There are two types of master-slave replication: one is full synchronization at the beginning of the connection, and the other is incremental synchronization after the end of full synchronization.

Full replication: the master server will start a background process to generate a rdb file of Redis data, and the master server will cache all write commands received from the client. When the background saves the process, it will transfer the rdb file to the slave server, then the slave server will have the master server's data. After that, the master server will send the cached commands to the slave server through the redis transport protocol, and then the slave server will use these commands locally to achieve data consistency.

Incremental replication: the master node will have continuous commands to write in. The process that the master server sends write operations synchronized to the server when the slave is initialized is called incremental replication. Incremental replication is that each time the server executes a write command, it sends the same write command to the slave server, and receives and executes the received write command from the server.

What are the characteristics of master-slave replication:

Master-slave replication is non-blocking for master / slave servers, and all external requests can be processed normally during data synchronization. A master node can contain multiple slave nodes, and each slave node can accept connections from other slave nodes. The slave node does not let the key expire, but sends a delete command to the slave node to delete after the key of the master node expires.

Accelerated replication: when the node completes resynchronization, you need to create a RDB file on disk, and then load this file to send data from the server, but what if the disk rate is low? This results in inconsistent data between the master node and the slave node. In the new version of Redis, diskless copy is supported, RBD files are sent directly to the slave server through the network, and disks are no longer used as middleware.

If the master-slave connection is disconnected, the replication can continue from the interrupted place after the reconnection without resynchronizing. After version 2.8, the new resynchronization feature uses the PSYNC command, while the old one uses the SYNC command

This is the end of the content of "what are the characteristics of the master-slave replication architecture in Redis6". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report