About Load Balancing
Loadbalancing is a useful mechanism to distribute incoming traffic around several capable Virtual Private servers. By apportioning the processing mechanism to several machines, redundancy is provided to the application -- ensuring fault tolerance and heightened stability. The Round Robin algorithm for load balancing sends visitors to one of a set of IPs. At its most basic level Round Robin, which is fairly easy to implement, distributes server load without implementing considering more nuanced factors like server response time and the visitors’ geographic region.Setup
The steps in this tutorial require the user to have root privileges on your VPS.Prior to setting up nginx loadbalancing, you should have nginx installed on your VPS. You can install it quickly with apt-get:
sudo apt-get install nginx
Upstream Module
In order to set up a round robin load balancer, we will need to use the nginx upstream module. We will incorporate the configuration into the nginx settings.Go ahead and open up your website’s configuration (in my examples I will just work off of the generic default virtual host):
nano /etc/nginx/sites-available/default
We need to add the load balancing configuration to the file.
First we need to include the upstream module which looks like this:
upstream backend { server backend1.example.com; server backend2.example.com; server backend3.example.com; }
We should then reference the module further on in the configuration:
server { location / { proxy_pass http://backend; } }
Restart nginx:
sudo service nginx restart
As long as you have all of the virtual private servers in place you should now find that the load balancer will begin to distribute the visitors to the linked servers equally.
Comments
Post a Comment