References: http://www.austintek.com/LVS/LVS-HOWTO/HOWTO/LVS-HOWTO.LVS-DR.html http://kb.linuxvirtualserver.org/wiki/LVS/DR

IPVS kernel support is already in the default Debian kernel. All that needs to be installed is the administration tool (ipvsadm) and a management tool. The only management tool that I have tested, and thus the one I like most, is keepalived.

Install the tools on the load balancer only.

apt-get install ipvsadm keepalived

All (most) configuration is done on the load balancer side. In particular, /etc/keepalived/keepalived.conf. Below is an excerpt for http load balancing.

global_def {
        notification_email {
                awesie@club.cc.cmu.edu
        }
        notification_email_from root@club.cc.cmu.edu
        smtp_server localhost
        smtp_connect_timeout 30
        router_id www-1
}

virtual_server 128.237.157.89 80 {
        delay_loop 6
        lb_algo wlc
        lb_kind DR
        protocol TCP

        virtualhost www.club.cc.cmu.edu

#       Can't have a server be the local computer, must be remote.
#       sorry_server 127.0.0.1 8080

        real_server 128.237.157.9 80 {
                weight 100
                HTTP_GET {
                        url {
                                path /index.cgi
                                status_code 200
                                #digest 523d93c9f140610c309061167f92a4b2
                        }
                        connect_timeout 3
                        nb_get_retry 3
                        delay_before_retry 2
                }
        }
        real_server 128.237.157.10 80 {
                weight 200
                HTTP_GET {
                        url {
                                path /index.cgi
                                status_code 200
                                #digest 523d93c9f140610c309061167f92a4b2
                        }
                        connect_timeout 3
                        nb_get_retry 3
                        delay_before_retry 2
                }
        }
}

Most of the configuration is relatively intuitive. More documentation can be found at the keepalived website (http://www.keepalived.org).

That finishes all of the load balancer server configuration. So go ahead and tell keepalived to reload it's configuration.

On the backends, you need to tell Linux to accept packets for your virtual server IP. In the configuration above, this IP is 128.237.157.89. There are several ways to do this, as described in the references. Also, as described in the references, since we have our load balancer on the same network as the backends, we need to prevent our backends from broadcasting ARP packets for the virtual server IP, and this is all documented in the references. Below is the way I prefer to do this.

iptables -t nat -A PREROUTING -p tcp -d <virtual_server_ip> --dport <virtual_server_port> -j REDIRECT --to-port <local_port>

It's simple. Doesn't require adding another address to an interface. Note that djbdns doesn't seem to like this at all.

Congratulations! The load balancing is now setup with failover. Both IPVS and keepalived are flexible systems, with support for failover load balancers as well, via VRRP2.