Build a Raspberry Pi Cluster

How to build a cluster with Raspberry Pi.


Building a cluster with Raspberry Pi is a good way to learn about cluster computing and distributed systems. It is also a good way to learn about Linux and networking. In this post, I will show you how to build a cluster with Raspberry Pi.

The hardware we need is listed below:

Cluster assemble

Easy and self-explanatory. Lots of related videos on Youtube.

We’re going to access each node using wireless LAN and use Ethernet port for communication among nodes. Thus the switch does not have to be connected to internet.

The connection is shown below:

OS installation

We use CentOS in our cluster. To be noticed, the distribution for armv7hl platform is called “CentOS Userland Linux” and not “CentOS Linux”.

  1. For Raspberry Pi 4, we have a limited choice on what version of CentOS we can use. We choose CentOS-Userland-7-armv7hl-RaspberryPI-Minimal-4 for our cluster.
  2. Download the zip file and unzip it to iso image. Image all microSD cards with CentOS7 using Raspberry Pi Imager. The default root passward is centos.

Expand capacity

There is a /root/README file that describes how to expand the root partition to capacity of the MicroSD. On each node, follow the instructions to expand the root filesystem using: rootfs-expand

== CentOS 7 userland ==

If you want to automatically resize your / partition, just type the following (as root user):

Network configuration


On each node, configure Wifi network with Network Manager Text User Interface(nmtui) tool.


There is no eth0 ifcfg files by default. We create a file named /etc/sysconfig/network-scripts/ifcfg-eth0 as follows:

# IPADDR are,,, for master, node1, node2, node3, respectively. 

Restart network service: systemctl restart network

Brand new key

For the cluster to work, each worker node needs to be able to talk to the master node without needing a password to login. To do this, we use SSH keys. Run the following:

ssh-keygen -t rsa

This creates a unique digital “identity” (and key pairs) for the computer. You’ll be asked a few questions; just press RETURN for each one and do not create a passphrase when asked. Next, tell the master( in our setup) about the keys by running the following on every other node:


Finally, do the same on the master node and copy its key to every other node in the cluster.

Setup NFS server

NFS stands for Network File System, helps you to share files and folders between Linux/Unix systems, developed by SUN Microsystems in 1990. NFS enables you to mount a remote share locally.

Install NFS server

Install the below package for NFS server using the yum command.

yum install -y nfs-utils

Once the packages are installed, enable and start NFS services.

systemctl start nfs-server rpcbind
systemctl enable nfs-server rpcbind

Create NFS share

Create a directory to share with the NFS client. We will create a new directory named nfs in the / partition.

mkdir /nfs

Allow NFS client to read and write to the created directory.

chmod 777 /nfs/

We have to modify /etc/exports file to make an entry of directory /nfs that you want to share.

vi /etc/exports

Create a NFS share:

/nfs,sync,no_root_squash,no_subtree_check) defines the range of client IP addresses.

Export the shared directories using the following command.

exportfs -r

Configure firewall

We need to configure the firewall on the NFS server to allow NFS client to access the NFS share. Run the following commands on the NFS server(master,

firewall-cmd --permanent --add-service mountd
firewall-cmd --permanent --add-service rpc-bind
firewall-cmd --permanent --add-service nfs
firewall-cmd --reload

Install NFS client

We need to install NFS packages on NFS client(,, to mount a remote NFS share. Install NFS packages using below command.

yum install -y nfs-utils

Check the NFS shares available on the NFS server by running the following command on the NFS client.

showmount -e

Mount NFS share

Create a directory on NFS client to mount the NFS share /nfs which we have created in the NFS server.

mkdir /nfs

Use blow command to mount a NFS share /nfs from NFS server in /nfs on NFS client.

mount /nfs

You can use the df -hT command to check the mounted NFS share.

Create a file on the mounted directory to verify the read and write access on NFS share.

touch /nfs/test

If other nodes can see the test file, you have working NFS setup.

Automount NFS shares.

To mount the shares automatically on every reboot, you would need to modify /etc/fstab file of your NFS clients.

vi /etc/fstab

Add an entry at the end of the file: /nfs nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

Save and close the file.

Reboot the client machine and check whether the share is automatically mounted or not.

If you want to unmount that shared directory from your NFS client, you can unmount that particular directory using umount command.

umount /nfs

The Raspberry Pi Cluster

Jie Li
Jie Li
Ph.D. candidate in Computer Science