NATS Pi Recipe
Possibly the Smallest NMS in the World
This is a recipe to make what is, possibly, the smallest network monitor (NMS) in the world: a NATS Pi with Raspberry Sauce.
First obtain a Model B Raspberry Pi. I was lucky enough to have mine delivered today.
It's a pretty cool bit of kit with an ARM processor, 256Mb of RAM, HDMI, Ethernet, 2 x USB and an SD card reader. More than powerful enough to run FreeNATS so I thought I'd give it a go.
The steps involved were to install the Debian Squeeze OS on the card, set it up as a LAMP server and then install FreeNATS.
It is possible to buy an SD card with the OS pre-installed but these were out of stock when I ordered.
So I followed the instructions pointed to in the documentation at http://elinux.org/RPi_Easy_SD_Card_Setup to install the Debian OS for it.
To setup LAMP I needed to put on Apache, PHP and MySQL.
Before any of this however I needed to update the system with the following commands:
sudo apt-get update sudo apt-get upgrade
Note I actually had to run apt-get update twice for some reason. It also took quite a while.
The following two commands installed apache2:
sudo groupadd -f -g33 www-data sudo apt-get install apache2
Originally these failed but then I went back and did the update/upgrade step and all was well.
To install PHP5 as a CLI and Apache module took the following apt-get with the next commands to ensure www-data could read the web directory:
sudo apt-get install php5 libapache2-mod-php5 sudo chown root:www-data /var/www sudo chmod 775 /var/www
MySQL was the easiest of them all. One command and the setup even prompted to set a root password:
sudo apt-get install mysql-server
Now I rebooted just to make sure everything was nice and shipshape. I probably didn't need to but the boot time is very quick thanks to small OS and SD install. I also at this point dropped out of X as I was using it to just run a single terminal so a command line would do the job just as well.
To ensure PHP has all the necessary modules for FreeNATS:
sudo apt-get install php5-mysql sudo apt-get install php5-imap sudo apt-get install php5-gd sudo service apache2 restart
Next to setup a MySQL database for FreeNATS and a user with the following commands, XXXX being the MySQL root password set during install:
mysql -u root -pXXXX create database freenats; grant all privileges on freenats.* to 'freenats'@'localhost' identified by 'freenats';
For simplicity I decided just to install FreeNATS directly to the web directory so I would access with the URI freenats/server/web/
I switched to root user (sudo su) to avoid sudo'ing all the time which is bad practice but I was feeling reckless. Again XXXX is the MySQL root password.
cd /var/www sudo su wget http://www.purplepixie.org/freenats/downloads/freenats-1.14.0a.tar.gz tar -xvzf freenats-1.14.0a.tar.gz mv freenats-1.14.0a freenats cd freenats/server/base/sql mysql -u root -pXXXX freenats < schema.sql mysql -u root -pXXXX freenats < default.sql cd ..
Now to edit the config.inc.php file to update the database connection for the correct credentials (server localhost, user freenats, password freenats, database freenats):
Finally setup the CRON job:
cd /etc mkdir cron.minute cd cron.minute pico freenats-tester
Put the following into the freenats-tester script:
#!/bin/sh cd /var/www/freenats/server/bin ./test-threaded.sh 2>&1 > /dev/null
Make it executable:
chmod 755 freenats-tester
Edit the crontab:
And add the following line:
* * * * * root run-parts /etc/cron.minute
Then restart cron to ensure changes have taken effect:
service cron restart
One installed NMS on a system no bigger than the credit card with which I purchased it.
Most of the LAMP setup stuff was sourced from http://chris-potter.co.uk/2012/05/raspberry-web-server-lamp-stack/ and http://www.raspberrypi.org/phpBB3/viewtopic.php?f=31&t=6294