(Last Updated On: August 3, 2018)

LibreNMS is a community-based GPL-licensed auto-discovering network monitoring tool based on PHP, MySQL, and SNMP. LibreNMS includes support for a wide range of network hardware and operating systems including Juniper, Cisco, Linux, Foundry, FreeBSD, Brocade, HP, Windows and many more. It is a fork of “Observium” monitoring tool.

In this guide, we will cover the installation and configuration of LibreNMS on Ubuntu 18.04 LTS server, codenamed Bionic Beaver. We have other monitoring tutorials around Cacti, Zabbix, Grafana, Prometheus, and InfluxDB.

Features of LibreNMS

Below are the top features of LibreNMS networking monitoring tool

  • Has Automatic discovery – It will automatically discover your entire network using CDP, FDP, LLDP, OSPF, BGP, SNMP, and ARP
  • API Access – LibreNMS provides a full API to manage, graph and retrieve data from your install.
  • Automatic Updates – With LibreNMS you get to stay upto date automatically with new features and bug fixes.
  • Customisable alerting – Highly flexible alerting system, notify via email, irc, slack and more.
  • Support for Distributed Polling through horizontal scaling which grows with your network
  • Billing system – Easily generate bandwidth bills for ports on your network based on usage or transfer.
  • Android and iOS application – There is a native iPhone/Android App is available which provides core functionality.
  • Multiple authentication methods: MySQL, HTTP, LDAP, Radius, Active Directory
  • Integration support for NfSen, collectd, SmokePing, RANCID, Oxidized

How to Install and Configure LibreNMS on Ubuntu 18.04 – Pre-requisites

Below are requirements for running LibreNMS on Ubuntu 18.04:

  • Database Server – We will use MariaDB
  • PHP
  • Web Server – We will use Nginx

Step 1: Install LEMP stack (MariaDB, Nginx, and PHP)

Follow the guide below to install MariaDB on your Ubuntu 18.04 system:

Install MariaDB 10.3 on Ubuntu 18.04 and CentOS 7

LibreNMS is not fully compatible with MySQL strict mode, for now, please disable this after mysql is installed.

sudo vim /etc/mysql/mariadb.cnf

Within the [mysqld] section please add:

innodb_file_per_table=1
sql-mode=""
lower_case_table_names=0

Then restart mysql

sudo systemctl restart mysql

Once database server has been installed and configured, you need to create a database for LibreNMS.

create database librenms;
grant all privileges on librenms.* to [email protected] IDENTIFIED by "StrongPassword";
flush privileges;
quit

Ubuntu 18.04 has PHP 7.2 in its repositories. Install it by running the commands below on your terminal:

sudo apt-get -y install wget php php-pear php-cgi php-common php-curl \
php-mbstring php-gd php-mysql php-gettext php-bcmath \
php-imap php-json php-xml php-snmp php-fpm php-zip

To confirm the php version installed, use the command php -v

# php -v
PHP 7.2.8 (cli) (built: Jul 17 2018 09:50:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Configure and Start PHP-FPM

Ensure date.timezone is set in php.ini to your preferred time zone:

Edit both files:

sudo vim /etc/php/7.2/fpm/php.ini
sudo vim /etc/php/7.2/cli/php.ini

Change date.timezone under [Date] section:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Africa/Nairobi

Restart php fpm:

sudo systemctl restart php7.2-fpm.service

For this setup, we will use Nginx as a web server for LibreNMS, install it by running:

$ sudo apt-get install nginx

Step 2: Download and Install LibreNMS

We will download and install LibreNMS in this step. If you don’t have git, first install it:

$ sudo apt-get install git

LibreNMS will run under its own user called librenms which we need to add:

$ sudo useradd -r -M -d /opt/librenms librenms
$ getent passwd librenms
librenms:x:997:996::/opt/librenms:/bin/sh

Add this user to web user group www-data

sudo usermod -a -G librenms www-data

When done. proceed to install packages required by LibreNMS

sudo apt-get update
sudo apt install rrdtool whois fping imagemagick graphviz  mtr-tiny \
nmap python-mysqldb snmp snmpd python-memcache mtr-tiny acl

Clone LibreNMS source code from github:

$ git clone https://github.com/librenms/librenms.git librenms
Cloning into 'librenms'...
remote: Counting objects: 130428, done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 130428 (delta 10), reused 10 (delta 4), pack-reused 130396
Receiving objects: 100% (130428/130428), 128.54 MiB | 19.52 MiB/s, done.
Resolving deltas: 100% (88754/88754), done.
Checking out files: 100% (8476/8476), done.

Move the folder librenms to /opt

sudo mv librenms/ /opt/

Change permission of the directory:

sudo chown -R librenms:librenms /opt/librenms/
sudo chmod -R 775 /opt/librenms/

Configure snmpd

sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
sudo vim /etc/snmp/snmpd.conf

Edit the text which says RANDOMSTRINGGOESHERE and set your own community string.

curl -o distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x distro
sudo mv distro  /usr/bin/distro

Restart snmpd

sudo systemctl restart snmpd

Create LibreNMS Cron job

Run the command below to set cron job:

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

Copy logrotate config

LibreNMS keeps logs in /opt/librenms/logs. Over time these can become large and be rotated out. To rotate out the old logs you can use the provided logrotate config file:

sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms

Fix LibreNMS Permissions

Finally, fix all permissions

sudo chown -R librenms:librenms /opt/librenms
sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
sudo setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/

Step 2: Configure Nginx

Let’s create the VirtualHost definition for Nginx to be used by LibreNMS.

$ sudo vim /etc/nginx/conf.d/librenms.conf

server {
 listen      80;
 server_name librenms.example.com;
 root        /opt/librenms/html;
 index       index.php;

 charset utf-8;
 gzip on;
 gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
 location / {
  try_files $uri $uri/ /index.php?$query_string;
 }
 location /api/v0 {
  try_files $uri $uri/ /api_v0.php?$query_string;
 }
 location ~ \.php {
  include fastcgi.conf;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
 }
 location ~ /\.ht {
  deny all;
 }
}

Check syntax:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

if all is okay, restart nginx:

$ sudo systemctl restart nginx

Step 3: Configure LibreNMS on Web UI

Run composer install:

cd /opt/librenms
./scripts/composer_wrapper.php install --no-dev

Now open your web browser and start the installer:

http://librenms.example.com/install.php

Proceed to configure database connection, and add an admin user.

The web installer might prompt you to create a config.php file in your librenms install location manually, copying the content displayed on-screen to the file.

sudo vim /opt/librenms/config.php

If you have to do this, please remember to set the permissions on config.php after you copied the on-screen contents to the file. Run:

sudo chown librenms:librenms /opt/librenms/config.php

You have a ready LibreNMS Monitoring tool, validate the installation by clicking  “validate your install and fix any issues” link or using:

# cd /opt/librenms
# ./validate.php
====================================
Component | Version
--------- | -------
LibreNMS  | 1.42
DB Schema | 257
PHP       | 7.2.7-0ubuntu0.18.04.2
MySQL     | 10.3.8-MariaDB-1:10.3.8+maria~bionic-log
RRDTool   | 1.7.0
SNMP      | NET-SNMP 5.7.3
====================================

[OK]    Composer Version: 1.6.5
[OK]    Dependencies up-to-date.
[OK]    Database connection successful
[OK]    Database schema correct
[WARN]  You have not added any devices yet.
	[FIX] You can add a device in the webui or with ./addhost.php
[WARN]  Your local git contains modified files, this could prevent automatic updates.
	[FIX] You can fix this with ./scripts/github-remove
	Modified Files:
	 rrd/.gitignore

Login to LibreNMS Admin portal and start configuring your Network Monitoring

Further readin:

How to Install and Configure Cacti on Ubuntu 18.04

Install Zabbix Server on Ubuntu 18.04