You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

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 20.04/18.04 LTS server, codenamed Bionic Beaver. We have other monitoring tutorials around Cacti, Zabbix, Grafana, Prometheus, and InfluxDB.

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

Below are requirements for running LibreNMS on Ubuntu

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

Step 1: Install PHP and required modules

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

sudo apt update
sudo apt -y install wget php php-{pear,cgi,common,curl,mbstring,gd,mysql,bcmath,imap,json,xml,snmp,fpm,zip}

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

# Ubuntu 20.04
$ php -v
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

# Ubuntu 18.04
$  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/*/fpm/php.ini
sudo vim /etc/php/*/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 php*-fpm.service

Step 2: Install Nginx Web Server

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

sudo apt remove apache2 -y
sudo apt -y install nginx

Ensure it is enabled to start on boot:

sudo systemctl enable nginx

Step 3: Install and configure MariaDB

Install MariaDB Server:

sudo apt install mariadb-server

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

sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf

Within the [mysqld] section please add:

[mysqld]
innodb_file_per_table=1
sql-mode=""
lower_case_table_names=0

Then restart mysql

sudo systemctl restart mariadb

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

$ sudo mysql -u root
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
FLUSH PRIVILEGES;
exit

Step 4: Download and Install LibreNMS

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

sudo apt install git -y

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

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 update
sudo apt install rrdtool whois fping imagemagick graphviz  mtr-tiny nmap python3 python3-pip python3-mysqldb snmp snmpd python3-memcache mtr-tiny composer acl unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd -y

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/

Configure snmpd

Copy configuration template:

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.

$ sudo vim /etc/snmp/snmpd.conf
com2sec readonly  default         LibreStr0ngSecret

Next download distro:

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

Configure PHP-FPM

Copy default PHP-FPM www.conf file

sudo cp /etc/php/*/fpm/pool.d/www.conf /etc/php/*/fpm/pool.d/librenms.conf

Open the file for editing:

sudo vim /etc/php/*/fpm/pool.d/librenms.conf

Change [www] to [librenms]:

[librenms]

Change user and group to “librenms”:

user = librenms
group = librenms

Change listen to a unique name:

listen = /run/php-fpm-librenms.sock

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/

Run composer install:

sudo su - librenms
./scripts/composer_wrapper.php install --no-dev
exit

Enable lnms command completion:

sudo ln -s /opt/librenms/lnms /usr/bin/lnms
sudo cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/

Step 2: Configure Nginx

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

Create a new file:

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

Add and modify below data:

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 ~ [^/]\.php(/|$) {
  fastcgi_pass unix:/run/php-fpm-librenms.sock;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi.conf;
 }
 location ~ /\.(?!well-known).* {
  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 rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx

#Ubuntu 20.04
sudo systemctl restart php7.4-fpm.service

#Ubuntu 18.04
sudo systemctl restart php7.2-fpm.service

Step 5: Configure LibreNMS on Web UI

Now open your web browser and start the installer:

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

Confirm that the pre-install checks is successful.

Install LibreNMS Ubuntu 01

Input database connection details.

Install LibreNMS Ubuntu 02

Check provided credentials and build the database.

Install LibreNMS Ubuntu 03

Database credentials check and build processes should both be successful.

Install LibreNMS Ubuntu 04

Create the first LibreNMS admin user.

Install LibreNMS Ubuntu 05

Username should be shown on the screen.

Install LibreNMS Ubuntu 06

Validate your LibreNMS installation on Ubuntu:

Install LibreNMS Ubuntu 07

Login to LibreNMS Admin portal and start configuring your Network Monitoring

Install LibreNMS Ubuntu 08

Further reading:

How to Install and Configure Cacti on Ubuntu

Install Zabbix Server on Ubuntu 18.04

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

LEAVE A REPLY

Please enter your comment!
Please enter your name here