Pi Cluster: E1 Building up

If you have a lot of spare Pi’s around, like I do, you’ll probably want to do something with it.
So after a few searches for a new project i found that it was possible to use them in a cluster.

So what is a cluster?

In this case a cluster is a group of Raspberry Pi Computers all working on a part of the task you want to complete. You can start your cluster with as little as two Pi’s, to more then a hundred Pi’s or many more. For our project, we’re starting with a modest five. Each one, known as a ‘node’, will carry out part of our task for us and they all work in parallel to produce the result a lot quicker than a single node ever could. There are some nice cluster cases available but that is not really required to get going. There are many possibilities but we’ll start with a simple acrylic case.

Requirements

• 5 (or more) Raspberry Pi’s
• Preferrably Pi3B+ or Pi 4B (for later episodes)
• Power Supply
• 5 Normal Pi Supplies (chose the correct one)
• or a single power supply like the Anker PowerPort 6
• Or a custom supply
• 5 SD cards, 16Gb min
• Case
• Cluster case
• individual cases
• or custom case

Power considerations

Considering the power requirement for your cluster you need to take into account the requirements for a single node. With the five nodes we are going to use at 2.5A each (3A for a pi 4) we’ll need around 62,5W (75W for the Pi 4). Now in most cases we don’t need all the power so we’ll probably could use a 60W charger.
To be save of course you could use 5 individual Pi Supplies, but that is only messy.
Do be careful of the higher demands of Raspberry Pi 4.

Networking

A cluster needs communication. The master node is in charge of the cluster and the other nodes will do its bidding and report back to the master node. To achieve this we’re going to use Ethernet, preferably a dedicated network. I used a TP-Link TL-SG108E Smart Switch.
You could use WiFi, but that is not recommended. So, in addition to wireless LAN, we’re linking each node to an isolated Gigabit Ethernet switch.

Setting up the hardware

For this series we chose to use a cheep plastic cluster case.
Each pi is mounted on the platter using a stand-off. When you have done this of all you pi’s, you can add the bigger stand-offs that will keep the layers apart.
You can see the progress of this in the pictures.

So now we have done that its time to go ahead and install the software.

Connecting the Pi

Now the easy part, connect your pi’s using a Ethernet cable to your switch/router.
If your switch hasn’t enough free ports for all your pi’s, I recommend you go and get a simple 1Gbps switch.
If you got some money to spend you can always get a managed switch or even a POE switch (see next episode).

Now that the network is connected, it is time to connect the power brick(s).
To reduce the amount of plugs needed it’s handy to use a USB ‘charger’ like the Anker PowerPort 6 that can handle all your pi’s at once.
This does mean you’ll need (preferably short) micro USB cables.

As you’ll notice the USB power port is not connected to the net yet, we still need to install the software onto the pi’s using the SD cards.

Software Setup

We’ll not get into burning the SD card again as we already covert that in a previous tutorial.
For the cluster you preferably want the Lite version of the Raspberry Pi OS.
Don’t forget to enable SSH! (add a file called ssh that is empty and has no extension to the boot partition of the SD card)

Once you burned the first SD card …. STOP!!!
Before we burn the others lets get the first one up and running and configured.
Lets Get Started.

Network Setup

We are going to use SSH to connect to our clusters, so if you don’t know how this works you can check out our Remote Access tutorial.
If you don’t have a screen and keyboard you can get your pi’s IP addresses using an IP scanner like ‘Angry IP’ of ‘Advanced IP Scanner’.

Once you have your Pi’s IP use an SSH client (see out remote access tutorial) to get connected to your Pi.
As always the standard password for the PI user is ‘raspberry’.

When logged in the first thing we will do is change the default password for security reasons.

passwd

The next thing we want to do is update our system. This might take some time so take a break.

sudo apt update && sudo apt upgrade -y

As we are in the console we might as well configure the time-zone correctly.

sudo dpkg-reconfigure tzdata

For the cluster you want to have a fixed IP on the Client side if possible. So find out what range you are using in your network and chose free IP’s that are next to each other.
We are going with 192.168.1.21 to 192.168.1.30 (only the first 5 are going to be used at the moment)

Where do we configure the network?
There is a file in the etc folder that configures the network on boot. Lets head in there and set everything up .

sudo nano /etc/dhcpcd.conf

In this file you’ll find the configuration of the local dhcp.
Near the end of the file you’ll find a commented out section that we are going to use in a bit.
It’ll look like this:

# Example static IP configuration:
#interface eth0
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

Unless you are using IPv6 we are going to ignore this for the build.
We’ll remove the ‘#’ from 4 lines in this fine and change the info behind it.
Like this

# Example static IP configuration:
interface eth0
static routers=192.168.0.1
static domain_name_servers=192.168.0.7 8.8.4.4

We uncommented all but the first and forth line of code.
What do we actually ask from our pi here?
The first line is just some comment, as is the forth as the ‘#’ isn’t removed.
The second line tells the DHCP server that we are talking about the ‘eth0’ interface.
Next is our IPv4 IP address, in this case the fixed IP is 192.168.1.21 with a mask of 255.255.254.0
The router in this example is located on 192.168.0.1. For the DNS servers you should use whatever you chose, in this example the first one is on our local network.
This server is a Pi-hole server, you can find out how to set it up here, the other one is the google DNS.

Save this file using ‘Ctrl + x’ and press y. Reboot your Pi and watch the IP change.
When you going to login again you’ll have to use this new IP.

sudo reboot now

Configuring the Pi

Now that we have our network settings sorted out lets head to the rest of it.
First we want to expand our partition to use the full SD card.

sudo raspi-config

Go to Advanced Options > Expand Filesystem
This will take some time, take a small break.
Next is out hostname: System Options > Hostname
You’ll be asked to enter a hostname, but don’t use SPACES!!

Burning the other SD’s

We are ready to burn the other SD’s.
Before we burn the other ones we’ll pull all data from the current SD as we are going to use that image to write the other SD’s.
How we do that you can find out in our Backup Your Pi tutorial.

Once you got all the data of the first SD we’ll label that as number 5 (or 4 depending on how many pi’s you have in the cluster).
Insert this in the Last Pi and boot it.

Once booted login using SSH and change the IP according to the Pi. in this first case it would be 192.168.1.25 (in our example).

When the burning of the rest of the SD’s is completed, continue changing the IP’s accordingly.

Where to now

So we have build our cluster,
To actually install the cluster software and use it go to the second episode.

See you soon!