Get support by phone or email
We have native English-speaking support staff in the UK, US and Thailand, providing friendly support around the clock.
Speak to us in person by calling +1 415 358 5210, +44 (0) 20 7183 8250 or +44 (0)845 686 8642.
Mail us at support@elastichosts.com with your account zone and login email address.
So we've duplicated our MySQL server. The next logical step is to duplicate our web server. We can then send half our traffic to one web server, and one to the other.
In this tutorial, we're not going to do anything smarter than that - literally half to one, half to the other. We'll use a technique called round-robin DNS, which simply alternates requests between the two servers.
Step 1: Set up a new server called albatross
We'll set up a new server called albatross, as in step 1. Connect via VLC and change the root password.
Next, we need to give it a static IP address, as we did for puffin previously, and connect it to the VLAN with the IP address 10.0.0.4.
Step 2: Update our databases to allow connections from this machine
We need to tell both our MySQL databases, on beagle and crocodile, to allow connections from this server at 10.0.0.4.
On both database servers, do the following:
$ mysql -u root -p > GRANT ALL PRIVILEGES ON prices.* to elastic1@10.0.0.4 IDENTIFIED BY 'oag4Chai'; > FLUSH PRIVILEGES; > EXIT;
Step 3: Duplicate our PHP application
Next, we need to install all the software we need to run PHP (note we won't install MySQL on this machine, just php5-mysql).
albatross$ apt-get update albatross$ apt-get dist-upgrade albatross$ apt-get install apache2 php5 libapache2-mod-php5 php5-mysql rsync
Back to puffin, and rsync across our PHP file:
puffin$ rsync /var/www/index.php root@10.0.0.4:/var/www/
Back to albatross, make the file executable and edit it to connect to 10.0.0.3, so we're using the second MySQL server.
albatross$ rm /var/www/index.html albatross$ chmod a+x /var/www/index.php
Then, restart Apache:
albatross$ /etc/init.d/apache2 restart
Visit our new server's IP in a web browser to check it works:
Step 4: Set up round-robin DNS
We won't show this in full here, because what you will do exactly will depend on how you choose to handle your DNS, but in theory this is as easy as adding multiple A records in our DNS zone file.
Suppose we use this in the DNS zone file for our domain:
lamp.elastichosts.com 20 IN A static.ip.1 lamp.elastichosts.com 20 IN A static.ip.2
Now about half the time, a host will see the first address, and half the time the second. And each server will have half the load that our previous single server did.
Note: You should set the TTL low (to 20 seconds) to prevent caching DNS servers keeping one address too long.
But this doesn't handle traffic in a very sophisticated way. In the next tutorial, we will use a 'real' load balancer.
