Creating A Raspberry Pi Cluster - A Tutorial For Students
Creating A Raspberry Pi Cluster - A Tutorial For Students
Begin by assembling
only two of your Pis.
Keep the SD cards and
cat5s aside for now.
SETTING UP THE MASTER NODE:
The SD card that comes with our Raspberry Pi is used to house its operating system.
To set up our master node, we must first install an image of our desired operating
system on it. In essence, an image allows us to get a set of desired software onto our
system quickly and relatively painlessly. We provide an image for you, called pi-
master.img that you can download from the course website.
1. Install Win32 Disk Imager (you may need to use admin privileges).
2. Download the pi-master.img file from the course website.
3. Insert an SD card into SD card reader slot.
4. Using Win32-disk-imager, select the drive the SD card is in (usually the F
drive). Be absolutely sure that the selected drive is the one associated with
the SD card!
5. Use the folder icon to navigate to where you downloaded the image. Click
write. This process may take a few minutes.
6. Once the process is done, safely eject the SD card and boot up your Raspberry
Pi. The login is pi and the password is student. While we will do the
majority of the work on the command line, you can gain a more typical
desktop view by typing in the command startx.
7. Use the cat5 cable to connect your Raspberry Pi to your router. Type in
ifconfig to get your IP address. You should see something like
192.168.1.123. The last 3 numbers will likely be different on your machine. It
should NOT be 255!
8. Replace the IP address in the provided machine_file file in the
mpi_test/ directory by using the following command (replace
192.168.1.123 with the IP address you found in the previous step). Next, cd
into the mpi_test directory.
echo '192.168.1.123' > ~/mpi_test/machine_file
cd ~/mpi_test/
If you make it this far, great job! You are ready to create worker nodes.
1. Create an image for your new worker node by repeating steps 3-6 in the
previous section. Connect the new worker node to the router and boot it up.
2. On the master node, generate an ssh key by typing in the following:
cd
ssh-keygen t rsa C 'pi@raspberrypi'
3. Determine the IP address of the worker node. Usually with routers it is one
number above the IP of your current node. You can test this by typing:
ping 192.168.1.124
If a route to the machine exists, you will get a response. Be sure to check your
connections to the router to ensure that the master node is plugged into the
1 location, and the worker node is plugged into the 2 location. In the
examples that follow, 192.168.1.124 is the IP of the worker node. Please be
sure to replace this with the IP address of your worker node!
4. Copy the log-in credentials to your worker node by typing in the following:
cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'
5. When this is done, ensure you can ssh into the worker node without the need
for any credentials by typing in the following:
ssh [email protected]
to launch the nano editor. Replace whats there with something like
worker001. Restart the machine to see changes:
sudo shutdown r now
This will restarted the worker node, and kick you out of the ssh session.
7. Next, lets repeat the test from the previous section. cd into the the
mpi_test folder and edit the file machine_file and add the IP of your
new worker node:
echo '192.168.1.124' >> ~/mpi_test/machine_file
cd ~/mpi_test/
If the above works, great job! You are ready to create additional worker
nodes! Unlike our test from the previous section, we are now running our
test on multiple nodes!
1. Place the SD card of the worker node you created in the previous section into
your laptop. Fire up Win32-disk-imager.
2. Type a path into the text box:
C:\Users\x0000\Desktop\workerNode.img
where x0000 is your xNumber. Select the drive that contains the SD card.
Click the read button. This will copy the image that is on your SD card to
your desktop.
Once the process is done, remove the SD card, and place it back into your
worker node.
3. Insert a new SD card. In Win32-disk-imager, select the image you just wrote
to your desktop. Ensure the SD cards drive is selected in the window. Click
write. This process may again take a while.
Remember these can be out of order (so dont worry about that). If
everything above works, hooray! You are done!
TROUBLESHOOTING
If the above test fails:
Check and make sure that all the ip addresses in your machine_file are valid.
If not, fix your machine_file with the appropriate ids.
Ensure that you can ssh into the worker nodes from the master nodes
without needing a password. If you are asked to provide a password, that
means the hosts ssh keys were not added to the workers set of authorized
keys. Follow step 4 in the Setting up worker nodes section. Reboot the
worker node!
Ensure that you can ssh from each worker node into the master node (this is
an issue with some routers does not appear to be a problem when
connecting to a switch):
o Edit /etc/hosts.allow and add the following line:
sshd: ALL
If you CAN ssh from each worker node into the master node, BUT require a
password to do so, you may need to add generate an ssh key for each worker
node and add it to the masters list of known hosts. Replace worker001 with
the name of each respective host, and the IP below with the masters IP
address:
cd
ssh-keygen t rsa C 'pi@worker001'
cat ~/.ssh/id_rsa.pub | ssh [email protected] "cat >> .ssh/authorized_keys"