Load Balancing Server For Dummies: Tutorial Part 1
How can I build a load-balancing server using low end VPS? Your answer is here. As promised before, I will write a practical tutorial to guide newbies and dummies build their own zero-downtime hosting using load-balancing setup. The main purpose of using load balancing is keeping your website up through traffic spikes as well as to keep your site’s up and accessible even one of hosting server is down. The main point of how such kind of technology works is to load balance between two or more identical nodes, so in case if one of the nodes in your cluster experiences any kind of hardware or software failure, the traffic can be redistributed to the other nodes working nodes.
Few years ago, server load balancing was very expensive requiring luxury device. But nowadays, we can build more cheap setup using only few low end VPS boxes, DNS server and a magical software called Varnish Cache.
So what this article is all about? This is a guide on how to build server load balancing using few cheap VPS, free DNS server, Varnish Cache, rSync and CentOS.
What is load balancing? I’ve explained that a bit at the top of this article. Shortly saying, with a Load Balancer allows users to intelligently distribute traffic to a single IP across any number of servers using a number of different protocols. Quoted from LiquidWeb, there are 3 (three) common methods of load balancing:
- Round Robin: the method will evenly distribute the traffic, but does not take into account the current load or responsiveness of the nodes.
- Least Connect: the method that takes into account the current number of open connections between the load balancer and the server, and sends the traffic to the server with the lowest number of active connections.
- Historical Intelligence or the Perceptive Algorithm: the method that decides which node to send the traffic to using both the current number of open connections between the load balancer and the server, and the response times of the nodes.
Which method is this tutorial gonna use it? While LiquidWeb is implementing the third method using Zeus and Cisco load balancing technology. But we are going to use an awesome free-to-use software called Varnish Cache.
Is your method is better than LiquidWeb’s method? Please define what is “better”! Shortly saying, such professional load balancing service use advanced technology with expensive hardware and software to invest so there is no way you gonna get that load balancing technology for free (e.g: their lowest price for load balancing plan is $250/month). So if you reside the money (as cost to spend), yes LiquidWeb’s load balancing is far way better. But if you take money as consideration in defining “better”, then you tell me.
A.1. Round Robin Load Balancing
This the simplest method of load balancing which we can get it for free via services like CloudFlare, CloudNS and many other free DNS hosting providers. What it does is simply distributing the load to all servers evenly and perhaps equally without considering whether the server it distributes the traffic to is offline or not.
Also, we can also build our own Round Robin load balancing server using either Nginx or Varnish Cache but I do really prefer the second option.
A.2. Varnish Cache
It is a “free-to-use” technology capable to do not just load balancing but also caching. It’s main purpose to serve as a web application accelerator also known as a caching HTTP reverse proxy software.
So why Varnish for Load Balancing? It’s simple. Varnish is free and it also has probe feature to check whether one (or more) of available backend servers is down or has decreased response time. Shortly it also works as Perceptive Algorithm method.
B. Low End Load Balancing Setup
So how our setup will be? As this tutorial is written specially for newbies and dummies, so I pick the most easier setup to build which is:
- 1 Load Balancing Server with Varnish Cache
- 2 (or more) web hosting servers
- 1 MySQL database server
- 1 free DNS server supports Round Robin
all of those servers running CentOS 6. You can choose either 32-bit or 64-bit but if the RAM of your VPS is below 1GB, you should simply use the 32-bit version.
Of course there are many other setup schemes but I’ll show you the easiest one.
C. Requirements (stuff you’ll need)
- 1 VPS for Load Balancing server with varnish Cache. This should be a very reliable, stable and having great uptime VPS with at least 256MB of RAM, greater is better.
- 2 (or more) VPS boxes to server as web hosting to store all your website’s files.
- 1 VPS to serve as MySQL database server
- CentOS 6
- Varnish Cache
- 1 Free DNS server.
- Two cups of coffee
C.1. VPS for the load balancing server
As this server is prepared to act as Load Balancing server —the one that distribute traffics and loads— so this one should be a rock solid server purchased from reliable and trusted VPS hosting providers. To mention few (that’s also cheap): RamNode, DigitalOcean, Iniz, Edis, iwstack, Vultr, BuyVM and many others.
How much RAM needed? That depends on whether you wish to use RAM-based caching or Disk-based caching (Varnish supports both). If you choose to use RAM-based caching, then you should at least have 512MB (1GB or more is recommended). But if you choose disk-based caching, a 256MB box will be fine but make sure your disk is as fast as lightning. Personally I choose to use disk-caching. I pick and trusted this job to RamNode’s SSD VPS with 700MB/s I/O speed (tested and benchmarked by me). HostHatch also has similar I/O speed but they only have nodes in Netherland.
C.2. VPS for the web hosting
I mean two or more VPS boxes where your website’s files are actually hosted at. These servers doesn’t have to be very rock solid or having great uptime (as long as trusted by many users). Few low end VPS boxes are fine. To mention some providers: Crissic, GreenValueHost, UGVPS, OpenVZ.io, OverZold, BlueVM, VPSDime, ChicagoVPS, FTPIT and many others or simply any VPS from your favorite providers.
The keys of choosing servers as web hosting are:
- Make sure it is cheap because you might need more than two if you want.
- Make sure the providers have quite positive reviews
- Make sure all servers’ main node are closely geographically located between each other to minimize latency.
C.3. MySQL Server
This server should also be a rock solid server if you plan to use 1 VPS dedicated as database server.
C.4. CentOS 6, Varnish Cache, rSync and LAMP
That’s the software we’ll use.
C.5. Free DNS Server
Of course you can choose to use paid DNS server but while there are many free DNS hosting providers, I found no reason to use paid one. The key here is: make sure it supports Round Robin DNS.
D. Basic Knowledge
I tagged this article as “advanced” simply because there are few basic skills you have to firstly master it (you don’t have to be a Ninja, at least you know what you are doing):
- How to use Putty (Windows) / Terminal (Mac/Linux).
- Most common shell commands to manage a Linux server
- How to Install LAMP on CentOS server
- How to Install Varnish Cache on LAMP CentOS Server.
Ok, I have read and I have all of those stuff above. What’s next?
Next, preparing your web hosting servers and syncing.
** stay tuned for the update. Don’t forget to follow me on twitter @servermomdotcom.
Part 1 – Introduction, Low End Setup, Requirements and Basic Knowledge
Part 2 – Setup Web The Server (Apache, PHP, rSync, etc)
really nice post locking forward for the next part
Very interesting, many thanks for the post!