Environment
[Email protected] ~]# cat/etc/redhat-7.1. 1503 ~]# uname-3.10. 0-229. el7.x86_64 #16each:2015 x86_64 x86_64 x86_64 gnu/linux
Host
IP NAME Describe10.0. 0.10 node1 main load 10.0. 0.11 node2 standby load 10.0. 0.12 node3 node 10.0. 0.13 node4 node 10.0. 0.14 node5 node
10.0.0.20 VIP
installation
[email protected] ~]# Yum install-~]# yum install-y ipvsadm keepalived
Primary Load Configuration
Modifying a configuration file
! Configuration File forKeepalivedglobal_defs {notification_email {[email protected] [email protected] [email protected]} Notification_email_from [email protected] smtp_server192.168.200.1Smtp_connect_timeout -router_id lvs_devel vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval0Vrrp_gna_interval0}vrrp_instance vi_1 {State MASTERInterfaceeno16777736 virtual_router_idWuyi Priority MaxAdvert_int1Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {10.0.0.20/ -Dev eno16777736 label eno16777736:0}}virtual_server10.0.0.20 3306{Delay_loop6Lb_algo RR lb_kind DR persistence_timeout -protocol TCP Real_server10.0.0.12 3306{weight1Misc_check {Misc_path"/etc/keepalived/check.sh 10.0.0.12"Misc_dynamic}} Real_server10.0.0.13 3306{weight1Misc_check {Misc_path"/etc/keepalived/check.sh 10.0.0.13"Misc_dynamic}} Real_server10.0.0.14 3306{weight1Misc_check {Misc_path"/etc/keepalived/check.sh 10.0.0.14"misc_dynamic} }}
configuration of the standby load
Modifying a configuration file
! Configuration File forKeepalivedglobal_defs {notification_email {[email protected] [email protected] [email protected]} Notification_email_from [email protected] smtp_server192.168.200.1Smtp_connect_timeout -router_id lvs_devel_backup vrrp_skip_check_adv_addr vrrp_strict vrrp_garp_interval0Vrrp_gna_interval0}vrrp_instance vi_1 {State BACKUPInterfaceeno16777736 virtual_router_idWuyi Priority -Advert_int1Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {10.0.0.20/ -Dev eno16777736 label eno16777736:0}}virtual_server10.0.0.20 3306{Delay_loop6Lb_algo RR lb_kind DR persistence_timeout -protocol TCP Real_server10.0.0.12 3306{weight1Misc_check {Misc_path"/etc/keepalived/check.sh 10.0.0.12"Misc_dynamic}} Real_server10.0.0.13 3306{weight1Misc_check {Misc_path"/etc/keepalived/check.sh 10.0.0.13"Misc_dynamic}} Real_server10.0.0.14 3306{weight1Misc_check {Misc_path"/etc/keepalived/check.sh 10.0.0.14"misc_dynamic} }}
Custom scripts for health checks (Node1 and Node2 configuration)
[Email protected] ~]# vim/etc/keepalived/check.sh
Insert the following configuration
#!/bin/-uwsrep-pnx111111-h$1"select 1; " &>/dev/nullret=$?" if 0 ];then 0Else 1 fi
Start the service
[Email protected] ~~]# systemctl start keepalived
Test
Turn off the main load keepalived to see if the VIP is drifting to the standby load
[Email protected] ~]# Systemctl stop keepalived
Start the main load keepalived to see if the VIP is drifting back
[Email protected] ~]# systemctl start keepalived
Lvs+keepalived+mysql