Analysis Lab on Raspberry Pi Cluster

I built my own mini analysis lab to practice and learn something new. An environment that I can use remotely with any device (with RealVNC) and of course an install script to rebuild it quickly anytime.

I hope, it will be useful for others, who want to make their own.

I have learned a lot from the descriptions and solutions of others, you will find these links in the references as well.

The services are distributed as follows


  • 5 Raspberry Pi 4 Model B (4x4gb ram 1x8gb ram) (link)
  • USB power adapter, 6 port Charger 60W (link)
  • Gigabit switch (D-Link Ethernet Switch, 5 Port) (link)
  • 5 USB-C cable (USB 3.1, 0.25 m) (link)
  • 5 Cat6 0.25m Gigabit Ethernet cable (link)
  • 5 Micro SD card (I used 5x SanDisk MicroSDXC Extreme 64GB) (link)
  • Raspberry Pi cluster case with cooling fan and heatsink (link)

1. Install OS:

Raspberry Pi Imager (link) install the last version of Debian Buster for host
(Raspberry Pi OS Legacy with desktop)

Download Ubuntu Server 18.04 LTS for the Raspberry Pi 4 (ARM 64-bit) (link) image for cluster nodes

2. Setup the cluster host:

Setup wifi and enable ssh before insert sd card into raspberry pi.

Create empty file on /boot partition “ssh”

Create file on /boot partition “wpa_supplicant.conf”

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev 
      ssid="SSID name"

After you insert the sd card, you have to set up a few things.

sudo raspi-config

# Enable vnc 
# GPU memory 256
# auto login with desktop
# update
# set display for vnc
# reboot

change the hostname in /etc/hostname file:

# sudo nano /etc/hostname

add this lines to /etc/hosts file:

# sudo nano /etc/hosts clusterhost master worker1 worker2 worker3

Then we can set up a separate subnet:

Step 1: create a file – sudo nano
copy this script to the file or download it:
Step 2: Execute the script on your Pi like so.

sudo bash

Step 3: Reboot.

sudo reboot

3. Preparation of nodes (network, user, authorized keys):

I made a script to set up the network for master and for workers. The differences are only the variables in the top and at script of master node the wlan0 is also configured.

Don’t forget to change these lines for your setup with both of the scripts:

userPass="passwd for pi"

and for master node wlan0 configuration:

echo '    wifis:'
echo '        wlan0:'
echo '            access-points:'
echo '                "<SSID>":'
echo '                    password: "<SSID passwd>"'

After you run it, you can give a new password to pi user:

sudo passwd pi

To change your shell use the chsh command

sudo su pi
chsh -s /bin/bash pi

If you want to run ‘sudo’ command without entering a password:
sudo visudo
and add this line:


Generate public/private rsa key pair for user pi in all cluster nodes:

sudo su pi
ssh-keygen -t rsa

Copy the public keys to the authorized keys list:

cat .ssh/  >> .ssh/authorized_keys

And copy to all nodes:

cat ~/.ssh/ | ssh clusterhost 'cat >> .ssh/authorized_keys'
cat ~/.ssh/ | ssh master 'cat >> .ssh/authorized_keys'
cat ~/.ssh/ | ssh worker1 'cat >> .ssh/authorized_keys'
cat ~/.ssh/ | ssh worker2 'cat >> .ssh/authorized_keys'
cat ~/.ssh/ | ssh worker3 'cat >> .ssh/authorized_keys'

You should do this process in each cluster node. In the end, all nodes will have all public keys in their lists. This is important — not having the key would prevent machine-to-machine communication after.

4. Install script for all node

This will be installed on every node:
Python3 libraries
Jupyter notebook and lab
Nodejs 12

This will be installed only on the “master” node:
Postgresql 10
Jupyter kernels:
### Scala kernel
### Python3 kernel
### Sqlite3 kernel
### R kernel
### Julia kernel
### Bash kernel

You should run this script on each cluster node, the worker node will run for 30-40 min/node, master 3-3,5h, but it depends on your network.
It’s important, if you are using different host names, you have to change it here as well.

If you are done with all the nodes you have to reboot them.

5. First run on the master node:

### Initiating the Hive metastore database schema:
cd /opt/hive/bin
./schematool -dbType postgres -initSchema

### it is necessary to format the data space and start the cluster:
hdfs namenode -format -force

### start services Hadoop and Spark:

cd /opt/spark

### I also disabled the safe mode. To do this, after finishing the installation run:
hdfs dfsadmin -safemode leave

### Create Hive data warehouse on Hadoop filesystem:
hdfs dfs -mkdir -p /user/hive/warehouse
hdfs dfs -chmod g+w /user/hive/warehouse
hdfs dfs -mkdir -p /tmp
hdfs dfs -chmod g+w /tmp
hdfs dfs -chmod -R 755 /tmp

### You should start the hive-metastore first:
/opt/hive/bin/hive –service metastore > /dev/null 2>&1 &
### After initializing the hive-metastore, you should start the hiveserver2:
/opt/hive/bin/hive –service hiveserver2 > /dev/null 2>&1 &
Hadoop Datanode Information
Hadoop Cluster Information
Spark Information
Hive Information
go to folder –> $ cd notebooks

Add password for jupyter, so you don’t have to use token:

jupyter notebook password

You can start jupyter with this command:

/opt/spark/bin/pyspark –master spark://master:7077


Next time you can use this starting script (Zookeeper and Kafka service start commands are included)

6. And you are ready 🙂

All node load activity and UI Tool for Kafka

Hadoop Datanode Information – http://master:8088/

Hive Server Information – http://master:10002/

Spark Cluster Information – http://master:8080/

Representation of Job Execution on Spark – http://master:4040/jobs

Jupyter lab notebooks http://master:8888/lab

7. References:

You May Also Like

Raspberry Pi Zero W – Wireless Router with VPN