码迷,mamicode.com
首页 > 其他好文 > 详细

haproxy高可用之非抢占keepalived(二)

时间:2017-08-07 17:35:33      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:keepalived haproxy高可用 非抢占

1、安装keepalived

yum install keepalived


2、编辑配置文件 /etc/keepalived/keepalived.conf

主:

global_defs {
    notification_email {
        xiaocheng@qq.com  #可以添加多个邮箱接收报警
    }
    notification_email_from admin@163.com
    smtp_server smtp.qiye.163.com
    smtp_connect_timeout 30
    router_id keepalived_1
}
vrrp_script chk_haproxy {
        script "killall -0 haproxy"    #服务探测,返回0说明服务是正常的
        interval 1    #每隔1秒探测一次
        weight 2      #haproxy上线,权重加2;其他情况权重不变
}
#
vrrp_instance 192.168.1.50 {        #双主实例1
    state MASTER            #ha1(192.168.1.50)为主,ha2(192.168.1.60)为备
   # state BACKUP           #测试下来状态设置为MASTER/BACKUP皆可实现非抢占
    interface eth1
    virtual_router_id 88    #实例192.168.1.50的VRID为88 主备id需设为一致
    priority 101            #主(192.168.1.50)的优先级为101,备的(192.168.1.60)优先级为100
    smtp_alert
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
#
    virtual_ipaddress {
        192.168.1.99    #实例192.168.1.50的VIP
    }
    track_interface {
        eth1
    }
#
    track_script {        #脚本追踪
        chk_haproxy
    }
    #状态变化时你要触发的脚本
    notify_master "/etc/keepalived/notify.sh master" 
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_stop "/etc/keepalived/notify.sh stop"
    notify_fault "/etc/keepalived/notify.sh fault"
}

备:

global_defs {
    notification_email {
        xiaocheng@qq.com
    }
    notification_email_from admin@163.com
    smtp_server smtphz.qiye.163.com
    smtp_connect_timeout 30
    router_id keepalived_2
}
vrrp_script chk_haproxy {
        script "killall -0 haproxy"
        interval 1
        weight 3 #haproxy上线,权重加3;其他情况权重不变
}
vrrp_instance 192.168.1.60 {
    state BACKUP
    interface eth0
    virtual_router_id 88
    priority 100
    advert_int 1
    smtp_alert
    authentication {
        auth_type PASS
        auth_pass 123456
    }
#
    virtual_ipaddress {
        192.168.1.99
    }
    track_interface {
        eth0
    }
#
    track_script {
        chk_haproxy
    }
    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_stop "/etc/keepalived/notify.sh stop"
    notify_fault "/etc/keepalived/notify.sh fault"
}


分别启动192.168.1.50、192.168.1.60上的haproxy、keepalived

这样的话haproxy的高可用就完成了。

本文出自 “linux_cheng” 博客,请务必保留此出处http://6764097.blog.51cto.com/6754097/1954173

haproxy高可用之非抢占keepalived(二)

标签:keepalived haproxy高可用 非抢占

原文地址:http://6764097.blog.51cto.com/6754097/1954173

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!