1

I have two servers (A-master and B-backup) with one virtual ip.

I need to assign the virtual ip to server B in case server A fails. For this I'm trying to configure keepalived.

server A virtual ip is configured on eth0:1 server B virtual ip is currently set to some other ip address in eth0:1

I'm not sure how to configure keealived. do I have to assign same virtual ip to both servers and start keepalived or set virtual ip only in server A

2

First of all, alias interfaces like eth0:1 used to be important about 15 years ago, when a network interface could only host a single IP address. For more than a decade, you can add multiple IP addresses to the same network interface without having to use interface aliases:

/sbin/ip address add 192.0.2.123/32 dev eth0
/sbin/ip address add 192.0.2.124/32 dev eth0
/sbin/ip address add 192.0.2.125/32 dev eth0
/sbin/ip address list
/sbin/ip address del 192.0.2.124/32 dev eth0
/sbin/ip address list dev eth0

So just in case you considered the idea of having only a single IP address per interface: forget about it, there's not much need for doing so, and keepalived also won't follow that idea.

Essentially, you'll be assigning individual IPs to each of your servers manually and configure keepalived to take care of adding or removing a list of extra virtual IPs to one of your servers interfaces.

vrrp_instance VRRP_1 {
    state BACKUP
    interface eth0
    virtual_router_id 101
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass sometext
    }
    virtual_ipaddress {
        192.0.2.123
    }
}

This will make Keepalived on both hosts periodically announce (using their manually configured IPs) it is ready to host a specific list of virtual IPs (max 20); that announcement also contains a priority (8 bit) and an authentication token (max 8 chars).

If one of your hosts doesn't see an announcement for the same virtual_router_id using the same authentication and for the same list of max. 20 IPs and with no higher priority than its own within a few seconds, it'll add those extra IPs to the host's interface, otherwise it'll remove them from the host's interface.

If your hosts are using the same priority: the announcing IP address is also used to decide who shall host that virtual IP address.

keepalived will also warn about (and ignore any other announcements) if you're using the same virtual_router_id than anyone else on your network, but you're using a different list of IPs or a different authentication token.

keepalived's "MASTER" and "BACKUP" state is just used for an initalization assumption on startup: a system starting in "MASTER" state won't wait for any other announcements to arrive and immediately start adding the extra IP address, while a BACKUP node will wait for a few potential announcements to pass before deciding wether (not to) to add the extra IP address.

Please do make sure your BACKUP node is not announcing the IP address with a higher priority than the MASTER; otherwise, your MASTER node will immediately take over the IP address after starting keepalived, and a few seconds later, your BACKUP node will take over that IP address.

My personal preference is not to care about "MASTER", configure all nodes to "BACKUP" and let VRRP decide what needs to be done without flip-flop-takeover.

  • Thanks, your explanation is very clear. alias interface was pre configured by someone else. Another question, I have two scripts. one to run in each node when in MASTER state and one in BACKUP state. how to configure that in to keepalived.conf ? – ivcode Aug 28 '14 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.