Redis Master-slave replication

Source: Internet
Author: User

Single Redis encounters a single point of failure, and in order to solve the high availability of Redis, master-slave replication should be the second step in learning. The purpose of this article is to achieve a master with a slave, and slave with a slave, the advantage is that when the master fault, the slaver1 changed directly to master, the other configuration does not need to be modified, the service can be used normally.


The Redis profile as Master does not need to be modified, only the slave1 and slave12 configuration files are modified here, for SLAVE1 only need to find in redis.conf # slaveof <masterip> < Masterport> and modified to slaveof192.168.1.18 6379 and then save, and Slave12 is modified to slaveof 192.168.10.10 6379, so you can, Start slave1 and Slave12 and try it.

Execute REDIS-CLI on 192.168.1.18, use the info command to see in # Replication

Role:master

Connected_slaves:1

Slave0:192.168.10.10,6379,online

In the REDIS-CLI on 192.168.10.10, you can see:

# Replication

Role:slave

master_host:192.168.1.18

master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:7

master_sync_in_progress:0

slave_priority:100

Slave_read_only:1

Connected_slaves:1

Slave0:192.168.12.12,6379,online

On the 192.168.12.12, you can see:

# Replication

Role:slave

master_host:192.168.10.10

master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:3

master_sync_in_progress:0

slave_priority:100

Slave_read_only:1

connected_slaves:0

At this point we want to achieve the goal has been achieved, but found that two slave can not be inserted data, when the master failure, need to first execute slaveof no one command on slave1, once again to execute the info replication, it has been converted to master, Slave12 is not affected at this time.

Redis 192.168.10.10:6379> slaveof No one

Ok

Redis 192.168.10.10:6379> inforeplication

# Replication

Role:master

Connected_slaves:1

Slave0:127.0.0.1,6382,online

Redis 192.168.10.10:6379>

At this point, has completed the master-slave replication, the careful netizen may have found that simply configure the master's address and port, it can be as slave exist, so that the data is stolen by others!!!

Now yes, the next section will address this issue.

High-availability design and implementation under Redis read-write separation (top)

Category: NoSQL Redis 2013-12-14 09:07 5030 People read reviews (7) favorites report

Through Redis notes (i) pure small white version, Redis notes (ii) master-slave replication and Redis notes (iii) master-slave synchronization after adding a password and modifying the default port three articles, we have been able to create a master-slave copy of the Redis, for example:


On this basis, we do a read-write separation, write the main library, read from the library, as follows:


This does realize the separation of read and write, but, whether it is starting or running process, as long as there is a redis work is not normal, even if another work properly, the whole Redis external is not available-the master is not available, not writable, never time unreadable, so there is a single point of failure problem, in order to solve the problem , the following improvements have been made:


After the transformation, the master Redis and from Redis only before the start of a clear master-slave relationship, when the startup if the main or from a non-usable, then the read-write common point to the available Redis, in order to achieve high availability at runtime, the loading master-slave Redis abstraction into a method, When accessing a Redis exception, the method of loading Redis is called again, so that Redis can serve as long as there is a redis available during the run.


Redis Master-slave 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.