Setting up a Linux based software load balancer
As the name suggest Load Balancing is simply spreading the work load between two or more backend servers. Load Balancing can be used for any kind of server – HTTP, SMTP, POP/IMAP, DB. There are several open source software load balancers available but for the purpose of this post we will look at Pen and Balance.
Disclaimer: These steps have worked for me and have been tested on Compaq Evo N610c running Ubuntu 8.04 LTS (Hardy Heron). YMMV. I am not responsible for loss of data or damage to computers.
The packages for both Pen and Balance are available for Ubuntu (both packages are available for OpenSUSE as well). You do not need both Balance and Pen. Either one of them will work. I have included instructions for both so you can test them yourselves and decide which works best.
Installing Balance on Ubuntu
Balance is simple but powerful generic tcp proxy with round robin load balancing and failover mechanisms. It is Open Source Software and released under GPL licensing terms. Inlab Software the developers of Balance also have a commercial version called BalanceNG®
To install Balance run the following command (see screenshot)
sudo apt-get install balance
Using Balance
It is very easy to use Balance. The syntax is
balance port host1 host2
So if you wanted to setup load balancing for two machines that run Apache the command would be
sudo balance -df 80 192.168.1.105 192.168.1.108
The -df tells Balance to display debugging and tracing information messages on the screen and to stay in the foreground. Note we need to run using sudo because we are trying to access ports lower than 1024. (see screenshot)
To use failover mechanism the you need to specify the failover host
sudo balance -df 80 192.168.1.105 192.168.1.108 ! 192.168.1.110
See Balance Manual for more information
Installing Pen on Ubuntu
To install Pen the command is (see screenshot)
sudo apt-get install pen
Using Pen
Pen usage syntax is very similar to Balance
pen port host1 host2
To setup load balancing for two machines that run Apache the command would be
sudo pen -df 80 192.168.1.105 192.168.1.108
The -df displays debugging and tracing information messages on the screen and stay in the foreground. Note we need to run using sudo because we are trying to access ports lower than 1024. (See screenshot)
See Pen web site for more information
Though Load Balancing as listed above is not suitable for Production systems it certainly is helpful if you are developing software and want to test how it would behave behind a load balancer.
1 comment1 Comment so far
Leave a reply






Wow. Never thought it can be so easy
Couple of years ago someone told me about dedicated hardware machines that do the same – I think the name is big-ip. I guess balance is more primitive one, but definitely should do the job for a small guy.