Simone Atzeni Computer Science – Ph.D. Candidate at The University of Utah

How to build a RaspberryPi Cluster

RaspberryPi was invented as educational device to inspire children to study computer science. Nevertheless, in a couple of years it has become the toy of computer scientists, engineers and curious of every age.

RaspberryPi 9 Nodes Cluster

RaspberryPi 9 Nodes Cluster

This project is our successful attempt to build an educational RaspberryPi Cluster composed by one main node and eight computational nodes. In this post we try to explain step-by-step our work in order to allow anybody to build its own cluster.

First of all, we need to make a detailed list of all parts that we have to put together to build our cluster. In the table below are listed all pieces and the websites where you can find them. Amazon and eBay are the most popular electronic e-commerce websites where all these parts can be found easily and for a low price. The prices and the links indicated in the table are the information at the time we built the cluster. At the moment you are reading this post could be out-of-date. Use the name of the part to look for more updated information on Internet.

Part Quantity Price per piece Price
Raspberry Pi Model B 8x $37.50 $300
CanaKit Raspberry Pi (512 MB) Complete Starter Kit 1x $59.99 $59.99
CablesOnline 10-PACK 6inch CAT5e UTP Ethernet 1x $13.79 $13.79
AmazonBasics 7 Port USB 2.0 Hub 2x $18.99 $37.98
Sony 16GB SDHC/SDXC Memory Card 9x $12.95 $116.55
NETGEAR 8-Port Gigabit Ethernet Switch 1x $41.99 $41.99
BUFFALO AirStation N450 Gigabit Wireless Router 1x $83.99 $83.99
Stacked 3 Floors Clear Raspberry PI case 3x $13.99 $41.97
Total Price $696.26

Raspbian Debian Wheezy OS: Installation

There are many specific Operating System to use with the Rasperry Pi. They are usually base on known Linux distribution like Debian, Fedora, etc. For our project we opted for a Debian-based version called Raspbian Debian Wheezy. A ready-to-use image of the OS can be download from here. Once the OS image has been downloaded, it needs to be installed in the SD card. This operation should be done for all SD cards that we have, so for the number of nodes of our cluster, nine in our case. However, since we would need to configure different aspects of the OS, in order to speed up all these operations, we will use some trick. Let us start installing our image only on one SD card. To do this operation we will need an SD card reader. After inserting the SD card in the reader, the command to write the OS in our SD card using a Linux system is the following:

Note that the “dd” command is very powerful and could overwrite any partition of our system. We must be sure that we are selecting the right device. For more detailed instructions refer to the Raspberry website.  There are guides to perform this operation with different systems (Linux, Windows and Mac OS).

Our SD card contains now the Raspbian Debian Wheezy distribution. Now we can put the SD card into the slot of our Raspberry Pi, connect keyboard, mouse and a monitor or a TV with an HDMI cable and turn it on connecting the Micro USB power supply. The first time that we boot our Raspbian operating system, we will be presented a configuration menu. We will choose “Expand Filesystem” to ensure that all the SD card storage is available to the OS. Below the screenshots of the different phases.

[Not a valid template]

Once the filesystem has been expanded we can login in the system with username “pi” and password “raspberry“.

Raspbian Debian Wheezy OS: Configuration

RaspberryPi Cluster Diagram

RaspberryPi Cluster Diagram

Now, we need to configure the network settings of the operating system. Our cluster will have the network structure shown in the picture. We use the NETGEAR 8-Port Gigabit Ethernet Switch to connect seven of the nine nodes, the remaining port is used to connect the switch to the BUFFALO AirStation N450 Gigabit Wireless Router and the other two nodes are also connected to the router. In our project we use a wireless router so that we can have a “mobile” cluster for educational purposes. You can modify the network architecture to better fit your needs.

As we can see from the network diagram, there is a main node called “Pi-Srv”, it will be the head of the cluster to submit the jobs on the other eight computational nodes. Furthermore, the main node will share its own filesystem to the other nodes, in this way there will be only a control point (the “Pi-Srv”) to compile and run the programs. We start the configuration assigning an hostname and a static address IP to each node. The table summarize the network information for each node.

Hostname IP Address Network Mask

The information about address and mask must be inserted in the configuration file under “/etc/network/interfaces” for each node, while the hostname will be inserted in the configuration file “/etc/hostname“. We also edit the file “/etc/hosts” to give each node information about the hostname of the other nodes. Now we are configuring the head node, so our configuration files will look like shown below.



 /etc/hosts (it will be the same in each node)

Now that we have configured the general aspects of one node we can quickly copy the entire OS (already configured) in the remaining eight SD cards. In order to do this let us power off the main node with the following command:

Remove the card from the RaspberryPi and insert it again in the SD card reader to make a copy with the command:

We can copy our OS image inside all the other SD cards running the following command for each card:

At this point we have the same OS and configuration for each one of the nine RaspberryPi. The only operation that we need to do is to change the IP address and hostname according to the table. We can follow the same steps we did for the configuration of the main node. Once this phase is complete we have all nine nodes ready to take part to the cluster.

In order to assembly the cluster let us follow the diagram shown previously and the pictures below.

[Not a valid template]

As we said previously, the master node will share its own home folder to the other computational nodes. In order to do this operation let us follow the following steps:

Server Side (main node Pi-Srv):

  • Installing the NFS Kenel Server package:
  • Add in the configuration file “/etc/exports” the following line:
  • Restart the NFS Kernel Server

Client Side (all nodes from Pi to Pi8):

  • Installing the NFS package:
  • Add in the configuration file “/etc/fstab” the following line: