LVS Local node patch for Linux 2.6.25, Centos 5 kernel build how-to

How-tos Published on 3 mins Last updated

Standard Kernel builds of LVS (Linux Vitual Server) don't have the ability to load balance traffic that is from the local node.
For example if you terminated some SSL traffic using stunnel or pound on the load balancer you then wouldn't be able to forward that traffic to a backend real server through LVS.

First many thanks to Siim Põder for helping to port Carlos Lozano's patch from 2.4 -> 2.6
In order to run an SSL reverse proxy on the same node that is running LVS
i.e.

External client --> pound:443 --> Local:443 --> IPVS:80 --> RealServer

The patch for Linux Kernel 2.6.25 is here:
http://downloads.loadbalancer.org/lvs/patches/ip_vs_locallvs.patch

The following is a guide how to install on Centos 5.1:

_Heavily borrowed from: http://howtoforge.com/kernel_compilation_centos

Download The Kernel Sources

First we download our desired kernel to /usr/src. Go to www.kernel.org and select the kernel you want to install, e.g. linux-2.6.25.tar.bz2 (you can find all 2.6 kernels here: http://www.kernel.org/pub/linux/kernel/v2.6/). Then you can download it to /usr/src like this:

cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.25.tar.bz2

Then we unpack the kernel sources and create a symlink linux to the kernel sources directory:

tar xjf linux-2.6.25.tar.bz2
ln -s linux-2.6.25 linux
cd /usr/src/linux
wget http://downloads.loadbalancer.org/lvs/patches/ip_vs_locallvs.patch
cat ip_vs_locallvs.patch | patch -p1 --dry-run
cat ip_vs_locallvs.patch | patch -p1

Configure The Kernel

It's a good idea to use the configuration of your current working kernel as a basis for your new kernel. Therefore we copy the existing configuration to /usr/src/linux:

make clean && make mrproper
cp /boot/config-`uname -r` ./.config

I needed to do a:

yum install ncurses-devel gcc gcc-c++ make rpm-build

Then we run

make menuconfig

which brings up the kernel configuration menu. Go to Load an Alternate Configuration File and choose .config (which contains the configuration of your current working kernel) as the configuration file

Then browse through the kernel configuration menu and make your choices. Make sure you specify a kernel version identification string under General Setup --> () Local version - append to kernel release. I use CS so our kernel rpm package will be named kernel-2.6.25CS.x86_64.rpm. You can leave the string empty or specify a different one which helps you identify the kernel (e.g. -custom or whatever you like).

Please note: After you have installed kernel-2.6.25CS.x86_64.rpm and decide to compile another 2.6.25 kernel rpm package, it is important to use a different version string, e.g. -default1, -default2, etc., because otherwise you can't install your new kernel because rpm complains that kernel-2.6.25CS.x86_64.rpm is already installed!

Once you are happy with the kernel configuration, save & exit menuconfig then simply:

make rpm

This may take quite a long time....
Once it has finished:

Source RPM is here:

ls -l /usr/src/redhat/SRPMS/

Binary RPM is here:

ls -l /usr/src/redhat/RPMS/x86_64/

now install the new kernel:

cd /usr/src/redhat/RPMS/x86_64/
rpm -ivh --nodeps kernel-2.6.25CS-1.x86_64.rpm

Now you can either run the following command:

/sbin/new-kernel-pkg --package kernel --mkinitrd --depmod --install 2.6.25CS

Or you can do the usual manual steps i.e.
Make sure you create a new initrd file:

mkinitrd /boot/initrd-2.6.25CS 2.6.25CS

Now configure the boot loader:

vi /boot/grub/menu.lst
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.25CS)
root (hd0,0)
kernel /boot/vmlinuz-2.6.25CS ro root=LABEL=/
initrd /boot/initrd-2.6.25CS

That's it, so reboot and do a:

uname -a

To check that we are using the new kernel:

Linux lbmaster 2.6.25CS #6 SMP Mon Jul 28 13:10:43 GMT 2008 x86_64 x86_64 x86_64 GNU/Linux

Now you should be able to set up any local proxy such as Pound, Stunnel, Squid etc to use your LVS  configuration.

NB. Obviously this only works in NAT mode.