vHersey

My Raspberry Pi Setup

Since today is Pi Day (3/14) here is a quick write up of how I set up my small, self contained, Raspberry Pi cluster. The build consists of two Raspberry Pi 2 Model B‘s and a Trendnet Gigabit switch, all powered by a Anker 5-port USB charger.

myrasppi

Initial Setup
The Raspberry Pis I have came with an 8GB SD card pre-loaded with the NOOBS distro, I had some 16GB SD Cards which I loaded with the latest Raspbian which can be found here https://www.raspberrypi.org/downloads/raspbian/. Instruction on creating the SD card can be found here https://www.raspberrypi.org/documentation/installation/installing-images/windows.md.

After booted I locate the Raspberry Pi on the network, using the DHCP clients table on my router, and ssh to it. From here I expand the Filesystem to use the full SD card and change the password for the pi user using the Raspberry Pi Software Configuration Tool.

The Raspberry Pi Software Configuration Tool is run using the following command sudo raspi-conf
raspiconfigtool

Setting a Static IP Address and Hostname
By default the Raspberry Pi is configured to receive a DHCP address. To set a static IP address on eth0 edit /etc/dhcpcd.conf using sudo vi /etc/dhcpcd.conf and add the following lines:

interface eth0
static ip_address=192.168.1.180/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.150 192.168.1.1

The default host name is set to raspberrypi, to change this edit /etc/hosts with sudo vi /etc/hosts and make the following changes (the line 127.0.1.1 will be configured with the default hostname, change it to the new hostname and add a line with the static IP address and hostname information):

127.0.1.1       rpi0
192.168.1.180   rpi0 rpi0.lab.local
192.168.1.180   rpi1 rpi1.lab.local

I also add the IP Address and host name of the other Raspberry Pi to the /etc/hosts file. The /etc/hosts file shown above is for rpi0.

Edit /etc/hostname using sudo vi /etc/hostname and replace the default hostname with the new hostname. Then run sudo /etc/init.d/hostname.sh and reboot the Pi with sudo reboot.

Once the Pi reboots it can be accessed using the static IP address and the new hostname is displayed in the prompt.

Now I make sure the packages are up-to-date by running sudo apt-get update followed by sudo apt-get upgrade

Shared Storage
I have a NFS share on my Synology which can be accessed by the Raspberry Pis. I store all the different scripts and projects here so they are available to new Pis I add. I created the share on the Synology and configure the NFS Permissions to allow the Raspberry Pi IP Addresses to access the share.
rpi-nfs-share

The NFS share is configured to automount using autofs when it is accessed. To do this first install the autofs and nfs-common packages using sudo apt-get install autofs nfs-common

I then create a mount point /mnt/nfs with sudo mkdir /mnt/nfs

Then I edit the /etc/auto.master file sudo vi /etc/auto.master and I add the following line:

/mnt/nfs /etc/auto.nfs

Then I create the file /etc/auto.nfs with sudo vi /etc/auto.nfs and add the following line:

synology -fstype=nfs,rw,async,vers=3    192.168.1.250:/volume1/rpinfs

Restart the autofs services using sudo /etc/init.d/autofs restart and when I change directory to /mnt/nfs/synology the NFS share is automatically mounted.
mount-rpi-nfs

Power and Network Connectivity
The Trendnet TEG-S80g switch needs 5 volts DC for power. I cut up the power supply and a USB cable to power the switch using the Anker USB charger. The USB cable has a red wire which provides +5 volts DC and a black wire for ground. The other wires are not used. I tested this as shown in the image below and then soldered everything together and used electrical tape to make it pretty.
switch-power

USB to Micro USB cables are connected between the USB charger and the Raspberry Pis to provide power. Each Raspberry Pi has an Ethernet connection to the 8-port switch and there is a single uplink from the switch into my lab network. So the whole build requires 1 x 1 GbE northbound network connection and 1 x 110 volt AC power plug on a surge protector. There is enough room on the switch and enough power to add a few more Raspberry Pis in the future.

Parts List
I put this together mostly using some stuff I had laying around, like the switch and the USB charger, but here is a parts list with links to everything on Amazon.

Quantity Description and Amazon Link
2 Raspberry Pi 2 Model B
1 Trendnet 8 port 1 GbE un-managed “green” switch (TEG-S80g)

8 x 1 GbE RJ45 ports for network connectivity which only needs 5 volts DC.
1 Anker 5-port USB Charger

Provides power to the Raspberry Pis and the Trendnet switch.
1 4-layer Clear Case Box Enclosure For Raspberry Pi 2

Optional but helps keep everything in a neat. Will support up to 4 Pis.
3 USB to Micro USB cables to power the Raspberry Pis and the Trendnet switch. The one to power the Trendnet switch is butchered as described above to provide 5 volts DC to the switch.
3 Cat 5e or Cat6 Ethernet Cables. One for each Raspberry Pi and one for the uplink from the Trendnet switch to where ever.

Happy Pi Day!

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

five × 4 =