haproxy高可用之非抢占keepalived
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了haproxy高可用之非抢占keepalived相关的知识,希望对你有一定的参考价值。
1、安装keepalived
yum install keepalived
2、编辑配置文件 /etc/keepalived/keepalived.conf
主:
global_defs { notification_email { [email protected] #可以添加多个邮箱接收报警 } notification_email_from [email protected] 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 { [email protected] } notification_email_from [email protected] 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 + mysql 构建高可用数据库