Update for 2020: keepalived
has been obsolete for a while because it doesn't work in virtual clouds (AWS).
A bit of history
Once upon a time, there was an (Cisco) internet router in the office. The router provided internet access to all the machines and it was good.
... then the router died and internet was broken for everyone and it sucked.
Turns out, it takes two of anything to have redundancy. So Cisco started offering pairs of routers that work in tandem.
This is done with a protocol called HSRP, VRRP or CARP. HSRP is the original cisco-made protocol to solve the problem. It was standardized into VRRP later https://www.rfc-editor.org/rfc/rfc3768 (year 1998) that got implemented by most network devices and vendors. BSD folks reinvented their own protocols CARP to do the same thing, they couldn't adopt VRRP due to concerns around licensing or patents.
Keepalived (and uCARP) is software that implements VRRP (and CARP). It can be setup on two regular Linux servers to have failover between them.
The rise of AWS and the end of VRRP
How VRRP operates? For starters it needs a floating IP, let's say 192.168.1.254, only one router has ownership of the IP at any point in time. Devices in the network simply send traffic to that (floating) IP and reach the active router, they don't know it's floating and don't care. Both routers talk constantly to one another and if either dies, the other router takes over the IP and start processing traffic.
One needs to be familiar OSI network layers 2 and 3 at this point (MAC and IP). Network devices communicate with MAC and IP addresses, addresses are resolved with ARP.
The concept of floating IP being taken-over involves a number of shenanigans in the network stack (all the acronyms above), it's not exactly designed-in nor expected behaviour.
On a physical network, multiple computers physically plugged into one Ethernet switch, it usually works.
On a virtual machine, it usually doesn't work. The virtual network has to handle network traffic (MAC and IP layers), it typically blocks the magic packets or isolate the virtual host preventing VRRP from operating.
On the major virtual clouds (AWS, Google and co). It definitely doesn't work and it's on purpose. Imagine if an AWS instance could take over the IP -all the trafic- from another Linux instance maybe from another customer. What the hell?!
Cloud and CDN solutions
Cloud providers provide load balancers solutions, see AWS ELB and Google Cloud load balancers. They come with build-in redundancy for this problem, so you don't have to think about it. keepalived is simply obsolete.
The next aspect is CDN (CloudFlare, Akamai). All public websites run behind a CDN nowadays that provides caching, filtering and DDoS protection. CDN can provide load balancing between multiple upstream servers. Simply configure all the individual servers and the traffic is split.
Last but not least. keepalived only allows to have a single active server out of many, it's wasting resources to put it lightly. This is actually a catastrophic issue in the real world because things need to scale and it can't scale by design. Failover solutions in use today -as found in clouds and CDN- are meant to distribute traffic across multiple destinations all active. It's a lot more complicated to achieve and is done cumulatively at different layers (see DNS
, Anycast
, OSPF
, BGP
). keepalived is not part of the big picture anymore.