Redis Master/Slave automatic failover

Source: Internet
Author: User
Tags redis version
Redis master-slave architecture persistence has a problem, that is, the conclusion of the previous test, persistence needs to be configured on the master instance to ensure data is not lost across instances, in this way, it is inevitable that the master instance will persist data to the hard disk.

Redis master-slave architecture persistence has a problem, that is, the conclusion of the previous test, persistence needs to be configured on the master instance to ensure data is not lost across instances, in this way, it is inevitable that the master instance will persist data to the hard disk.

Redis master-slave architecture persistence has a problem, that is, the conclusion of the previous test, persistence needs to be configured on the master instance to ensure data is not lost across instances, in this way, the persistence of data on the master instance to the hard disk will inevitably lead to disk I/O waits. The Hong Kong virtual host has passed actual tests, this process of persistent hard disk writing has an unbearable impact on applications. Therefore, in most scenarios, you may consider configuring persistence on the slave instance. When the master instance goes down, you can manually or automatically promote the master instance from the instance to continue providing services! After the master instance is restored, the data is synchronized from the original Instance. After the synchronization is completed, the data is restored to the original master-slave state! To meet this requirement, we need the cooperation of keepalive. On the one hand, keepalive provides VIP, which can avoid modifying the application connection, at the same time, the configuration file listening part of the apsaradb for redis instance also needs to be changed to a full-network listener. On the other hand, the keepalive timed scheduling script is used to monitor the status of the master-slave instance and the Hong Kong server. Switch based on the actual situation! This article will focus on using keepalive to implement automatic master-slave failover for redis!

Environment Introduction
Operating system versions: rhel5.4 64bit
Redis version: 2.6.4
All redis instance ports are: 6379
Redis instance password is: 123
VIP: 192.168.1.120
The master instance is server11 (192.168.1.112)
The slave instance is server12 (192.168.1.113, enabling snapshot persistence)

1. Install the keepalive software. After server11 is installed, it can be directly scp to server12.

Ii. Configure the master node server11 configuration file

3. Configure the slave node server12 configuration file

4. Prepare related scripts. These scripts must exist on both the master and slave instances. Note that the script must have executable permissions.

5. The master and slave instances start the keepalive process respectively to test whether the VIP is normal (here we need to modify the listening address of the redis configuration file to 0.0.0.0)

6. Write test data to the master instance. In principle, this script will write 25 test data records. However, some write requests may fail because the default concurrency of redis is not optimized, 231839 pieces of test data are written, which accounts for about 25 MB of memory. During the write process, you can observe the persistent file changes and website space of the master-slave instance, the persistent files of the master instance are maintained at 30 k, and the files are constantly extended from the instance!

7. Simulate the fault of the master instance, observe the log output, verify whether the instance can successfully take over the VIP, and change the instance to the read/write mode.

8. Continue to write test data using the script. Repeat the script to update the record. 249925 test data records are successfully written this time.

9. The master instance role is automatically restored using shell scripts.

10. Verify data integrity and Master/Slave role recovery

Reference:

This article is from the "Bo Yue" blog and will not be reproduced!

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.