Five Raspberry Pi working independently thanks to the cluster hat.

Image


Raspberry pi can have multiple hats attached to them. Some can provide sensors, weather predictions, power over ethernet, AA batteries UPS, and so on. The hat I have here allows 4 raspberry pi zero to be attached to a standard size one.



How it works



The cluster hat can handle up to four Raspberry Pi Zero, and this is what I've done here. Each one is seen on the network as an individual machine, so they have their own IP address and can all be accessed remotely via SSH, and it is possible to use them as a cluster or independently. The Pi Zeros get access to the network via a bridge connection made by the central one.



First test with docker swarm

I chose to use it as a cluster, not as individual, because I wanted to learn more about it. Currently, these are my only machines that work as a cluster, and starting with raspberry pi was a great and cheap idea. The first time, I tried to use Docker Swarm to run multiple containers managed by the central Raspberry Pi. Unfortunately, the results were not really good, because some Docker elements were not yet compatible with Raspbian 10, and the one-core CPU of the Pi Zeros had a hard time handling containers. In the end, I decided not to use Docker Swarm for this project, but I still wanted to do clustering or high availability.



Apache web server cluster

After a bit of thinking and searching online for what I could use to make a high availability cluster, I decided to make an Apache web server cluster. I already knew that Debian had some solutions to do that, but I didn't know what exactly. I went to the Debian Wiki, and found an article explaining a utility called Pacemaker, and another one called Corosync. Like many other programs on Linux, the configuration was made by modifying text configuration files. By modifying Corosync's configuration file, I could choose how many nodes I wanted to have in the cluster, and what their IP address would be. I chose to put the four Pi Zeros together as a four node cluster. They already all have a static IP address.

Once the configuration was done on the first cluster node, I had to do the same on all the nodes, so they are all registered in the cluster and seen by the other nodes. When all nodes were configured and registered in the cluster, all was left was the configuration of the Apache web server. The main goal was to attribute a virtual IP to access the web server that would be accessible regardless of which node it was running on. This was done with an utility called CRM. I configured it according to my network settings and addresses and, in the end, everything worked fine. The only thing left was to put a real Apache website on the four nodes, and the cluster was ready to go.



Here's how to check the cluster's status :
Image