Use keepalived to achieve master-slave High Availability of redis

Source: Internet
Author: User

Keepalived: LVS + Keepalived Chinese application doc-March 16,201 0.

Keepalived implements VRRP protocol and implements VIP switching at the routing level, which completely avoids problems similar to heartbeat split-brain. You can use nice to implement master-slave, master-slave, and mutual backup solutions, especially for stateless businesses. You need to spend more time on stateful businesses.

Since mysql can use keepalived for master-slave switchover, redis naturally has the same learning experience.

 

The master-slave Implementation of redis is no longer mature than mysql, and it is only available. According to the author's plan, the improvement needs to be improved after 3.0. After testing, the master and slave nodes are not so unreliable. The main problem is that you need to perform full synchronization again after the synchronization connection is disconnected. Frequent synchronization will have a great impact on the performance of the master service. However, in reality, the master and slave machines usually need to be placed under the same switch device of a cabinet, and the transient disconnection of the network is extremely low. In addition, when the number of synchronization operations is large, you need to make the cache area large enough, otherwise the connection may also be disconnected.

The switch logic is as follows: A and B

1. Start A and B in sequence, and A acts as the master and B as the slave

2. Master A fails, and B takes over the business.

3. A is used as A slave SLAVEOF B

4. B goes down and A switches back to the master.

You can use one server as the master node to implement Master/Slave splitting. You can also use multiple instances on one server as the master node and half as the slave node to implement mutual backup and take over services at the same time, after a crash, services are concentrated on one platform.

In keepalived, there are two roles: Master (one) and Backup (multiple). If one is set to Master, but after the Master is down, it is necessary to switch the business again, this is unacceptable for stateful services. Solution: both machines are set to Backup, and the priority Backup is set to nopreemts without preemption.

 

Easy to install:

Dependent packages: openssl-devel (libssl-dev in ubuntu), popt-devel (libpopt-dev in ubuntu), and redheat.

The default path of the configuration file is/etc/keepalived. conf. You can also manually specify the path, but note that you need to manually specify the absolute path. Run with keepalived-D to start three Daemon Processes: one parent process, one check health check, one Vrrp, and one-D to write logs to/var/log/message

The configuration is as follows:

MASTER:

! Configuration File for login {router_id test} vrrp_script chk_redis {script "/etc/keepalived/scripts/ipv127.0.0.1 7001" interval 2} vrrp_script chk_redis2 {script "/etc/keepalived/scripts/login 127.0.0.1 7002 "interval 2} vrrp_instance redis {state BACKUP # Master is also configured as SLAVE interface wlan0} virtual_router_id 51 priority 150 nopreempt # Not preemptible, note that the authorization 1 authentication {auth_type PASS auth_pass lulu} virtual_ipaddress {192.168.1.144} track_script {chk_redis} yy_master "/etc/hosts/scripts/hosts 192.168.1.126 7001" yy_backup "/etc/keepaliv/ scripts/ipv127.0.0.1 192.168.1.126 7001 "Hangzhou/etc/keepalived/scripts/redis_fault.sh policy_stop/etc/keepalived/scripts/Summary} vrrp_instance redis2 {state BACKUP interface wlan0} limit 50 priority 150 advert_int 1 login authentication {auth_type PASS auth_pass lulu} virtual_ipaddress {192.168.1.145} track_script {scripts} yy_master "/etc/hosts/scripts/hosts 192.168.1.126 7002" yy_backup "/etc/keepalived/scripts 127.0.0.1 192.168.1.126 7002 "yy_fault/etc/keepalived/scripts/redis_fault.sh notify_stop/etc/keepalived/scripts/redis_stop.sh}

Backup:

! Configuration File for keepalivedglobal_defs {   router_id test}vrrp_script chk_redis {      script "/etc/keepalived/scripts/redis_check.sh 127.0.0.1 7001"      interval 2}vrrp_script chk_redis2 {      script "/etc/keepalived/scripts/redis_check.sh 127.0.0.1 7002"      interval 2}vrrp_instance redis {    state BACKUP       interface wlan0 }      virtual_router_id 51      priority  100           advert_int 1            authentication {            auth_type PASS           auth_pass test    }    virtual_ipaddress {     192.168.1.144    }    track_script {          chk_redis     }     notify_master "/etc/keepalived/scripts/redis_master_slave.sh 127.0.0.1 192.168.1.126 7001"    notify_backup "/etc/keepalived/scripts/redis_backup_slave.sh 127.0.0.1 192.168.1.126 7001"    notify_fault /etc/keepalived/scripts/redis_fault.sh     notify_stop /etc/keepalived/scripts/redis_stop.sh }vrrp_instance redis2 {    state BACKUP       interface wlan0 }      virtual_router_id 50      advert_int 1          priority 100    authentication {           auth_type PASS          auth_pass test    }    virtual_ipaddress {       192.168.1.145    }    track_script {          chk_redis2    }    notify_master "/etc/keepalived/scripts/redis_master_slave.sh 127.0.0.1 192.168.1.126 7002"    notify_backup "/etc/keepalived/scripts/redis_backup_slave.sh 127.0.0.1 192.168.1.126 7002"    notify_fault /etc/keepalived/scripts/redis_fault.sh     notify_stop /etc/keepalived/scripts/redis_stop.sh }

For other scripts, see Attachment: http://files.cnblogs.com/lulu/scripts.rar

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.