Redis multi-host function Replication

Source: Internet
Author: User
Tags failover redis server

Purpose of replication:Create a copy server with the same database; expand the system's ability to process read requests;

 

Definition of Replication

Redis replication allows you to create any number of copies of the server based on a redis server. The copied server is the master server ), the server created by copying is called the slave server );

Master/Slave servers have the same database data: As long as the network connection between the master and slave servers is normal, the master server will always synchronize the data updates on itself to the slave server, so as to keep the data of the master and slave servers the same;

A master server can have 1 to n slave servers;

 

Use the slave server to process read command requests,Use replication to expand the system's ability to process read requests 

Redis allows the server to execute command requests sent from clients, such as get and lrange;

Because the master and slave servers have the same database dataWhen the slave server executes the READ command sent by the client, the obtained results are the same as those obtained when the master server executes the same read command.;

Therefore, you can forward some (or even all) read command requests processed by the master server to the slave server, reducing the load of the master server in processing READ command requests, and the ability of the entire system to process read command requests;

By adding slave servers, the system can linearly expand the ability of the entire system to process read command requests.

 

Create and use slave servers

Create a slave server. redis provides two methods to create a slave server for a master server.

1,Use the slaveof master-Ip Master-PORT command

For example, sending the slave hadoop000 6379 to a server can change the server that receives the command to the slave server of hadoop000: 6379;

After setting a server as a slave server, you can send the slaveof no one command to it to change it back to a master server (the existing data in the database will be retained );

2,Configuration in the configuration file: Slaveof master-Ip Master-port option to make the server a slave server of the specified server;

For example, if the client sends the command slaveof 127.0.0.1 6380 to the server 127.0.0.1: 6379, 127.0.0.1: 6380 will become the slave server of 127.0.0.1: 6379;

 

Master/Slave server operation example:

127.0.0.1:6379> SET msg "hello world"OK127.0.0.1:6380> GET msg"hello world"127.0.0.1:6379> INCR counter(integer) 1127.0.0.1:6379> INCR counter(integer) 2127.0.0.1:6380> GET counter"2"127.0.0.1:6379> RPUSH lst 1 3 5 7 9(integer) 5127.0.0.1:6380> LRANGE lst 0 -11)"1"2)"3"3)"5"4)"7"5)"9"

 

 

Server offline Processing

What should I do if the master server or slave server is offline?

Server disconnection during replication

In a system composed of a master server and a slave server, the master server or slave server may be deprecated, but the removal of different servers has different effects:

Remove from server: Entire systemThe performance for processing read requests will decrease.,The entire system can continue to process write and read requests., AndWill not cause system downtime;

Example of deprecation from the server:

The removal from server B causes access to client C to fail, but this problem can be solved as long as client c changes to access other online servers.

Active Server offline: Because in the entire systemOnly the master server can process write requestsAfter the master server is deprecatedThe entire system can only process read requests, but cannot process write requests.,System downtime;

When the master server is deprecated, the connection between the master and slave servers is interrupted, and the entire system cannot execute write commands. At this time, the slave server can continue to process read requests, but the data on the slave server cannot be updated because the master server is offline.

 

Let the system go online again

In order to enable the system to go online again normally (so that the system server can process both read requests and write requests ), the user needs to send the slaveof no one command to a slave server in the system, convert it into a new master server, and send the slaveof command to other slave servers, let them copy new slave servers.

Now that the system has a new master server and an slave server, the client can continue to use this system to process read and write requests.

Because one server is offlineThe performance of the re-launch system may not be comparable to that of the original system, but this recovery operation can avoid the overall system downtime..

Although the method described above can bring the system back online, it is too troublesome to manually execute these operations. For this reason, redis provides the Sentinel Program, you can use sentinel to automatically detect the status of the master and slave servers. When the master server goes offline, it performs a failover operation (Failover) to bring the system online again.

 

Redis multi-host function Replication

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.