Use keepalived to create Redis dual-machine Hot Spares

Source: Internet
Author: User
Tags redis cluster

Redis is a very useful and excellent nosql open source product, in a highly concurrent server environment, Can be used as a cache and as a queue. The drawback is that until now, Redis has not launched its own cluster solution, for a complete production environment, load balancing, high availability, master-slave backup is an essential option, Redis provides a stable master-slave backup function, provides a number of persistence strategies, In the master-slave backup also provides the function of incremental backup, now through Sentinel to provide master-slave hot standby function, unfortunately the function is not perfect, can not reach the requirements of production environment.

Now that we have selected Keepalived as a high-availability redis support, keepalived can not only be more complete to support the high availability of Redis, but also as a companion for LVS load Balancing, and the LVS has a good combination of natural, to build a Redis cluster has a good scalability.

Redis and keepalived installation is very simple, a lot of articles on the Internet can be consulted, here will not repeat, here in accordance with the Redis dual-master hot standby scene, talk about the need to pay attention to the points, many articles on the internet did not speak clearly.

The relationship between 1,lvs and keepalived, LVS is load balancing, and keepalived is highly available (hot spare) support, keeplaived can be used alone.

2,keepalived through the VIP virtual IP binding transformation to create hot-standby support, in the process of converting master-slave identity, but also support the call of the script, according to different scripts, keepalived can be used for different scene requirements, is a powerful

The use of keepalived in the 3,centos environment requires installation of IPVSADM support.

4, if the load balancer is using a NAT policy, then the Linux arp_ignore (ARP multicast ignore) option can be set.

5,/etc/sysconfig/keeaplived is keepalived startup script, this can not be modified, if keepalived's boot configuration is not/etc/keepalived/ Keepalived.conf you need to specify the location of the configuration file here

/ETC/KEEPALIVED/KEEPALIVED.CONF is the default configuration file location for kaapalived

/var/log/messages recorded the start of keepalived, VIP conversion, such as log information, as for the role of the conversion process of the script execution log, by each script to specify

The following post-master keepalived.conf settings, under the CENTOS7 test pass

Host keepalived.conf

! Configuration File forKeepalivedglobal_defs {notification_email {[email protected] [email protected] [email protected]} Notification_email_from [email protected] smtp_server128.0.0.1Smtp_connect_timeout -router_id lvs_master}vrrp_script Chk_redis {script"/usr/local/redis/sh/redis_check.sh 127.0.0.1 6379"interval2Timeout2Fall3}vrrp_instance vi_1 {State MASTER interface eno16777736 virtual_router_id - Priority -Advert_int3Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {192.168.72.115       # 192.168.200.17       # 192.168.200.18} track_script {Chk_redis} notify_master"/usr/local/redis/sh/redis_master_master.sh 127.0.0.1 192.168.72.128 6379"Notify_backup"/usr/local/redis/sh/redis_master_slave.sh 127.0.0.1 192.168.72.128 6379"Notify_fault"/usr/local/redis/sh/redis_fault.sh"}virtual_server192.168.72.115 6379{Delay_loop6Lb_algo RR lb_kind NAT nat_mask255.255.255.0Persistence_timeout -protocol TCP Sorry_server127.0.0.1  theReal_server192.168.72.11 6379{weight1Tcp_check {connect_timeout3Nb_get_retry3Delay_before_retry3Connect_port6379}} real_server192.168.72.128 6379{weight1Tcp_check {connect_timeout3Nb_get_retry3Delay_before_retry3Connect_port6379        }    }}

KEEPALIVED.CONF configuration from the machine

! Configuration File forKeepalivedglobal_defs {notification_email {[email protected] [email protected] [email protected]} Notification_email_from [email protected] smtp_server128.0.0.1Smtp_connect_timeout -router_id lvs_backup}vrrp_script Chk_redis {script"/usr/local/redis/sh/redis_check.sh 127.0.0.1 6379"interval2Timeout2Fall3}vrrp_instance vi_1 {State BACKUP interface eno16777736 virtual_router_id - Priority AboutAdvert_int3nopreempt Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {192.168.72.115       # 192.168.200.17       # 192.168.200.18} track_script {Chk_redis} notify_master"/usr/local/redis/sh/redis_backup_master.sh 127.0.0.1 192.168.72.11 6379"Notify_backup"/usr/local/redis/sh/redis_backup_slave.sh 127.0.0.1 192.168.72.11 6379"Notify_fault"/usr/local/redis/sh/redis_fault.sh"}virtual_server192.168.72.115 6379{Delay_loop6Lb_algo RR lb_kind NAT nat_mask255.255.255.0Persistence_timeout -protocol TCP Sorry_server127.0.0.1  theReal_server192.168.72.11 6379{weight1Tcp_check {connect_timeout3Nb_get_retry3Delay_before_retry3Connect_port6379}} real_server192.168.72.128 6379{weight1Tcp_check {connect_timeout3Nb_get_retry3Delay_before_retry3Connect_port6379        }    }}

Please note the points:

1, the same group in each machine configuration file router_id can not be the same, many articles say here can be the same is wrong, this is the identity of the group. The virtual_router_id in the same group must be the same, which is the group ID.

2,priority is set priority, the primary server must have a higher priority than the slave server, which is a larger number.

3,interface is followed by the network card name, in Centos7 is not called eth0, it is best to use ifconfig before configuration to see your network card name.

4,real_server in the weight set is the load Balancer priority, if the master-slave hot standby scenario, here can be set to the same.

Keeaplived can detect the master-slave state when the master and slave are running well, when the primary server is down, or the process terminates unexpectedly, first binds the VIP to the slave server, and then promotes the role positioning from the server's application level through the specified script, which is run in Redis slave No one, when the primary server resumes service, binds the VIP back to the primary server, and then invokes the script to synchronize the data stored from the server during the primary server outage, and then promote the primary server Redis process to primary redis, degraded from the server Redis to the backup process. These features are implemented by actively invoking the Notify_master script, which can, of course, be configured for other functions, so this allows keepalived to work on many occasions.

Use keepalived to create Redis dual-machine hot standby

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.