Load Balanced web servers?


7 posts
by NateL » Mon Jan 28, 2013 7:03 pm
For a web project I'm working on, I will eventually need multiple servers with load balancing capabilities.

I figured buying a couple of RPis might be good practice. I've seen a few topics on setting up a RPi as a web server, but not multiple servers that are load balanced.

As for the physical setup, would I just use my home router/switch and assign a static IP to each RPi? Could I use one RPi to store the database, and then another RPi to run Apache and PHP? I've never really messed with multiple servers for a web application. I've always increased a single server's beef rather than add additional servers, and I'm just looking for a place to start.

Thanks!
-Nate
Posts: 3
Joined: Mon Jan 28, 2013 4:16 pm
by Spid » Mon Jan 28, 2013 7:21 pm
I will always assume you are running Raspbian for desktop and Raspbmc for XMBC !
Posts: 525
Joined: Sat Jan 19, 2013 12:47 pm
by NateL » Mon Jan 28, 2013 8:24 pm
Thanks!

It's definitely doable - as noted in many blog posts. But there's not really a DIY on how the farms are created. I have limited Linux experience and some network experience.
Posts: 3
Joined: Mon Jan 28, 2013 4:16 pm
by titanicsaled » Tue Jan 29, 2013 12:17 pm
Load balancing is very possible for the Pi.

There are many different ways to do this, one is to split services (webserver,mysql, ftp) over different Pi's. Another is to split the files across Pi's (images on one, html on another etc). But in my opinion, the best (and most complicated) way to achieve load balancing is to setup one Pi as a nginx proxy to distribute the load to the two Pi's hosting the same files. You can even set how much load is distributed to each Pi!

I would write a guide on how to do this but at present I only have one Pi.
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm
by NateL » Wed Jan 30, 2013 6:24 pm
It sounds like a fun challenge!

Since you can write a guide, can you give me some direction as far as where I can start?

How should the network infrastructure be set up, physically as well as logically?
As far as setting up the software, do you have any guides that you can suggest to set up the software for load balancing between 3+ machines?

I appreciate the info :)
Posts: 3
Joined: Mon Jan 28, 2013 4:16 pm
by technion » Thu Jan 31, 2013 12:43 am
NateL wrote:Iet up the software for load balancing between 3+ machines?

I appreciate the info :)


The easiest solution here may be:
One Pi running Varnish at the "front"
That Varnish Pi proxying to two or more backend servers
SQL services running on another device

It's often worth looking at the backend somewhat before throwing more hardware at a problem. For example, I've seen some terrible SQL queries that developers wanted to throw more hardware at, when all that was needed was to tune the query.
Edit; You refer to Apache, but if the goal is squeezing peformance, the Nginx application discussed by the earlier poster may be a better option.
Posts: 239
Joined: Sun Dec 02, 2012 9:49 am
by titanicsaled » Thu Jan 31, 2013 12:48 pm
NateL, You should look at how to use nginx's proxying feature to load balance multiple servers. It may also be worth you looking into HAproxy, this performs more or less the same function as nginx proxy.

Physically, you would need to connect your Pi's to your router and assign all of them a static IP address.

I would just experiment with nginx proxy and see if you can get it to work.
Posts: 15
Joined: Tue Feb 28, 2012 4:24 pm