Redis implements master-slave replication (Master & slave)

Source: Internet
Author: User

Some time ago, the company's projects were too busy to write a blog. Today, I want to write an article. I have explained the basic operations of apsaradb for redis in the previous section. Now I will continue to explain the advanced sections of apsaradb for redis, including master-slave replication and read/write splitting.

1. What is Master & slave?

This is what we call master-slave replication. After the host data is updated, it is automatically synchronized to the slave according to the configuration and policy.

Master/slaver mechanism, Master write-oriented, slave read-oriented.

2. What can it do?

1. read/write splitting;

2. Disaster Recovery.

3. How to play?

1. The configuration slave (database) does not deserve the master (database );

2. Slave Database Configuration: slaveof [master database IP address] [master database port];

Supplement: each time slave and master are disconnected, they need to be reconnected unless you configure them in the redis. conf file;

Type info replication to view redis Master/Slave information.

3. modify configuration file details

-Copy multiple redis. conf files

-Specified port


-Enable daemonize Yes


-Pid file name


-Log File Name


-Dump. RDB name


4. Three Common tricks

-One master, two slaves

One master, two slave, slave can only be read and cannot be written; When slave and master are disconnected, you need to re-slave of connection to establish it

Master-slave relationship. After the master fails, the master relationship still exists and can be restored after the master is restarted.

-Keep fire

The previous slave can be the master of the next slave, and slave can also receive connection and synchronization requests from other slaves.

The next slave master in the chain can effectively reduce the write pressure on the master. If the slave changes midway through, the previous data will be cleared, and then

Create the latest one.

-Customer-oriented

After the master node fails, slave can type the command slaveof no one to stop the current redis data synchronization with other master redis and convert it

Master redis.

Iv. Replication principles

1. After the Server Load balancer instance is successfully started and connected to the master node, A Sync command is sent;

2. The master node receives the command to start the disk-saving process and collects all received commands for modifying the dataset. After the background process is executed, the master node

Transfers the entire data file to slave to complete a full synchronization;

3. Full replication: The slave service stores the database file data and loads the data to the memory;

4. incremental replication: The Master continues to pass all the new collected modification commands to slave in sequence to complete synchronization;

5. But as long as the master is reconnected, a full synchronization (full replication) will be automatically executed.

5. Sentinel)

The automatic version of the anti-customer master database can monitor whether the master database is faulty in the background. If the master database fails, the slave database is automatically converted to the master database based on the number of votes. A group of sentinel capabilities

Monitors multiple masters at the same time.

Procedure:

1. Create the Sentinel. conf file in the same directory of the redis. conf file of the master. The name must be unique;

2. Configure the Sentinel. conf file with the following content:

Sentinel monitor the name of the monitored database (from your own name) IP Port 1

Note: The last number 1 above indicates that after the host fails, slave will vote to see who will replace the host, and then become the host after the number of votes.

3. Enable the guard mode:

Command: redis-Sentinel/myredis/sentinel. conf

Note: The above Sentinel. conf paths are configured according to their actual conditions.

Vi. disadvantages of Replication

Latency. Because all write operations are performed on the master and then synchronously updated to the slave, the synchronization from the master to the slave has a certain

When the system is very busy, the delay problem will be more serious, and the increase in the number of slave machines will make this problem more serious.

 

 

 

Redis implements master-slave replication (Master & slave)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.