Skip to navigation


A Banana Pi can easily host a small website, but could easily be overwhelmed by spikes in traffic.  One answer would be to host this site on a PC.  That would be simple, but it would use a lot more power.  

I have found that a cluster of eight Raspberry Pi servers can handle relatively large amounts of traffic.  My Raspberry Pi cluster handled 10,000 hits in one day when my site was featured on Hackaday.

This isn't a huge amount of traffic, but it's much more than my Raspberry Pi site usually gets. Page load times stayed consistent while the cluster handled the spike.  The cluster can't serve as much traffic as a PC would be able to, but it fits my needs, and uses less power than a PC. 

How does it work?

My router is configured to forward incoming HTTP requests on port 80 to a load balancer.  The load balancer is a PC running Lubuntu, with Apache configured as a reverse proxy.  It has two network interfaces (both ethernet), one for receiving requests from the router, and another one to forward requests to the servers.  

The servers are on a different subnet than the local network, and they have different IP addresses.  Anything on the local network has a 192.168.0.x IP address, whereas the servers have 192.168.1.x IP addresses.  The load balancer interface connected to the router has an IP address on the local network, and the interface that communicates with the servers has an IP address on the subnet.

The load balancer receives HTTP requests from the router, and forwards them to one of the servers in the cluster.  The server handles the request and sends the result back to the load balancer.  You can read more about the load balancer's configuration on my Raspberry Pi Cluster

I could use a Banana Pi as a load balancer, and it would probably perform quite well.  However, my load balancer needs to act as a gateway for three different web sites (this site, and, so it needs to be quite powerful.  For that reason, I'm using a PC as my load balancer.

The servers

There are four servers in the cluster.  Each one is simply a Banana Pi with Raspbian running on an SD card.  A copy of this site is installed on each server along with the Nginx webserver. 

One server is a master node.  The site is edited on the master node.  A web API is used to synchronize the files on each node.  This API creates a .tar.gz file containing a backup of the site on the master server, transfers it to the other servers, and unpacks it.

This site is built with the Pyplate CMS, which uses an SQLite database.  SQLite stores data in a file, so the servers' databases can be synchronized simply by copying the database file from the master node to the other servers.

This wouldn't work for many types of sites, but it works in this situation because there's only one person editing this site, and it doesn't need to be updated very often.  

Share this page:

comments powered by Disqus