跳转至

Haproxy HA(Keepalived)


2015-11-17 by dongnan

环境

VIP: 1.1.1.1
Master: 1.1.1.2/10.0.100.2
BACKUP: 1.1.1.3/10.0.100.3
Web1: 10.0.100.4
Web2: 10.0.100.5

注意,如果系统有防火墙,则需要允许 vrrp 协议通过。

目标

使用 KeepaliveHaproxy 负载均衡器配置高可用功能,确保负载均衡器在架构中不是单点。

配置文件

Haporxy 配置文件参考这里

注意,keepalived 的 Master 与 Backup 配置文件的区别。

Master

! Configuration File for keepalived

#Global
global_defs {
   router_id haproxy-ha
}

vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 3
    fall 3
    rise 1
    weight -30
}

#VRRP
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    track_interface {
        eth0
        eth1
    }

    virtual_router_id 45
    priority 120
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass zongming.net
    }

    track_script {
        chk_haproxy
    }

    virtual_ipaddress {
        1.1.1.1
    }
}

Backup

! Configuration File for keepalived

#Global
global_defs {
   router_id haproxy-ha
}

vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 3
    fall 3
    rise 1
    weight -30
}

#VRRP
vrrp_instance VI_1 {
    #state MASTER
    state BACKUP
    interface eth0
    track_interface {
        eth0
        eth1
    }

    virtual_router_id 45
    #priority 120
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass zongming.net
    }

    track_script {
        chk_haproxy
    }

    virtual_ipaddress {
        1.1.1.1
    }
}

验证

测试过程请参考 Nginx HA(Keepalived) 测试过程。

参考

Nginx HA(Keepalived)

回到页面顶部