Redis master-slave replication

Redis master-slave replication process, the replication request is initiated by the slave node, and the slave node is read-only by default

1. The slave node initiates a replication request and saves the master node information

2. The master-slave establishes a socket connection

3. Send a ping command from the node

4. Master node permission verification (off by default)

5. Sync data

6. Continuous replication

 

Among them, the synchronization data is divided into full replication and partial replication

 

Full replication, the first replication of the slave node must be full replication, the full replication process is initiated by the slave node, the master node maintains the RDB file, the master node sends the RDB file, the master node caches the incremental commands during the period and sends them after the RDB transmission is completed The incremental command is given to the slave node. If the slave node has enabled AOF, the first AOF will be performed immediately after synchronization.

It can be seen that full replication is a very time-consuming and network bandwidth-consuming operation. It is usually necessary to deploy slave nodes to the same computer room or place, and in addition to the first synchronization, full replication should be avoided, and the master node hangs up and restarts Modifying the serviceid will also trigger full replication of the slave node, which needs to be solved through a better cluster solution.

 

For partial replication, both master and slave save the offset. It can be considered that the offset is the pointer of the buffer. The master node transmits incremental data according to the offset. The efficiency and speed are much better than full replication. The default buffer data size is 1M. If the offset is not in the buffer, a full copy will be triggered, and reasonable parameters need to be adjusted to avoid it.

 

The master and slave nodes will maintain the connection through heartbeat.

 

To avoid replication storms, that is, multiple slave machines initiate replication to the same master machine, one method is to use a tree structure (there is a slave below the slave), and the other is that the master node is scattered on multiple machines.

 

The cluster solution can better solve the master-slave high availability problem.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326048900&siteId=291194637