This documentation shows how to us ipvsadm to create load-balanced services on CentOS that are capable of handling over 8 million concurrent connections in 1GB of memory. It's possible to use this to load-balance any service. However, this doesn't take into account data-syncronisation issues you may incur. For this you'll need to set up Networked File Systems and Database replication :) (maybe coming soon).
Instructions for CentOS 5 (with ip_vs loaded in kernel as module).
Load ip_vs module
modprove ip_vs
Install ipvsadm
yum install ipvsadm
Run the following commands on the commandline and test them by visiting the $(external_ip) address in your browser.
ipvsadm -A -t $(external_ip):$(port) -s rr -p $(timeout_in_seconds)
ipvsadm -a -t $(external_ip):$(port) -r $(nat_ip_real_server1):$(port)
-m -w $(weight) [ example = 1 ]
ipvsadm -a -t $(external_ip):$(port) -r $(nat_ip_real_server2):$(port)
-m -w $(weight) [ example = 1 ]
Once you're confident they're set right. run:
ipvsadm --save
This will output the config file to the screen. Copy that into /etc/sysconfig/ipvsadm.
nano /etc/sysconfig/ipvsadm
Restart ipvsadm
/etc/init.d/ipvsadm restart
Test the sites.
Make module & config persistent @ boot time:
echo modprobe ip_vs >> /etc/rc.modules
chmod +x /etc/rc.modules
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! /etc/rc.modules is used instead !!
!! of rc.local as it loads earlier !!!!!!!!!
!! in the boot process.!! !!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
chkconfig --add ipvsadm
Done :)