LibreNMS on the Raspberry Pi 2 or 3



LibreNMS is a fork of Observium – per the LibreNMS Github:

“We intend LibreNMS to be a viable project and community that:

  • encourages contribution,
  • focuses on the needs of its users, and
  • offers a welcoming, friendly environment for everyone.”

This project is going to utilize a Rapberry 2, Raspian Jesse Lite, and then proceed with the required packages to set up LibreNMS.

To start, you will need an SD Card – preferrably at a minimum a 32GB Class 10 Micro-SD. Format the Micro-SD with an appropriate tool -SDFormatter works great, and can be downloaded at:

https://www.sdcard.org/downloads/formatter_4/

Format the SD card, and download the Raspian Jesse Lite image to your PC. Once you have the image file downloaded, you will need to write it to the SD card. Within OS X, the process will be within the terminal:

diskutil list
diskutil unmountDisk /dev/disk2
sudo dd if=~/Downloads/2016-05-27-raspberry-jessie-lite.img of=/dev/rdisk2 bs=1m
diskutil eject /dev/disk2

In the above example, we determined which disk we needed to write using the “diskutil list” command, then proceeded to unmount the disk, write the image to the disk, then eject the disk.

At this point, you may remove the SD card, insert it in the Raspberry Pi, and boot.

The default login credentials are pi and raspberry.

After logging in, you will want to run the following command:

sudo raspi-config

Proceed to expand the file system, set up your language (use space to de-select and select), set up your timezone, and default keyboard. You will also want to change your default password. Within the advanced options, you can change the hostname and enable SSH.

Once your configurations have been changed, reboot your Pi.

Assign a static IP if desired, applying your network settings. In the example below, the pi is assigned a static ip in the 172.16.13.0/24 subnet, with a gateway and DNS name server of 172.16.13.250.

sudo nano /etc/network/interfaces

 

librenms_static_ip

 

 

 

 

 

 

Update the file, and save  (control+o to write, control+x to exit).

After saving your settings, reboot the pi, then verify the IP address:

sudo reboot
ifconfig

Now we can install LibreNMS. First we need to update our Pi’s available packages:

sudo apt-get update

Install the database:

sudo apt-get install mariadb-server mariadb-client

It will prompt for a root password for the database, please enter twice and record.

Restart the SQL service:

sudo service mysql restart

Then create the database:

mysql -uroot -p

Enter your database root password, then proceed with the following SQL commands:

CREATE DATABASE librenms;
 GRANT ALL PRIVILEGES ON librenms.*
  TO 'librenms'@'localhost'
  IDENTIFIED BY '<password>'
 ;
 FLUSH PRIVILEGES;
 exit

Now edit the following file:

sudo nano /etc/mysql/my.cnf

Add the follow lines to the mariadb.cnf file under the [mysqld] section:

innodb_file_per_table=1 

Save the file, and restart the SQL service:

service mysql restart

Next install the following packages:

sudo apt-get install libapache2-mod-php5 php5-cli php5-mysql php5-gd php5-snmp php-pear php5-curl snmp graphviz php5-mcrypt php5-json apache2 fping imagemagick whois mtr-tiny nmap python-mysqldb snmpd php-net-ipv4 php-net-ipv6 rrdtool git

No configure a basic SNMP config file – we will move the template and create a new file:

sudo mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.old
sudo nano /etc/snmp/snmpd.conf

Add your new SNMP parameters to the config file (replace with the appropriate info):

rocommunity infosoda
syslocation My Laboratory
syscontact Call the HelpDesk

Save your file, then restart the SNMPD service:

sudo service snmpd restart

Add the librenms user:

sudo useradd librenms -d /opt/librenms -M -r
sudo usermod -a -G librenms www-data

Now change directories and download LibreNMS:

cd /opt
sudo git clone https://github.com/librenms/librenms.git librenms
cd /opt/librenms

Prepare the web interface:

sudo mkdir rrd logs
sudo chown -R librenms:librenms /opt/librenms
sudo chmod 775 rrd

Now we create our conf file for Apache:

sudo nano /etc/apache2/sites-available/librenms.conf

Now add the following to the librenms.conf file, Changing librenms.example.com to the appropriate hostname for your domain:

<VirtualHost *:80>
 DocumentRoot /opt/librenms/html/
 ServerName librenms.example.com
 CustomLog /opt/librenms/logs/access_log combined
 ErrorLog /opt/librenms/logs/error_log
 AllowEncodedSlashes NoDecode
 <Directory "/opt/librenms/html/">
 Require all granted
 AllowOverride All
 Options FollowSymLinks MultiViews
 </Directory>
 </VirtualHost>

Enable mcrypt:

sudo php5enmod mcrypt

Load the website:

sudo a2ensite librenms.conf
sudo a2enmod rewrite
sudo service apache2 restart

Disable the default site setup:

sudo a2dissite 000-default
sudo service apache2 reload

Configure your polling defaults (copy the template to your default config, then modify your subnet and default SNMP community name):

sudo cp config.php.default config.php
sudo nano config.php

Change the values to the right of the equal sign for lines beginning with $config[db_] to match your database information as setup above.

Change the value of $config['snmp']['community'] from public to whatever your read-only SNMP community is. If you have multiple communities, set it to the most common.

Initialize the database:

sudo php build-base.php

Add user in the following format:

sudo php adduser.php <name> <pass> 10 <email>

Validate the install, and correct any errors:

sudo php validate.php 

Add the localhost:

sudo php addhost.php localhost public v2c

Discover the newly added localhost:

php discovery.php -h all

Create the cronjob:

cp librenms.nonroot.cron /etc/cron.d/librenms

At this point, your setup is complete and you should be able to log into the web interface utilizing the credentials created with the adduser.php command. Open your browser and browse to http://yourip

librenms_web_page

 

Observium on the Raspberry Pi 2

Please note – I have also detailed the installation of LibreNMS on the Pi, which is a fork of Observium. Please take a look at my post at:

LibreNMS on the Raspberry Pi 2 or 3

I love Observium, an open source network monitoring platform. I monitor anything and everything with this tool: firewalls, servers, routers, switches, wireless access points, printers… the possibilities are endless. If you are not familiar with Observium, please check out everything you are missing at their site:

http://www.observium.org/

The Raspberry Pi 2 seems to render and handle Observium well in my lab. You will not be disappointed by the beautiful graphs and the constant flow of information that Observium will feed you via the Raspberry Pi 2.

For the installation, I will deviate off the beaten path by using a currently unsupported version of Ubuntu on the Raspberry Pi 2. I am aware that Snappy Core Ubuntu is available, but I did not want to gravitate away from my comfort zone, and elected to go with Ubuntu 14.04LTS Server…

First, I would recommend grabbing a decent Micro-SD card (I used a 32GB class 10), and installing Ubuntu 14.04LTS per:

https://wiki.ubuntu.com/ARM/RaspberryPi

Choose to install OpenSSH-Server during the installation. You will reboot the pi after the installation, and can log in using ubuntu/ubuntu for your username and password. You will first want to set a static IP address on the Pi so you always know how to find it, by editing the following file:

sudo nano /etc/network/interfaces.d

The file should instruct how to configure eth0, the ethernet interface on the Pi. For example:

iface eth0 inet static
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1

Save the config with “control+o” to write the file, and “control+x” to exit the editor.

Now proceed by accessing your Raspberry Pi 2 via SSH (use Putty from Windows) with the static IP you assigned.

ssh ubuntu@192.168.0.10

Install you base packages required for Observium, making sure you document your MySQL password:

apt-get install libapache2-mod-php5 php5-cli php5-mysql php5-gd php5-mcrypt php5-json php-pear snmp fping \ mysql-server mysql-client python-mysqldb rrdtool subversion whois mtr-tiny ipmitool graphviz imagemagick

If you monitor libvert machines, you will need to install the following, if not, please skip:

apt-get install libvirt-bin

Make a directory for Observium, then change directory into /opt:

sudo mkdir -p /opt/observium && cd /opt

I will be working with the community edition of Observium, install it with the following command:

sudo wget http://www.observium.org/observium-community-latest.tar.gz 
sudo tar zxvf observium-community-latest.tar.gz

After downloading, change into the unpackaged Observium directory:

cd observium/

Copy the example php config into your working config:

cp config.php.default config.php

Create the MySQL database:

mysql -u root -p

<you will be prompted to enter your root MySQL password to continue>

mysql> CREATE DATABASE observium DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> GRANT ALL PRIVILEGES ON observium.* TO 'observium'@'localhost'         -> IDENTIFIED BY 'observium_db_password';
mysql> quit

MySQL setup Observium

Now we will need to edit the working config file we copied from the default, updating it with our database password:

sudo nano config.php

You should be updating the “db_user” to observium and your “db_password” to the password configured above when setting up MySQL with the line “IDENTIFIED BY ‘observium_db_password'”

You will see in my attached example I simply used “ubuntu” for my Observium database password. This is also the time and place to update the default SNMP community name. In my attached example I am using the SNMP community name of “infosoda”.

config.php Observium

I used “nano” to edit the file – you will need to use a “control+o” to save and then a “control+x” to exit.

Now update the database with the following php script:

sudo php includes/update/update.php

As long as your updated database password in the config.php file matches your setup password, yo should see the terminal session scroll while updating the database schema.

We need to create the directory “rrd” to store RRD files. We then follow it up by modifying the permissions:

mkdir rrd
sudo chown www-data:www-data rrd

Assuming this is the only site running on Apache on your Raspberry Pi 2, we should edit the Apache config:

sudo nano /etc/apache2/sites-available/000-default.conf

Edit the file (see my attachment – please omit me working around the default comments in the config file):

<VirtualHost *:80>
       ServerAdmin webmaster@localhost
       DocumentRoot /opt/observium/html
       <Directory />
               Options FollowSymLinks
               AllowOverride None
       </Directory>
       <Directory /opt/observium/html/>Options Indexes FollowSymLinks MultiViews
              AllowOverride All
              Require all granted
       </Directory>
       ErrorLog ${APACHE_LOG_DIR}/error.log 
       LogLevel warn 
       CustomLog ${APACHE_LOG_DIR}/access.log combined 
       ServerSignature On 
</VirtualHost>

Apache2 config Observium

We then need to run the mcrypt module:

sudo php5enmod mcrypt

Enable the module rewrite:

sudo a2enmod rewrite

Restart Apache:

sudo service apache2 restart

We now get to add a user in the format ‘user_name’ ‘password’ ‘level’, where a level 10 denotes an administrator:

sudo ./adduser.php admin observium 10

We will then perform an initial discovery:

sudo ./discovery.php -h all

Followed by an initial poll:

sudo ./poller.php -h all

We finally need to set up a CRON job to maintain the discovery and polling:

sudo nano /etc/cron.d/observium

Edit the newly created job to reflect the following:

33  */6   * * *   root    /opt/observium/discovery.php -h all >> /dev/null 2>&1
*/5 *     * * *   root    /opt/observium/discovery.php -h new >> /dev/null 2>&1
*/5 *     * * *   root    /opt/observium/poller-wrapper.py 2 >> /dev/null 2>&1

Please note, this cron job utilizes a username.

Editing /etc/cron.d/observium

To set the correct timezone for your graphs, you will need to edit your php.ini file and set the time on your Raspberry Pi.

The Pi can be set in Ubuntu with the following command in the terminal, which will launch the interface that users usually utilize when they set up their servers:

sudo dpkg-reconfigure tzdata

Edit the php.ini file with your editor:

sudo nano /etc/php5/cli/php.ini

Editting php.ini

 You will need to setup SNMP on all of your hosts and devices, which is beyond the scope of my post, but here is how we add our Raspberry Pi 2 within Ubuntu:

sudo apt-get update
sudo apt-get install snmpd

Move the original snmpd.conf file:

sudo mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.original

Now re-create the snmpd.conf file:

sudo nano /etc/snmp/snmpd.conf

There are only a few variables that are necessary in your new, blank config:

rocommunity         batman
syslocation         Bat Cave
syscontact          Bruce@wayneenterprises.com

Usually you would enter some useful information to help you locate the device on your network.

Relaunch the snmpd service:

sudo service snmpd restart

Now you can monitor your own Observium install…

Simply add it using “localhost” for the hostname and the appropriate SNMP community name. Observium requires DNS names to resolve, and you will want to correctly setup DNS in your environment.

A sample screenshot:

Raspberry Pi in Observium
Observium screenshot