Create a Load Balance Server Using Ubuntu

I had been trying to create a server which would work as a load balancer: receive incoming traffic and forward it to two or more servers. I had one Ubuntu server to use and two web servers to forward traffic to. I tried three options and settled with the last one.

Linux Virtual Server

Linux Virtual Server (LVS) is a kernel module that allows one to set up machines as load balancing servers. There are many tutorials on how to get it to work. However, when I tried all those tutorials, for some reason or another it would not work. I messed up many things on my server without knowing exactly what I was doing or how to set them right again. So I abandoned the idea.

A product I came across while researching this option was Ultra Monkey.

BalanceNG

There are two versions of it available: a free version (Balance) and a commercial version (BalanceNG). It is a user-level program and does not make you mess around with the firewall and kernel. I tried BalanceNG as it was free to be evaluated with one virtual server (load balancer) and two real servers (machines between which traffic has to be balanced). I could not set up the configuration file the way I wanted to.

I did not have the required tools to build software so Installing basic development tools pointed me to the right direction.

sudo apt-get install build-essential

cd /usr/local/src/

sudo tar xvzf ~/Desktop/BalanceNG-1.899-Linux-x86.tar.gz

cd BalanceNG-1.899-Linux-x86

sudo cp bng /etc/init.d/bng

Check that the application was installed where it was supposed to be.

ls /etc/init.d/bng

sudo touch /etc/bng.conf

Now follow the instructions on the product’s website on how to configure it. I was unable to get Balance-NG to work for me. I tried Balance and it felt similar to the next product: Crossroads.

Crossroads

I ended up trying Crossroads. The inspiration was a blog entry — Free load balancer (possible connection broker) for VDI. I downloaded the stable tarball on my desktop and followed their instructions. Following are the steps I took. I did not have the required tools to build software so Installing basic development tools pointed me to the right direction.

sudo apt-get install build-essential

cd /usr/local/src/

sudo tar xvzf ~/Desktop/crossroads-stable.tar.gz

cd crossroads-1.59

sudo make install

Check that the application was installed where it was supposed to be.

cd /usr/local/bin

Create a file called crossroads.conf by using the command below.

sudo touch /etc/crossroads.conf

sudo gedit /etc/crossroads.conf

You may use any text editor other than gedit. I use it because it’s graphical and I don’t need to learn copy-paste in vim or other editor.

My configuration included the following setup: Internet > Firewall > (eth0) Ubuntu Server for Load Balancing (eth1) < Real Servers. These real servers were actually the ones providing services. All the Ubuntu server was doing was forwarding traffic both ways.

Initially, I had two real servers which would get traffic. They would be serving web pages to users. I wanted to keep a user connected to the same machine for the whole session so that there were not too many factors to consider when designing the website within a cluster.

My configuration file contained the following, based on the example provided by the documentation. I have no idea if tabbing and formatting affects the configuration.

service www {
	port 80;
	revivinginterval 15;
	type http;
	dispatchmode random;
	backend one {
		server 172.16.0.10:80;
	}
	backend two {
		server 172.16.0.20:80;
	}
}

Once you have written your configuration file, you can start the server

crossroads start

Surf to the IP address (on eth0 in my case) which the user will be using. Your real servers should now receive connections through the load balancing server and respond to the user through it as well.

19 Responses to Create a Load Balance Server Using Ubuntu

  1. Thank you, this was very helpful. I will try the third option.

  2. bhg says:

    very nice tutorail so this works on any linux?

  3. hs says:

    I believe this should work on any distribution. But there has been a new version out since this post. It’s better to read the documentation for updated information.

  4. Jake says:

    Thanks for the advice and article. I have 2 RHEL web servers and LVS is giving us headaches too. I think I’ll give Crossroads a try.

  5. Pingback: Create a Load Balance Server Using Ubuntu « 关注开源 刘理志

  6. Luigi Molinaro says:

    I love this kind of load balancer but :
    Be careful !
    There is a big difference from crossoroad nad LVS and balanceNG.
    CrossRoad hande in/out traffiic, so every backend pass throught crossroad for the output data.
    IPVS for examle balance only incoming traffic, leaving the backend the outbond traffic.

  7. GZ says:

    Another to look at is:
    HAProxy. http://haproxy.1wt.eu/

    It’s in active development. UltraMonkey may no longer be in development.

  8. aa says:

    very nice so good!

  9. Bob says:

    For anyone interested, I have 4 crossroads balancers running in 2 HA pairs. I was using commercial balancers from Coyote Point (which I was happy with). I decided to build my own using cheap 1U boxes. After 10 months, I am quite impressed with the performance of XR. I was a little skeptical at the beginning because it was a user space daemon. The throughput is sustained at ~65mbit with ~35,000 connections (split between the 2 pairs).

    Anyone that is looking for a great load balancer, give XR a try. It’s is well worth the effort. The filters are very good, and rival the commercial offerings.

  10. Rice says:

    I really like xr (Crossroads). A lot of options are available. The only problem that I have is I need to be able to have a load balancer that forwards the visitor’s ip address as the visitor’s ip address instead of the load balancer’s ip address.

    For an example, if I forward https traffic, the web server sees the visitor as being the load balancer. While this is not a problem for many, it is for us because we use the visitor’s ip address, in addition to username and password as validation.

  11. Nagendra says:

    I really like Crossroads. Could any one please tell me how to configure Oracle Internet Directory 11g (HA) in crossroads.conf file? OID 11g ports are 3060,3131.

  12. Matt Duguid says:

    Have you also tried Varnish Cache for Load Balancing? I use it to select between a number of different Apache/PHP frontends running on Ubuntu and it works great.
    https://www.varnish-cache.org/trac/wiki/LoadBalancing

  13. lipan says:

    hye everyone …can I ask something,
    is this load balancer can be work like this ? let say I want to do the bruteforce attack, so I shared the load to another pc,so the load are shared to two pc…am I correct ?is that the purpose of load balancer ? because i’m planning to use balanceng…n can it done via wifi ? or still need a local cable only ? thx :D

  14. smooter says:

    Bob, and Rice:

    I am currently in the process of getting Crossroads up and running. I have it working well, and I honestly can’t complain. However, I am certain tuning, configuration, and gotchas abound when I decide to go live with it.

    I plan on supporting about 300 desktops with it, and would LOVE to see/utilize the configuration you have with respect to the HA Pairs, and other configuration/gotchas you have gone through.

    Your assistance is GREATLY appreciated!

  15. gerhard says:

    It seems the forum for crossroads has died. I had a problem compiling the latest version on Ubuntu 64bit server and tried to join the forum for help, but my subscription needs approval and it has not happened. Most entries on the forum are from 2008/2009/2010. Copying the files from a previous compile on a different desktop solved the problem (missing link libraries for create_thread etc even though these were installed).
    I now have it working on Ubuntu 12.04LTS, but would like some input: If you want to load balance both http and https, is the only way to do this by running 2 instances of xr, one for port 80 and another for port 443(both on the same IP address) or is there a better way.

  16. smooter says:

    Gotta be honest, I have tried a few of them

    http://www.zenloadbalancer.org/web/ is by far the best. Using it for both SSL and RDP load balancing.

    Nicely built, clean, free, and professional support is available if needed!

    Save a ton of time, and just use Zen!

  17. edib says:

    Definitely, zen load balancer is the best among others. I am using f5 and citrix load balancing solutions in our enterprise, if I was a decision maker, I would not pay money for the other enterprise things.

  18. Matt says:

    So in a couple of paragrpahs interested in why you’d use Zen vs F5, apart from the obvious price cost.

    MD