Adding Java to the Development Environment

Now we have LAMP and Python installed its time to start adding some more of the programming languages we are going to use, first step is Java because it opens up a range of additional languages such as Groovy, Scala, Closure along with Java versions of Python ( JPython ) and Ruby ( JRuby )

The version of Java we will use is Open JDK. There are 2 components to install Java, the Java Runtime Environment ( JRE ), which is used by Java based applications that we will install later such as Tomcat; and the Java Development Kit ( JDK ) which contains the programming environment, libraries and compilers necessary to write, compile, debug and execute Java code.

sudo apt-get install openjdk-7-jre
sudo apt-get install openjdk-7-jdk

You can check its all installed by checking the version

java -version

should return the following

java version "1.7.0_07"
OpenJDK Runtime Environment (IcedTea7 2.3.2) (7u7-2.3.2a-1+rpi1)
OpenJDK Zero VM (build 22.0-b10, mixed mode)

Once we have Java installed we will then add Tomcat, an open source software implementation of the Java Servlet and JavaServer Pages technologies

sudo apt-get install tomcat6
sudo apt-get install tomcat6-docs
sudo apt-get install tomcat6-examples
sudo apt-get install tomcat6-admin

Tomcat starts on port 8080 so to make sure its working point a browser to http://:8080 and you should see something similar to the following

Creating a Basic Development Environment

To allow us to use our super computer as a via development environment we need to install some essential software and then we can begin installing the languages and supporting tools.

Underpinning all the installs we are about to do is ‘build-essential’. The build-essential is a reference for all the packages needed to compile a debian package. It generally includes the gcc/g++ compilers an libraries and some other utils

sudo apt-get install build-essential

Now we have the core tools lets install the 2 most common version control systems, subversion and git

sudo apt-get install subversion
sudo apt-get install git-core

As Python is the defacto language on the Pi lets install some python package management tools. This section is scraped from SaltyCrane Blog

Pip is a tool for installing and managing python packages

sudo apt-get install python-pip python-dev 
sudo pip install --upgrade pip

Next we are going to turn out Pi into a LAMP Server. LAMP stands for Linux, Apache, MySQL and PHP, a common framework for web development

This section was helped from Chris Potters Blog

Note, that during the below Lamp install you will be asked for certain information, specifically userid/password for MySQL and some supporting tools. The installers typically run their own application to configure.

First we install Apache, our web server

sudo apt-get install apache2

You can now test that Apache is installed correctly by opening your browser and entering the url http:// where is the name of the server you are installing into, this should show the following screen

Next we install PHP which is one of the easiest languages to write dynamic web pages

sudo apt-get install php5 libapache2-mod-php5

We can now check that PHP is installed correctly. First create a file in /var/www called info.php and include the following information

Open a browser and then open the url http:///info.php, again where server name is the name of the server you are installing on. You should get the following screen

Next we add MySQL a relational database that integrates well with Apache and PHP

sudo apt-get install mysql-server

Now we hook up Apache, PHP and MySQL by installing the PHP libraries for Apache and the libraries that allow you to make SQL calls to MySQL from PHP code

sudo apt-get install libapache2-mod-auth-mysql php5-mysql

And then we add in PHPMyAdmin a great web based tool for managing your MySQL databases which integrates with Apache

sudo apt-get install phpmyadmin

We can check that PHPMyAdmin is installed by loading it up into our browser. Enter the url http:///phpmyadmin and the following screen should be displayed

Login and you should see

Finally we can add some additional PHP libraries which are useful including PEAR which is a PHP package manager

sudo apt-get install php5-cli php5-common php5-curl php5-dev php-pear

Thats it, you have a decent LAMP server that you can write applications in Python and PHP, create websites and hook them up to a back end database, cool or what ?

Connecting via hostnames

One of the problems with IP addresses is they are hard to reconcile to the machine they relate to. Its always much easier to talk about pimaster or pislave1 than or If you have a crappy DHCP server like I have with the BT Home Hub, then the easier way around this is to modify the hosts file on each of the machines, which is used by the OS to lookup the mapping between hostname and ip before it goes off to name servers.

sudo vi /etc/hosts

and you’ll see something like this

Add lines ( highlighted in blue ) for each device in your network

I’ve replaced the name for with pislave1, the name of the device I am logged into, and then added the ip addresses for pimaster, pislave1-4 and readynas

Repeat this for each machine, machine sure you change the name for the device to the actual name of the device you are logged into

It lives !!!!!!!!!!!!!!!!!!!

It finally works, all the cards are formatted and the devices networked, I now have a 5 node Super Computer just itching for world domination.

Below you can see PiSlaves1-4 and PiMaster sat on top, connected through their own 100Mbs hub to my main 1GB hub

And there are all 5 machines opened at the terminal

Its time to create dastardly deeds with all this computing power now


Mounting an NFS Folder

Most of this info was pulled from the website Peter Mount’s Blog

First we need to tell NFS to use statd, to do this

sudo /etc/init.d/rpcbind start 
sudo vi /etc/default/nfs-common
add the line "NEED_STATD=yes"
reboot PI or /etc/init.d/nfs-common restart

Next we need to create a local folder that will be the mount point of the remount NFS folder. In this instance I have a folder called ‘raspberry’ on my Netgear RasdyNAS NV+ device

sudo mkdir -p /nas/raspberry
sudo chmod 777 /nas/raspberry

Now we can mount the remote folder to local folder

sudo mount /nas/raspberry

Change the IP address to whatever you NFS server has.

If you subsequently want to remove the remote folder, or unmount it, then using the following command

sudo umount /nas/raspberry

If you want the mount to be available everytime you boot the pi, then you need an entry in /etc/fstab

sudo vi /etc/fstab

And add the following entry at the end of the file: /nas/raspberry nfs defaults 0 0

Thats it. The next time you reboot the pi it will automatically mount that drive.

Duplicating an SD Card Image

Once we have created an SD Card image of our base system, updated the OS and configured for SSH access we don’t want to have to do this over and over again, so this section will show you how to make a copy of your original SD Card and then burn it onto all the others

Without plugging in your SD card, from the command line run the command df


Filesystem                        512-blocks       Used Available Capacity  iused     ifree %iused  Mounted on
/dev/disk1                        1247961912  377253544 870196368    31% 47220691 108774546   30%   /
devfs                                    378        378         0   100%      656         0  100%   /dev
map -hosts                                 0          0         0   100%        0         0  100%   /net
map auto_home                              0          0         0   100%        0         0  100%   /home
localhost:/FubuLodeAG-ddMZnEma0co 1247961912 1247961912         0   100%        0         0  100%   /Volumes/MobileBackups

Then insert the card, wait for it to appear on your desktop and then df it again. You will notice the only difference is the new line with your card name on it


Filesystem                        512-blocks       Used Available Capacity  iused     ifree %iused  Mounted on
/dev/disk1                        1247961912  377253544 870196368    31% 47220691 108774546   30%   /
devfs                                    378        378         0   100%      656         0  100%   /dev
map -hosts                                 0          0         0   100%        0         0  100%   /net
map auto_home                              0          0         0   100%        0         0  100%   /home
localhost:/FubuLodeAG-ddMZnEma0co 1247961912 1247961912         0   100%        0         0  100%   /Volumes/MobileBackups
/dev/disk2s1                          114576      68000     46576    60%      512         0  100%   /Volumes/Untitled

In this instance my card has been mounted as /dev/disk2s1 and its the number 2 that we are interested in so remember it.

To be able to copy the image we first need to unmount it with the unmount command

sudo diskutil unmount /dev/disk2s1

You will notice the card disappears from your desktop

Next we want to make a copy of the image using the dd command

sudo dd bs=1m if=/dev/rdisk2 of=RPi.img

And finally eject the SD card so we can insert another one and copy the new image to that

sudo diskutil eject /dev/rdisk2

Once one card is done you can repeat this for every card for the super computer. As each card is done, you can boot them individually and change the static ip and hostname using the information documented in Setup Stage 2 – Network Configuration

Setup Stage 4 – Updating the system

Now we can login without a password using SSH and our secure keys

Working behind a proxy

If you are behind a proxy server, then you need to follow the following instructions. If you are not behind a proxy server, or don’t know what one is then just to the next section Updating your system

Its a bit of a catch 22 now, before we explore updating the system with apt-get we need to set it up to access files on the internet from behind a proxy.

The proxy configuration is stored in the a folder at /etc/apt/apt.conf.d/. Change to this folder and the create a blank file called ’10proxy’ using the commands as they are below

Enter the following details into the empty file, substituting the IP address and port below with the details of you own proxy server and port.

Save the file by pressing esc and the enter !wq

Updating your system

To update our system using the command ‘apt-get’. Enter the following command and the system will chunter away from a while updating the base system with anythiing that has changed since it was installed,

Next enter the following command to install a better editor than ‘vi’, this again will chunter away and install an editor called ‘vim’

sudo apt-get install vim

Once Vim is installed we can edit some of the basic configuration files when we login.

cd ~
vim .bashrc

This will load the file .bashrc into vim, its quite a large file so we don’t display it here, but scroll down until you find the following

Remove the # from the beginning of the lines which contain the command ‘alias’ so it looks like this

If you are not behind a proxy you can skip this section and you are done, otherwise, scroll down to the bottom and enter the following line

export http_proxy=""

Substituting the IP address and port below with the details of you own proxy server and port making sure its the same IP and port you used above when configuring the proxy settings for apt-get, so that it looks something like this

You are now done, press esc and the enter !wq to save the file and exit, and thats it, we are ready to start installing all manner of magic software needed by a super computer

Setup Stage 3 – Configuring SSH

If you don’t know what SSH is or what it can do for you, check out the the articles Secure Shell on Wikipedia

Before we begin check out the blog entry Generating an SSH key pair

As we start to build our super computer we don’t want to have to access each of the PI’s by connecting them to separate screens, keyboards and mice. Instead we’ll connect them only to the network and access all of the Pi’s from a computer using SSH and so we don’t need to enter a password everytime we log in, we’ll use secure keys to take care of this.

To make sure everything is working, first SSH into your pi with the following command, substituting the name keith for the name you used.

ssh keith@raspberrypi

Enter the password you set for the user, and this should log you into a terminal on the remote raspberry pi. It should look something like this

When you are happy you are logged in, exit back to you computer by just typing ‘exit’

Next we need to create a pair of keys, this is done by entering the command ‘ssh-keygen’ as below and follow the prompts for entering the pass phrase which secures the keys

Keys come in a pair, a public and private part. We give the public part to any system we want to connect to and keep the private part secret to ourselves.

They keys are stored in a folder called ‘.ssh’, you can see them by entering the command ‘ls .ssh’ as below

Once we are happy the keys have been generated we need to copy the public key to the system we want to connect to. This is done using the scp command as follows

scp .ssh/ keith@raspberrypi:~

Once this is done, ssh again into the raspberry pi using the same commands as above

ssh keith@raspberrypi
mkdir .ssh
cat >> .ssh/authorized_keys

You can now SSH again into the raspberry, but this time it won’t ask you for the password as it uses your key instead

ssh keith@raspberrypi

Most of this information was taken from the following website How to use RSA Key for SSH Authentication

Setup Stage 2 – Network Configuration

Now that you have an SD configure with the base system, we need to configure the network so that we have a static ip address and unique name for each pi.

When the pi boots by default it will grab a dynamic ip address via dhcp and have the default hostname of raspberrypi, but we are going to have 5 Pi’s on our network so each needs its own name, plus we want to ensure that each Pi always boots with the same ip address.

First we edit the network configuration file

sudo vi /etc/network/interfaces

Which will look something like this

auto lo

iface lo inet loopback
iface eth0 inet dhcp

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

The network card is called eth0, and we need to change it from dhcp to static ip address. Edit the file, so it looks like use. You can use whatever ip address that works for your network. For this super computer I am going to use – for the Pi’s

auto lo

iface lo inet loopback
iface eth0 inet static

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

We will set the other 4 Pi’s as do the individual per Pi configuration later

Next we need to edit the hostname file so that each Pi has a unique name

sudo vi /etc/hostname

Replace raspberrypi with unique name, for the first device I’ll use pislave1, and the configure 3 as pislave2, pislave3 and pislave4 and also have a pilaster which will control the 4 slaves


Setup Stage 1 – Create a new user

So we’ve burnt an SD card, and installed our base operating system, we’ve booted the card and configured the base operating and rebooted it and logged in with out ‘pi’ user. Now its time to create a user, and install the base tools including updating the operating system

After you have logged in, its best to create a user other than pi that will do all the work, as pi is the default user and its nice to have a user that is you 😉

We create a user using the ‘adduser’ command. Enter the following command and you’ll see the system respond with something similar. Everytime ‘adduser’ asks you a question you can just press enter as the default answer is always fine at this stage

pi@raspberrypi ~ $ sudo adduser keith
Adding user `keith' ...
Adding new group `keith' (1002) ...
Adding new user `keith' (1002) with group `keith' ...
Creating home directory `/home/keith' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for keith
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
pi@raspberrypi ~ $

So we now have a user created. To allow this user to be able to modify the system we have to give this user super user privileges, and this is a 2 stage process

The first stage is to use the ‘visudo’ command which brings up the file containing the list of all users with ‘su’ or super user priviledges.

pi@raspberrypi ~ $ sudo visudo

This will bring up the following screen

Underneath the line pi = ALL(ALL) NOPASSWD: ALL, enter a new line using the user you created above, the line should read keith = ALL=(ALL) ALL, and the result should look like this

To save and exit, type Ctrl-O remove the .tmp extension from the file, hit enter and the hit Ctrl-X to exit.

The next stage is to complete adding the user to su privs, enter the following command

pi@raspberrypi ~ $ sudo adduser keith sudo