ginger technological blog header information panel


Baking a ServerGrid Pi - Adventures with Raspberry Pi's

Published: February 1st 2014

In one of those moments where I have a few hours to spare and an itch to scratch, I decided to build a monitoring system for my physical and virtual web server fleet using my Raspberry Pi. It is always connected at home as my own personal cloud unit, so it made sense to utilise the unit a bit more.

Raspberry Pi units are the ideal experimental system in my opinion due to their low cost, ease of re-installation when you mess something up and their physical diminutive size / power requirements.

Having decided that I needed a central place to "watch" what's happening with my machines, I set about putting together a quick and dirty monitoring system using PHP and MySQL built on top of the extremely useful twitter bootstrap. Twitter's bootstrap is great for fleshing out new ideas and sites as it removes some of the complexity from fluid website construction. Simply put, it allows you to create a site that will display on pretty-much any device you throw at it.

Home Screen, ServerGrid

Pre-requisits

  1. A Raspberry Pi
  2. Some web servers or virtual machines to use as clients for monitoring
  3. Apache2 Web server
  4. PHP5
  5. MySQL
  6. About an hour of your time.

This post assumes you have a little understanding about web servers given that it's a system for monitoring web servers. If you're not entirely comfortable with installing services, there's no better time to learn than when you have a reason for up-skilling.

Building ServerGrid

ServerGrid is available for free to download through my github account. If you're not familiar with github, you can simply download the zip file with all of the system in it.
Either download the files to your Pi directly or copy them from your machine onto your Raspberry Pi.

If you do not already have Apache/PHP/MySQL installed on your Pi, now is the time to install the necessary services that make ServerGrid work. If you have Apache, PHP & MySQL installed you can skip this step and copy the ServerGrid files to your web folder or start to configure Apache to provide a URL and folder mapping.

Install PHP5 / Apache / MySQL

You will need to install PHP5 / Apache Web server and MySQL on your Pi to allow ServerGrid to operate. This can be accomplished using the apt-get system built into your Linux distribution.

# sudo apt-get install mysql-server
# sudo apt-get install php5
# sudo apt-get install php5-curl
# sudo apt-get install php5-mysql

Install your Database

Once you have your services installed you will need to create your storage and control database. There is a MySQL source file stored in the github download ( database/db_construct.sql).

# mysql -uroot -p[YourPassword]
# create database servergrid
# use servergrid
# source /path/to/your/db_construct.sql
# quit

This should have reported it has created your control and storage database. You will need to specify the correct username and password for your MySQL database in your config file ( located in src/core/database/settings.php ). Use your favourite editor to modify these settings.

Punch-through to that Pi!

Wouldn't it be great to be able to access your Pi from anywhere on the planet and see how your servers are doing from your phone or tablet? Yeah, I thought so too... so if you don't already have your home router set up for punching your Pi to the outside world in a DMZ or Port 80 forwarding ( web server port ), now would be a good time to have a look at doing that.
Depending on your equipment, the process varies. For example, using VirginMedia's Superhub you will have to go into the Advanced settings option.

If you decide not to punch a hole to your Pi from the outside world, you can ommit the configuration of the no-ip domain and simply use the IP address of your Raspberry Pi in your browser address bar.

Configure Apache / No-IP domain

Remembering an IP Address can be difficult, which is why the Domain Name Service (DNS) was put together. It translates text we understand into addresses you computer can understand. To make things easier for you to find your Pi you can set up a URL mapping to your Pi using an online free domain service (such as no-ip.com. Once you've chosen your address you can plug it into your Apache configuration as a new virtual host.

Using pico text editor (or one of your own choice) you can add a new virtual host as below into the /etc/apache2/sites-available/default file:

<VirtualHost *:80>
  ServerName servergrid.myChoiceOfNoIPservice.net
  DocumentRoot /home/pi/servergrid
  <Directory />
      Options FollowSymLinks
      AllowOverride None
  </Directory>
  <Directory /home/pi/servergrid/>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>
</VirtualHost>

Once you have saved your Apache configuration you will have to restart your Apache service for the changes to take effect.

# sudo /etc/init.d/apache2 restart

Note: It can take up to 48 hours for the DNS service to replicate this new information across the planet, but it's usually fairly instantaneous with no-ip.com.

Navigate to your new system

You should now be able to get to your system using your web browser and either the IP address of your Raspberry Pi or the domain name you set up with your no-ip service. The default account is:
Username: sysadmin
Password: servergrid

Setting up your clients

The Linux machines you want to monitor need to have PHP5 and PHP-curl packages installed on them in order to launch the data collection. In the same way that you installed your PHP services on your Pi, you can install the services on your web or application servers (if they are not already installed).

# sudo apt-get install php5
# sudo apt-get install php5-curl

Replicate the "Add server / copy client code & create cron job" process for as many machines as you want to monitor.

Freshly baked ServerGrid Pi

Once you have signed-in to your ServerGrid system and generated your client code, you can set up your cron job to send status information back to your Raspberry Pi. Simply by going to your one web location you can now keep an eye on your entire fleet of web servers.

Now that you have your system installed, you can start to customise the software as you choose - perhaps modifying the colour scheme or creating different graphs or tabular output from the information.

Happy hacking!
gingerCoder()



Next Item.. Automated Flash Adverts from a CSV

Previous Item... MySQL Auto Backup Routine