Redis notes (2) master-slave Replication

Source: Internet
Author: User

A single redis instance may encounter single point of failure. To solve the high availability of redis, master-slave replication should be the second step of learning. The purpose of this article is to bring one master with one slave, and the slave with another slave. The advantage is that when the master fails, the slaver1 is directly changed to the master, other configurations do not need to be modified, and the service can be used normally.


You do not need to modify the redis configuration file as the master. Here, you only need to modify the slave1 and slave12 configuration files. For slave1, you only need. in the conf file, find # slaveof <masterip> <masterport> and change it to slaveof192.168.1.18. Then save it, and modify slave12 to slaveof 192.168.10.10 6379, start slave1 and slave12.

Run redis-CLI on 192.168.1.18 and run the info command.

Role: Master

Connected_slaves: 1

Slave0: 192.168.10.10, 6379, online

In 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 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

Now we want to achieve the goal, but we find that data cannot be inserted on two slave. When the master node fails, we need to first execute the slaveof no one command on slave1, when info replication is executed again, it has been converted to master, and slave12 is not affected.

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, master-slave replication has been completed, and careful netizens may have discovered that they only need to configure the Master Address and port to exist as a server Load balancer, so that the data is stolen by others !!!

Yes. This problem will be solved in the next section.

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.