Redis Master-slave replication configuration

Source: Internet
Author: User

First, Redis's replication:

The first thing to note here is that it's too easy to configure the Master-slave mode in Redis. I believe you can do it easily after reading this blog. Here we should first list some theoretical knowledge, and then give the actual operation of the case.
The following list clearly explains the features and benefits of Redis replication.
1). The same master can synchronize multiple slaves.
2). Slave can also accept other slaves connection and synchronization requests, which can effectively load the sync pressure of master. So we can treat Redis's replication architecture as a graph structure.
3). Master Server provides services for slaves in a non-blocking manner. So during Master-slave synchronization, the client can still submit queries or modify requests.
4). Slave Server also completes data synchronization in a non-blocking manner. During synchronization, if a client submits a query request, REDIS returns the data before synchronization.
5). In order to load the read operation pressure of master, the slave server can provide a read-only service to the client, and the write service must still be completed by master. Even so, the scalability of the system has been greatly improved.
6). Master can leave the data save operation to slaves to complete, thus avoiding the need to have a separate process in master to complete the operation.

Second, the working principle of replication:

After the slave is started and connected to master, it will actively send a sync command. Master will then start the background disk process and collect all the received commands to modify the dataset, and master will transfer the entire database file to slave to complete a full synchronization once the background process has finished executing. The slave server then disks and loads the database file data into memory after it receives it. After that, Master continues to pass all the modified commands that have been collected, and the new modification commands to Slaves,slave will execute these data modification commands at this time to achieve final data synchronization.
If the link between master and slave appears to be disconnected, slave can automatically reconnect master, but once the connection is successful, a full synchronization will be performed automatically.

third, How to configure replication:

See the following steps:
1). Start two Redis servers at the same time, consider starting two Redis servers on the same machine, listening to different ports, such as 6379 and 9001, respectively.

2) We assume that the port is 9001 from, the port is the main of 6379. We execute the following command on the slave server with Port 9001, as shown in:

  

Here we can test: Execute the Set mtest ' qwe123 ' on the 6379 server and then get the large cache value from the server.

The above method only guarantees that after executing the slaveof command, redis_6380 becomes the slave of redis_6379, and once the service (redis_6380) restarts, the replication relationship between them terminates.
If you want to guarantee the replication relationship between the two servers over the long term, you can make the following changes in the redis_6380 configuration file:

  Open the cache configuration file from (9001 port) and make the following changes:

Will
# slaveof <masterip> <masterport>
Switch
slaveof 127.0.0.1 6379

 Save exit.
This ensures that the REDIS_9001 Service program will actively establish a replication connection to the redis_6379 after each boot.

This article references: http://www.cnblogs.com/stephen-liu74/archive/2012/02/23/2364717.html

 

Redis Master-slave replication configuration

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.