Alasdair Allan
Published © CC BY-NC

A 4-Node Raspberry Pi Cluster

This walkthrough shows you how to build your own Raspberry Pi cluster, which you can use for development, data crunching, or just for fun.

IntermediateFull instructions provided6,900
A 4-Node Raspberry Pi Cluster

Things used in this project

Hardware components

Raspberry Pi
×4
GeauxRobot 4-Layer Dog Bone Enclosure
×1
Anker 5-Port USB Charger
×1
TP-LINK Ethernet Switch
×1
BlinkStick
×1
Cable Ties
×1
Velcro Strips
×1
USB Flash Drive
×1
Apple USB to Ethernet Adaptor
×1
SainSmart I2C 16×2 LCD panel
×1
Micro SD Cards
×1
USB Cables
×1
Ethernet Cables
×1
Heat-shrink Tubing
×1
Wire
×1

Hand tools and fabrication machines

Philips Screwdriver
Snips
Soldering iron (generic)
Soldering iron (generic)
Scissors

Story

Read more

Code

Code

Plain text
% cat /etc/hosts
 127.0.0.1 localhost
 ::1 localhost ip6-localhost ip6-loopback
 fe00::0 ip6-localnet
 ff00::0 ip6-mcastprefix
 ff02::1 ip6-allnodes
 ff02::2 ip6-allrouters

 127.0.1.1 rpi0
 192.168.1.173 rpi0 rpi0.local rpi0.lan
 192.168.1.177 rpi1 rpi1.local rpi1.lan
 192.168.1.178 rpi2 rpi2.local rpi2.lan
 192.168.1.180 rpi3 rpi3.local rpi3.lan

Code

Plain text
% df -h
Filesystem   1K-blocks  Used Available Use% Mounted on
rootfs     14984668 2513228 11812356 18% /
/dev/root    14984668 2513228 11812356 18% /
devtmpfs     470416    0  470416  0% /dev
tmpfs       94944   232   94712  1% /run
tmpfs        5120    0   5120  0% /run/lock
tmpfs       189880    0  189880  0% /run/shm
/dev/mmcblk0p1   57288  19448   37840 34% /boot
rpi0:/mnt/usb  60467008   64 60466944  1% /mnt/nfs/rpi0

Code

Plain text
% sudo i2cdetect -y 1
  0 1 2 3 4 5 6 7 8 9 a b c d e f
00:     -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- 
20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --            

Code

Plain text
#!/bin/sh -e
#
# rc.local

cd /home/pi
python ip.py
exit 0

Code

Plain text
auto lo
iface lo inet loopback

auto eth1
allow-hotplug eth1
iface eth1 inet dhcp

auto eth0
allow-hotplug eth0
iface eth0 inet static
 address 192.168.50.1
 netmask 255.255.255.0
 network 192.168.50.0
 broadcast 192.168.50.255

Code

Plain text
ddns-update-style none;
authoritative;
log-facility local7;

# No service will be given on this subnet
subnet 192.168.1.0 netmask 255.255.255.0 {
}

# The internal cluster network
group {
 option broadcast-address 192.168.50.255;
 option routers 192.168.50.1;
 default-lease-time 600;
 max-lease-time 7200;
 option domain-name "cluster";
 option domain-name-servers 8.8.8.8, 8.8.4.4;
 subnet 192.168.50.0 netmask 255.255.255.0 {
   range 192.168.50.14 192.168.50.250;

   host rpi0 {
    hardware ethernet b8:27:eb:22:60:fb;
    fixed-address 192.168.50.1;
   }
   host rpi1 {
    hardware ethernet b8:27:eb:a0:a1:7f;
    fixed-address 192.168.50.11;
   }
    host rpi2 {
    hardware ethernet b8:27:eb:68:b6:a3;
    fixed-address 192.168.50.12;
   }
   host rpi3 {
    hardware ethernet b8:27:eb:0b:4e:2c;
    fixed-address 192.168.50.13;
   }
 }
}

Code

Plain text
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.1.1 rpi0 rpi0.local rpi0.lan rpi0.cluster

192.168.50.1    rpi0 rpi0.local rpi0.lan rpi0.cluster
192.168.50.11   rpi1 rpi1.local rpi1.lan rp1.cluster
192.168.50.12   rpi2 rpi2.local rpi2.lan rpi2.cluster
192.168.50.13   rpi3 rpi3.local rpi3.lan rpi3.cluster

Code

Plain text
% ifconfig
eth0   Link encap:Ethernet HWaddr b8:27:eb:22:60:fb
     inet addr:192.168.50.1 Bcast:192.168.50.255 Mask:255.255.255.0
     UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
     RX packets:2470 errors:0 dropped:0 overruns:0 frame:0
     TX packets:2267 errors:0 dropped:0 overruns:0 carrier:0
     collisions:0 txqueuelen:1000 
     RX bytes:215730 (210.6 KiB) TX bytes:237032 (231.4 KiB)

eth1   Link encap:Ethernet HWaddr ac:29:3a:da:74:37
     inet addr:192.168.1.194 Bcast:192.168.1.255 Mask:255.255.255.0
     UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
     RX packets:15245 errors:0 dropped:1 overruns:0 frame:0
     TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
     collisions:0 txqueuelen:1000 
     RX bytes:1787746 (1.7 MiB) TX bytes:283761 (277.1 KiB)

lo    Link encap:Local Loopback
     inet addr:127.0.0.1 Mask:255.0.0.0
     UP LOOPBACK RUNNING MTU:65536 Metric:1
     RX packets:4 errors:0 dropped:0 overruns:0 frame:0
     TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
     collisions:0 txqueuelen:0 
     RX bytes:260 (260.0 B) TX bytes:260 (260.0 B)

Code

Plain text
% route -n
Kernel IP routing table
Destination   Gateway     Genmask     Flags Metric Ref  Use Iface
0.0.0.0     192.168.1.254  0.0.0.0     UG  0   0    0 eth1
192.168.1.0   0.0.0.0     255.255.255.0  U   0   0    0 eth1
192.168.50.0  0.0.0.0     255.255.255.0  U   0   0    0 eth0

Code

Plain text
% ssh rpi1
Linux rpi2 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

Last login: Sat Sep 5 20:49:07 2015 from rpi0
% ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=54 time=23.8 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=54 time=21.4 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=54 time=23.2 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 21.470/22.838/23.829/1.014 ms
%

Python script

Prints the current IP address to the SainSmart I2C 16×2 LCD panel using the ThinkBowl I2C library

Python script

Prints the current IP address for eth0 and eth1 to the SainSmart I2C 16×2 LCD panel using the ThinkBowl I2C library

ThinkBowl I2C libraries

Library to use the SainSmart I2C 16×2 LCD panel

Credits

Alasdair Allan

Alasdair Allan

3 projects • 32 followers
Scientist, Author, Hacker, Maker, and Journalist.

Comments