RaspberryPi Cluster

We decided to build a cluster based on Raspberry Pi's. The cluster will be powered from solar/wind energy, and the first job for the cluster will be to monitor its own energy consumption.

So of course that makes the whole thing a play-project, but nevertheless, lets get to it :)

1. Hardware

  • RaspberryPi 3 Model B
  • 3 RaspberryPi 2 Model B
  • D-Link DGS-108 8-port GLAN Switch
  • LogiLink USB2.0 Hub 10 ports

The D-LInk was chosen primarily because of its metal casing. It is sturdy enough to hold the weight of the entire structure.

The frame consist solely of threaded rods (3mm). The aluminium pipe was originally just added as eyecandy, but they eventually saved a lot of nuts! We could have settled with half of the lenght of the threaded rods, but this way, we can easily scale the number of nodes.

There is room for 3 more in the stack at the right. Adding another swicth below the first one and 7 nodes to the left side , will make this a 14 node cluster. (note that two 8-port switches only gives you 14 ports in total, as they need to be connected to eachother as well)

 

2. Pi Configuration

For the first part of this tutorial we will have all boards connected to the 8-port switch, and have the switch connected to our local network. So they will get IP's assigned automatically from the DHCP-server in the router.

As the very first step, we recommend to change the host name of the RP's. This is due to the fact all RP's are born with host name = raspberrypi, so when doing SSH, you might end up sending commands to another RP than expected. So as a super user open the file 'hostname' in your /etc directory and edit the file to fit your needs.

(Hint: You can double-click the line. The $ will be removed)

$
sudo nano /etc/hostname

 

We went with:

  • Master
  • Slave-01
  • Slave-02
  • Slave-03

 

Now we can do SSH to all the RP's and the cluster software would be able to navigate to the RP's. But what happens if we move the cluster to another network? IP's might change and what then? The logic thing to do, is to install a DHCP-server on the master

Step 1 is to make sure that we always know the IP of the master. Using this tutorial we can set up the RP to send an email containing the IP every time it boots. I had to add sleep 60 as the first line of rc.local to get script working on reboot.

For setting up the DHCP-server, we have looked at Alasdair Allans guide to building a cluster. But times are changing, and since Alasdairs guide, the Raspberry Pi Model 3 has arrived, and with it the functionality of WiFi. So we will make use of wlan0 to reach the master from the outside world, and let the DHCP server manage eth0. This enables us to skip a few steps compared to Alasdairs excellent guide.

There is a GUI which allows you to connect to a nearby WiFi, but the command-line method is quite easy. But to keep things seperated you might want to wait with the Wifi-part, until DHCP server and IP-assigning to eth0 is fully configured.

You might run into troubles trying to SSH to your RP over WiFi from a windows pc locally. But from my Ubuntu, there were no issues.

Now lets get to it. Install the DHCP server:

$
sudo apt-get install isc-dhcp-server

 

Then edit the conf-file

$
sudo nano /etc/dhcp/dhcp.conf

 

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 master {
        hardware ethernet b8:27:eb:22:60:fb;
        fixed-address 192.168.50.1;
    }
    host slave-01 {
        hardware ethernet b8:27:eb:a0:a1:7f;
        fixed-address 192.168.50.11;
    }
    host slave-02 {
        hardware ethernet b8:27:eb:68:b6:a3;
        fixed-address 192.168.50.12;
    }
    host slave-03 {
        hardware ethernet b8:27:eb:0b:4e:2c;
        fixed-address 192.168.50.13;
    }
  }
}

Note: If your DHCP server fails to start after doing this configuration, you have most likely made a typo. Be careful :)

This command might help (or start/stop/restart)

sudo service isc-dhcp-server status

 

Next we edit the /etc/default/isc-dhcp-server file. Note that even though we are not using a secondary ethernet like Alasdair, we should still configure the DHCP to service eth0

$
sudo nano /etc/default/isc-dhcp-server

 

DHCPD_CONF=/etc/dhcp/dhcpd.conf
DHCPD_PID=/var/run/dhcpd.pid
INTERFACES="eth0"

 

We should also edit the hosts file of each RP

$
sudo nano /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 master master.local rmaster.lan master.cluster
192.168.50.1 master master.local master.lan master.cluster
192.168.50.11 slave slave-01.local slave-01.lan slave-01.cluster
192.168.50.12 slave slave-02.local slave-02.lan slave-02.cluster
192.168.50.13 slave slave-03.local slave-03.lan slave-03.cluster

 

The /etc/network/interfaces file should be configured like this:

$
sudo nano /etc/network/interfaces

 

auto lo
iface lo inet loopback

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

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

 

Reboot all RP's. By now it should be safe to set up the WiFi-connection and disconnect the 8-port switch from your local network. You can SSH to the IP that your router has assigned to master wlan0, and then you can SSH to the slaves using the IP's assigned from the master (192.168.50.11-13)

But in order to get access to the internet from the slaves, you have to apply this on the master

$
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

 

Edit /etc/sysctl.conf and uncomment:

$
net.ipv4.ip_forward=1

 

Then edit the iptables:

$
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
$
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
$
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
$
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

3. HADOOP

Hadoop guide is comming soon

Add comment


Security code
Refresh