Master side: 192.168.2.156
! Configuration File forKeepalivedglobal_defs {notification_email {[email protected] [email protected] [email protected]} Notification_email_from [email protected] smtp_server192.168.2.156Smtp_connect_timeout -router_id lvs_devel}vrrp_script Check_nginx {script"/data/sh/check_nginx.sh"interval2Weight2}vrrp_instance vi_1 {State BACKUPInterfaceeth0 virtual_router_idWuyi Priority -Advert_int1Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {192.168.2.100} track_script {Check_nginx}}
Slave End: 192.168.2.157
! Configuration File forKeepalivedglobal_defs {notification_email {[email protected] [email protected] [email protected]} Notification_email_from [email protected] smtp_server192.168.2.156Smtp_connect_timeout -router_id lvs_devel}vrrp_script Check_nginx {script"/data/sh/check_nginx.sh"interval2Weight2}vrrp_instance vi_1 {State BACKUPInterfaceeth0 mcast_src_ip192.168.2.157virtual_router_idWuyi Priority -Advert_int1Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {192.168.2.100} track_script {Check_nginx}}
Fail-over script
#vim/data/sh/check_nginx.sh
#!/bin/Bash COUNT=$ (ps-c nginx--no-header |WC-l)if["${count}"="0"];then Echo"re-start Nginx"Sleep2COUNT=$ (ps-c nginx--no-header |WC-l)if["${count}"="0"];then systemctl stop keepalived Fifi
# chmod a+x/data/sh/check_nginx.sh
[Email protected] ~]# crontab-e
*/1 * * * */data/sh/check_nginx.sh >>/var/log/check_nginx.log
Test : When we try to stop Nghinx, when we stop the nginx manually for about 2 seconds, the keepalived is turned off and the VIP transfer is realized.
Browser Access Browse: VIP192.168.2.100
Remember once nginx+keepalived high-availability failover