keepalived+nginx

先在两台服务器安装keepalived和nginx

[root@master-mariadb keepalived]# yum install keepalived -y
[root@master-mariadb keepalived]# yum install nginx -y

 

配置各keepalived文件

[root@master-mariadb keepalived]# vim /etc/keepalived/keepalived.conf
vrrp_script check_nginx {
   script /etc/keepalived/nginx_check.sh
   interval 2
   timeout 3
   weight -30
}

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.37.100 dev eth0 lable eth0:1
    }
           track_script {
                check_nginx
           }
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}

[root@lam keepalived]# vim /etc/keepalived/keepalived.conf
vrrp_script check_nginx {
   script /etc/keepalived/nginx_check.sh
   interval 2
   timeout 3
   weight -30
}
vrrp_instance VI_1 {
    state backup
    interface eth0
    virtual_router_id 51
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.37.100 dev eth0 lable eth0:1
    }
           track_script {
                check_nginx
           }
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
}

 

配置检测脚本

[root@lam keepalived]# vim nginx_check.sh 
#!/bin/bash
killall -0 nginx &> /dev/null  || exit 1

[root@lam keepalived]# vim notify.sh
#!/bin/bash
case $1 in
backup)
systemctl restart nginx
;;
esac

 

posted @ 2019-08-14 12:19  Linus小跟班  阅读(168)  评论(0编辑  收藏  举报