Remember once nginx+keepalived high-availability failover

Source: Internet
Author: User

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

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.