大网数据广告活动
服务器运维问答

KeepAlived on different subnets

· 52CE 我爱测

I am trying to setup keepalived on ESXi based setup where 2 physical box have ESXi installed and each one having a node which works as load-balancer using HAProxy. Now in order to achieve high availability I want to use KeepAlive…

问题原文

原帖链接 · deej · CC BY-SA 3.0

I am trying to setup keepalived on ESXi based setup where 2 physical box have ESXi installed and each one having a node which works as load-balancer using HAProxy. Now in order to achieve high availability I want to use KeepAlived so both HAProxy instance can share virtual-ip and I can point physical-ip address to virtual-ip address. Challenge with my implementation is that it has 2 subnets.

HAProxy on subnet A: 1.1.10.101 HAProxy on subnet B: 1.2.10.101

Now how when I am trying to assign virtual-ip 1.1.10.201 on both instance then it is pointing to local instance on both Servers.

I am using CentOS 7.x with HAProxy and KeepAlived, primarily to load-balance HTTP traffic and possibly for database too.

I am not posting config file as question itself is very simple but if required I can do that.

已采纳解答

原帖链接 · Theo Cerutti · CC BY-SA 4.0

There is an alternative way. 2 keepalived in differents network can communicate using unicast_peer (it will works as the same as if you have a VIP but you don't)

Then you can use the notify_script to move a IP Failover (provided by your host for example) and make an API call to your provider to tell to move your IP Failover to another service when the keepalived transitioned to MASTER (there is a notify_master rule).

Example of my keepalived config:

global_defs {
    vrrp_version 2
    vrrp_garp_master_delay 1
    vrrp_garp_master_refresh 60
    script_user root
    enable_script_security
}

vrrp_script chk_haproxy {
    script "/etc/keepalived/scripts/check_haproxy.sh"
    timeout 1
    interval 5   # check every 5 second
    fall 2       # require 2 failures for KO
    rise 2       # require 2 successes for OK
}

vrrp_instance lb-vips {
    state {{KEEPALIVED_STATE}}
    interface {{KEEPALIVED_INTERFACE}}
    virtual_router_id {{KEEPALIVED_VIRTUAL_ROUTER_ID}}
    priority {{KEEPALIVED_PRIORITY}}
    advert_int 1
    unicast_src_ip {{KEEPALIVED_UNICAST_SRC}}
    unicast_peer {
        X.X.X.X # here you have all ip of other keepalived
        X.X.X.X
    }
    authentication {
        auth_type PASS
        auth_pass {{KEEPALIVED_AUTH_PASSWORD}}
    }
    track_script {
        chk_haproxy
    }

    notify "/etc/keepalived/scripts/notify_script.sh"
}

Associated variables:

# Keepalived Config
KEEPALIVED_STATE=MASTER
KEEPALIVED_INTERFACE=eth0
KEEPALIVED_VIRTUAL_ROUTER_ID=77
# For electing MASTER, highest priority wins.
# MASTER=101, SLAVES=100
KEEPALIVED_PRIORITY=101
# password: Only the first eight (8) characters are used.
KEEPALIVED_AUTH_PASSWORD=password
# Should be the public ip of the server
KEEPALIVED_UNICAST_SRC=X.X.X.X

# Keepalived Notify Script Config
OVH_ENDPOINT=ovh-eu
OVH_APP_KEY=X.X.X.X
OVH_APP_SECRET=X.X.X.X
OVH_CONSUMER_KEY=X.X.X.X
FAILOVER_IP=X.X.X.X
FAILOVER_SERVICE=X.X.X.X

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。