It seems inevitable that anyone that is interested in computer programming eventually becomes interested in the idea of parallel programming. After a little bit of searching you eventually discover the world of cluster computing, only to find that there is really nothing out there to help.
I think this is because cluster computing is still pretty expensive to play with, unless you are a government agency, corporate entity, or educational facility. This leaves me out in the cold…
Or does it. I have started to see more and more blogs and tutorials describing how to build a low-cost cluster out of Raspberry PI single board computers. I have to admit I have been a tremendous fan of the Raspberry PI since it first came out. They run Linux, promote Python as the programming language of choice, and best of all, they only cost $35. But I could never figure out what I would do with one, and then I found clusters, oh sorry, they are called brambles when they are built with Raspberry PI’s.
How cool would it be to have an affordable cluster that you experiment with? I loved the idea, so I went out and purchased the components to build a small 3 node Raspberry PI Bramble.
- 3 x Raspberry PI 3 @ $35 for 1
- 3 x 32GB microSD card @ $11 for 1
- 3 x 1 ft ethernet patch cords @ $12 for 6
- 3 x 1 ft USB to micro-USB cords for power @ $11 for 10
- 1 x RavPower 4-port USB charger @ $22 for 1
- 1 x Netgear 5-port ethernet switch @ $20 for 1
- 1 x Stackable 4-layer dog-bone case @ $23 for 1
The total price was $226. Not bad for a 3-node bramble!
While I have built my bramble with 3 Raspberry PIs (I will refer to them as nodes from now on) it is not necessary to have more than one. It turns out you can still play with clustering with a single node.
The following sections are a review of the initial steps to configure each node of your bramble. In summary:
- Flash the microSD card with the OS
- Add an empty file named ssh on the newly flashed microSD card
- Put the microSD card into the node
- Boot the node
- Login to the node
- Setup a static ip-address (unique on each node)
- Run raspi-config
- Change the password (same on all nodes)
- Set so ssh server starts on boot (same on all nodes)
- Change the hostname (unique on each node)
- Set the memory split to 16 (same on each node)
- Exit and restart
- Repeat for each node
Once you have completed each of the above steps you will probably think you now have 1 or more nodes for use in a bramble. But that would be wrong! In the next blog I will cover how to finish the configuration.
What follows is arguably the most confusing aspect of setting up any Raspberry PI, let alone a bramble of them.
I must point out right now that I am a Mac user and all of the steps after this are done using Mac OS, though Linux users should have no difficulty with them. As for Windows users, I apologize, but I do not have the hardware to figure out how to do all of this for you, though I know there are lots of blogs out there that have.
Setup the microSD cards
I have opted to the use raspbian-stretch-lite distribution that is available here. I went with the lite distribution because I plan on using my Mac to ssh into the bramble and am not going to be needing the Graphical User Interface part of the operating system.
To put the operating system on the microSD card, called flashing, I had to mount the card on my computer. Fortunately I have an older Mac that still has an SD card slot. I was able to flash the microSD cards each using the excellent app Etcher that is available here. The microSD card is named boot after the flash finishes.
After flashing, the microSD card is left unmounted. To mount it extract and reinsert it and it will mount and show up on the desktop. Once mounted I performed the following in the terminal
The touch command is used to change the modified timestamp of a file to the current time. In this case there is no file named ssh and so it creates an empty one. Putting this file on the microSD card makes it so the Raspberry Pi it is inserted into starts the ssh server after it boots. But don’t boot it just yet. It is easier to do them all together so be sure to configure each of the microSD cards the same way.
I did not want to mess with the whole, “what is my ip-address?” thing, so I connect my first Raspberry PI to my TV with an HDMI cable. My Mac is plugged into one of the ethernet ports of the switch as are all of the Raspberry PI’s. Now I plug the micro USB cables into each of the Raspberry PI’s power connector.
Now I only plug into the USB charger the Raspberry PI that is connected to the TV. As the PI boots, I will be able to watch the progress on the TV. At the very end I can see that the ssh server is being turned on and finally it will say something like ‘the ip-address is xxx.xxx.xxx.xxx’. I am looking for a line above the login prompt when the boot has completed that has 4 numbers separated by periods. This is the ip-address that has been assigned to the PI. Write it down.
This is unquestionably the most confusing part of setting up a cluster. Again, if you are having trouble I refer you to all of the other blogs that discuss how to figure out your ip-address. The point is to get what the current ip-address is so that you can ssh into the PI to finish the initial configuration.
In the Terminal I can now log in using the ip-address I wrote down earlier and then entering the password when prompted:
>> ssh email@example.com
The user is pi by default and the default password is raspberry.
And I am logged in.
At this point I set the node to have a static ip-address. By doing this I have made it so that I do not use the bramble anywhere else, but can always access it from my Mac.
In the Terminal I type
sudo nano /etc/dhcpcd.conf, scroll all the way to the bottom of the file and on a new line type
static ip_address=xxx.xxx.xxx.xxx/24, where xxx.xxx.xxx.xxx is replace with the ip-address I wrote down earlier, followed by return. Remember each node must have it own unique ip_address.
While I am still logged into the node I type
sudo raspi-config followed by enter. This brings up the raspi-config tool interface. Be sure to do the following:
- change the password (this should be the same on all nodes)
- set ssh to always on (this should be the same on all nodes)
- set the hostname (this should be unique on each node)
- change the memory split to 16 (this can be the same on all nodes)