首页 > 其他 > 详细

keepalived+nginx

时间:2019-08-14 12:55:47      阅读:83      评论:0      收藏:0      [点我收藏+]

先在两台服务器安装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

 

keepalived+nginx

原文:https://www.cnblogs.com/maxuebin/p/11351192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!