You are here

Creating a two-node cluster with keepalived

While trying to balance packets over two hosts, where one of the hosts is both a load-balancer and a realserver, I bumped into an issue adding the local realserver to the setup.

Note that in this example I used 10.0.0.10 as the VIP, 10.0.0.1 as the local realserver and 10.0.0.2 as the remote realserver.

Somehow, when I inserted both machine ip's as realserver only the remote machine got enabled:

[root@machine01 ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
UDP  10.0.0.10:53 rr
  -> 10.0.0.2:53              Route   1      0          0

When I added the local realserver with the ipvsadm command it got added just fine though:

[root@machine01 ~]# ipvsadm -a -u 10.0.0.10:53 -r 10.0.0.1
[root@machine01 ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
UDP  10.0.0.10:53 rr
  -> 10.0.0.2:53              Route   1      0          0         
  -> 10.0.0.1:53             Local   1      0          0

By accident, I found that simply adding the word 'local' after the realserver entry in keepalived.conf makes things work even through keepalived. Now, after restarting keepalived both the local as the remote realserver are added to the config. :-)

The relevant part of my keepalived.conf:

virtual_server 10.0.0.10 53 {
    delay_loop 1
    lb_algo rr
    lb_kind DR
    protocol UDP
    real_server 10.0.0.2 53 {
    }
    real_server 10.0.0.1 53 local {
    }
}

Life can be so simple...