dual master and standby keepAlived

nginx can be configured with default

1, standby configuration

1, the main configuration keepAlived

{VI_1 vrrp_instance 
    State the MASTER    # distinguish standby 
    interface eth0 
    virtual_router_id 51 is   # standby consistent 
    priority 100    # standby distinguish 
    advert_int. 1 
    authentication { 
        AUTH_TYPE the PASS 
        AUTH_PASS 1111 
    } 
    virtual_ipaddress { 
        192.168.244.200 
    } 
    track_script { 
        chk_nginx 
    } 
}

2, the configuration Preparation keepAlived

{VI_1 vrrp_instance 
    State the BACKUP   # distinguish standby 
    interface eth0 
    virtual_router_id 51 is    # standby consistent 
    priority 50      # standby distinguish 
    advert_int. 1 

    authentication { 
        AUTH_TYPE the PASS 
        AUTH_PASS 1111 
    } 
    virtual_ipaddress { 
        192.168.244.200 
    } 
}

2, the master spare

1, the first configuration keepAlived

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
}

2, a second configuration keepAlived

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
}

 

3, the detection Nginx, to achieve high availability standby

1, the first configuration keepAlived

vrrp_script chk_nginx {
    script "/zjl/program/nginx/conf/checkNginxAlived.sh"
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
    track_script {
        chk_nginx
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
    track_script {
        chk_nginx
    }
}

2, a second configuration keepAlived

vrrp_script chk_nginx {
    script "/zjl/program/nginx/conf/checkNginxAlived.sh"
    interval 2
    weight 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
    track_script {
        chk_nginx
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
    track_script {
        chk_nginx
    }
}

3, monitoring script

! # / bin / bash 
psnginx PS -C = `nginx --no-heading | WC -l` IF [$ psnginx == 0]; the then 
    echo" nginx service is down, try to restart ... " 
    / ZJL / commond / nginxbegin-start.sh SLEEP . 3
     IF [ `--no-PS -C Nginx heading | WC -l` -eq 0]; the then 
        echo" Nginx attempt failed to start off keepalived " 
        killall keepalived the else 
        echo" Nginx successfully restarted " 
    fi the else 
    echo" nginx normal service ... " 
fi

    
    

Guess you like

Origin www.cnblogs.com/happydreamzjl/p/10986237.html