IPVS, the right way

I had a close encounter with IPVS lately and wanted to document my findings. Imagine a setup whereby you have one IP used for a bunch of hosts on port 80, for the sake of the example we’ll call that one 192.168.66.6, now let us take 3 boxes, the IPVS one with IP 10.10.1.66, and two boxes serving web stuff over 80 on IPs 10.10.1.101 and 10.10.1.102.

So to get this to work, you need to install ipvsadmin on the box along with keepalived. The latter will allow you to load balance between the 2 boxes. Here is the default config:

global_defs {
     notification_email {
         luser@frlinux.net
     }
     notification_email_from root@frlinux.net
     smtp_server 127.0.0.1
     smtp_connect_timeout 3000
     router_id MYFANCY_IPVS
}
virtual_server 192.168.6.66 80 {
    delay_loop 30
    lb_algo wrr
    lb_kind NAT
    protocol TCP
       real_server 10.10.1.101 80 {
        weight 10
        TCP_CHECK {
		connect_timeout 3
        }
     real_server 10.10.1.102 80 {
        weight 10
        TCP_CHECK {
		connect_timeout 3
        }
    }
}

Don’t forget to enable ip_forward in sysctl.conf: net.ipv4.ip_forward = 1.

Then comes the part where you add a default route for the boxes, the cleanest way is to default them to the IPVS box: route add default gw 10.10.1.66. Make sure your changes survive a reboot.

You can now start the IPVS service and watch it fly 🙂

2 thoughts on “IPVS, the right way

Comments are closed.