Set up a new Raspberry Pi 3 to join the cluster

Submitted by code_admin on Wed, 07/25/2018 - 15:23

The standard ClusterHat configuration has a RaspberryPi 3 controller and 4 Pi Zeros plugged into the top. I wanted to run a DB server and I thought it would be good to seperate it from the controller so I purchased another RaspberryPi 3, SDCard and Standoffs. I could then attach it physically below the controller and I then used this process to set it up.

Downloaded latest Raspbian Jessie Lite image

Put the image on the SD card

While the SDCard is in the host machine I changed the file /etc/wpa_supplicant/wpa_supplicant.conf to add my cluster networks wireless username and password:

  1. country=GB
  2. ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
  3. update_config=1
  4. network={
  5.     ssid="The_ESSID_for_cluster_network"
  6.     psk="wifi_password"
  7.     id_str="main_net"
  8. }

Change the file /etc/hostname from raspberrypi to the new host name. I chose p3-1 as all my pi zeros are named p1, p2, p3, p4, and I will adopt the names p3-1, p3-2, etc. for any raspberry pi 3's in my cluster.
When you choose hostnames not that you can not use underscores.

Also change the entry in the SDCards /etc/hosts file:

  1.   localhost
  2. ::1     localhost ip6-localhost ip6-loopback
  3. ff02::1     ip6-allnodes
  4. ff02::2     ip6-allrouters
  6.   p3-1

Default raspbian images come with SSH turned off. It must be turned on:
on the SDCard
rename /etc/rc2.d/K01ssh
to /etc/rc2.d/S01ssh

create a file /etc/SSHFLAG
insert the following code into etc/rc.local just above the exit 0 line

  1. if [ -e /etc/SSHFLAG ]; then
  2.   /usr/sbin/update-rc.d -f ssh defaults
  3.   /bin/rm /etc/SSHFLAG
  4.   /sbin/shutdown -r now
  5. fi
  7. /etc/init.d/ssh start

Ejected the SDCard and placed it into the new RaspberryPi 3

Log into the controller

Check the dhcp leases to find new ethernet address of new raspberry pi:

  1. cat /var/lib/dhcp/dhcpd.leases

We need to assign an IP address to the new raspberry pi. To do this:
On the controller alter /etc/dhcp/dhcpd.conf to add a row.
I allocated it ip, add the following to the end of the list:

  1.         host p3-1 {
  2.                 hardware ethernet ??:??:??:??:??:??;
  3.                 fixed-address;
  4.         }

(Replace ?? with the acutal ethernet address found in dhcpd.leases and change all the letters to uppercase)

Restart the dhcpd server on the controller

  1. sudo /etc/init.d/isc-dhcp-server restart

Then restart p3-1
It should pick up the correct ip address. Check this by running:

  1. ping

You should get a response.

Next add the new server to our DNS zone files:

  1. p3-1    IN  A

(Use tabs not spaces)


  1. 105 IN  ptr

(Use tabs not spaces)

Shut down p3-1
Then run the following commands on the controller to reload the dhcp server and bind configuration:

  1. sudo rndc reload
  2. sudo rndc reload

Make sure you see zone reload successful after each command

Restart the controller

Turn on p3-1 and wait for it to boot.
Check it is booted correctly with

  1. ping p3-1

You should get packets back

ssh pi@p3-1

The first thing you should do when logging in to p3-1 in is run raspi-config

  1. sudo raspi-config

Goto Advanced options -> Expand file system. It will tell you that the file system will be expanded apon reboot.

Goto Localisation Options and change the timezone to Europ -> London.

Goto Interfacing options and activate SSH

Click finish.

Next change the SSH password to another value (the default is raspberry but we shouldn't leave it as default)

Finally reboot p3-1

It will take a while to come back online as it will be resizing the filesystem.

When it was booted and I could log in to it I turned it off again and put the SDCard back into my laptop to check the resize operation was sucessful.

We need to put our SSH keys on it so we can then do the rest of the configuration using ansible.
Run the following command from the controller:

  1. ssh-copy-id -i ~/.ssh/ p3-1

Finally double check that it is possible to log in without a password.
Then your done. This new raspberry pi is part of the network and you can now use ansible to finish configuring this device with ansible.

This process can be repeated mutiple times adding devices to the network.


I have created a quick reference page for process I use maintain the cluster here.

If you have found any issues, improvements with this tutorial then it would be great if you share them with me so I can correct and improve my setup. I should be active in the clusterhat forum (!forum/clusterhat)

RJM Article Type
Work Notes