Load Balancing with Hercules and VMware

How-To make a Load Balanced Server with VMWare and Hercules

————————————————————

Prerequisites:

-> vmware player

-> A computer with about 256 MB of RAM

We are going to make a load balanced pair of LAMP installations. For this we are going to use virtual appliances that you can download from: http://www.vmware.com/vmtn/appliances/index.html

I used Ubuntu Dapper for this tutorial and it’s really simple to install vmware-player here, just open a terminal and do: sudo aptitude install vmware-player. But there’s vmware for win also.

First Step – Downloading

————————

First of all download hercules from here: http://www.vmware.com/vmtn/appliances/directory/300

Now Download a LAMP installation, i used: http://www.vmware.com/vmtn/appliances/directory/465

Second Step – Configuring

————————-

Uncompress Hercules one time and the LAMP installation twice, so you can have two LAMP servers ;)

I have a dhcp server in my network thus, all the new boxes will grab IPs from there. Hercules came configured for not doing nat so it will grab an ip from my dhcp server, we will need to change something in the LAMP VMs configuration for them to have a real ip on my LAN.

Open lamp-1.0.0-x86.vmx with your favorite text editor and comment the following line:

ethernet0.connectionType = “nat”

note: Comments begin with “#”

If you have uncompresed two LAMP installations, you will need to modify both files.

Third Step – Starting VMs

————————-

Login into the VMs with the following info:

LAMP1 and LAMP2:

User: root

Password: [Blank] (press enter)

Hercules:

User: root

Password: root

Now if you have a dhcp server do this to chek up IPs:

#ifconfig

My setup is:

LAMP1: 192.168.1.133

LAMP2: 192.168.1.137

Hercules: 192.168.1.105

As you can see in the image:

ifconfig

Fourth Step – Configuring Hercules

———————————-

Notice that if you open a web browser and put the hercules ip as address, a help page will appear as hercules also run a thttpd server.

Now let’s kill the default load balancer runing program:

#killall -9 pen

Now let’s start our configured load balancer program:

#pen -l pen.log -p pen.pid 192.168.1.105:8080 192.168.1.133:80 192.168.1.137:80

Fifth Step – Testing

——————–

First go and test if your load balancer is working. Open a web browser and put the following as address :

http://192.168.1.105:8080

welcome

If webservers are working you should see apache welcome page. Now add more complexity cretate “test.php” file and put this code inside:

system(“ifconfig”);

?>

With this you will see the ip of the server that we are accessing. Put the file in /srv/www/html/ folder.

works!

Let’s test that the load balancer it’s working. This load balancer has a particular thing, it remebers the host you accessed last so you will need to try from differents ips to see if it’s balancing the load. But you can do a simple test, try accessing the file you uploaded above.

When i do:

http://192.168.1.105:8080/test.php

It shows the ip of LAMP2(192.168.1.137) so i’ll shutdown webserver at LAMP2 with

#/etc/ini.d/httpd stop

Now, when i do:

http://192.168.1.105:8080/test.php

It shows LAMP1(192.168.1.133) YAY!

YAY!

Comments (3) to “Load Balancing with Hercules and VMware”

  1. Readed…

    Press every key to continue.

  2. Did you tried load balancing server with weight. I want ot load blance between 3 server and use with weight server1 highest weight, server 2 with weight 20 and server3 with weight 30 but I can’t get it to work.

  3. I didnt try it but try playing with the config. Something like this could help: http://siag.nu/hypermail/pen/0210.html

Post a Comment
*Required
*Required (Never published)