Martin.xu

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
场景:
两台Haproxy主机:192.168.100.40 , 192.168.100.41
生成浮动IP:192.168.100.200 , 192.168.100.201
 
1、安装ipvsadm
yum install ipvsadm -y
ipvsadm -v

2、安装keepalived

yum install keepalived -y
keepalived -v
3、Keepalived配置
在配置keepalived之前,先关闭selinux
vi /etc/selinux/config
SELINUX=disabled
#如果只想临时关闭,直接输入:setenforce 0
增加Haproxy服务检测脚本
#mkdir -p /data/bin
#vim /data/bin/check_haproxy.sh
#!/bin/bash
A=`ps -C haproxy --no-header |wc -l`
if [ $A -eq 0 ];then
killall keepalived #yum install psmisc
fi
#chmod +x check_haproxy.sh
修改配置
global_defs {
        router_id haproxy-ha
}
vrrp_script check_haproxy {
                script "/data/bin/check_haproxy.sh"
                interval 2
                weight 2
}
vrrp_instance VI_1 {
        state BACKUP                              
        interface em1   #网卡
        virtual_router_id 51   #局域网中相同表示同一组                 
        priority 99                               
        authentication {
                     auth_type PASS
                     auth_pass eric                
        }
        track_script {
                check_haproxy
        }
        virtual_ipaddress {
                192.168.100.201
        }
}
vrrp_instance VI_2 {
        state MASTER
        interface em1
        virtual_router_id 52
        priority 100
        authentication {
                     auth_type PASS
                     auth_pass eric
        }
       track_script {
                check_haproxy
        }
        virtual_ipaddress {
                 192.168.100.200
        }
}

 

posted on 2017-04-18 16:11  Martin.xu  阅读(114)  评论(0编辑  收藏  举报