LibreNMS – A Fully Featured Network Monitoring Tool for Linux

LibreNMS is an open source, powerful and feature-rich auto-discovering PHP based network monitoring system which uses the SNMP protocol. It supports a broad range of operating systems including Linux, FreeBSD, as well as network devices including Cisco, Juniper, Brocade, Foundry, HP and many more.

LibreNMS Features:

  1. It auto-discovers a whole network using these protocols: CDP, FDP, LLDP, OSPF, BGP, SNMP and ARP.
  2. It has a mobile friendly Web UI, with customizable dashboards.
  3. Supports a Unix agent.
  4. Supports horizontal scaling to expand with your network.
  5. Supports a highly flexible and customizable alerting system; sends notifications through email, irc, slack and more.
  6. Supports an API for managing, graphing and retrieving data from your system.
  7. Offers a traffic billing system.
  8. Also supports an Android and iOS apps which offer core functionalities.
  9. Supports integration with NfSen, collectd, SmokePing, RANCID and Oxidized.
  10. Supports multiple authentication methods such as MySQL, HTTP, LDAP, Radius and Active Directory.
  11. Allows for auto updating and many other features.

An online demo is available for you to try before installing LibreNMS on Linux systems.

Demo URL: https://demo.librenms.org/
Username: demo
Password: demo

Test Environment:

  1. Ubuntu 16.04 with LEMP Stack
  2. CentOS 7 with LEMP Stack

In this tutorial we will learn how to install LibreNMS Network Monitoring Tool on a freshly installed Ubuntu or CentOS Linux (same instructions also works on Debian and RHEL based distributions).

NOTE: All these instructions in this article should be run as the root user, if you are not, use the sudo command to gain root user privileges.

Step 1: Install Required Packages

1. First start by installing all the required packages using the default package manager as shown.

On Ubuntu/Debian

$ sudo apt install composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.0-cli php7.0-curl php7.0-fpm php7.0-gd php7.0-mcrypt php7.0-mysql php7.0-snmp php7.0-xml php7.0-zip python-memcache python-mysqldb rrdtool snmp snmpd whois

On CentOS/RHEL

# yum install epel-release
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# yum install composer cronie fping git ImageMagick jwhois mariadb mariadb-server mtr MySQL-python net-snmp net-snmp-utils nginx nmap php72w php72w-cli php72w-common php72w-curl php72w-fpm php72w-gd php72w-mysql php72w-process php72w-snmp php72w-xml php72w-zip python-memcached rrdtool

2. Once all the packages are installed, nginx, php-fpm, mariadb and snmp services will be started and enabled to auto-start at boot time (this is normally the case with Ubuntu), otherwise, you can run the commands below to start and enable them.

------------ On Debian/Ubuntu ------------ 
$ sudo systemctl nginx start php7.0-fpm mysql snmp 
$ sudo systemctl enable nginx php7.0-fpm mysql snmp

------------ On CentOS/RHEL ------------ 
# systemctl nginx start php-fpm mariadb snmpd 
# systemctl enable nginx php-fpm mariadb snmpd

Step 2: Install LibreNMS Monitoring Tool

3. Next, create a system user called librenms, with the useradd command; where the -M flag disables creation of user’s home directory, and -r enables creating of a system account. Then add the librenms user to the group www-data (on Ubuntu) or nginx (on CentOS) as follows.

------------ On Debian/Ubuntu ------------ 
$ sudo useradd librenms -d /opt/librenms -M -r
$ sudo usermod -a -G librenms www-data   

------------ On CentOS/RHEL ------------ 
# useradd librenms -d /opt/librenms -M -r
# usermod -a -G librenms nginx           

4. Then install LibreNMS via composer command as shown.

------------ On Debian/Ubuntu ------------ 
$ cd /opt
$ sudo composer create-project --no-dev --keep-vcs librenms/librenms librenms dev-master

------------ On CentOS/RHEL ------------ 
# cd /opt
# composer create-project --no-dev --keep-vcs librenms/librenms librenms dev-master

Step 3: Create LibreNMS Database

5. Before you can start using the MariaDB server, you need to secure your installation, run the security script provided in the binary package. It will ask you set a root password, remove anonymous users, disable root login remotely and remove test database.

You can launch the script by issuing the below command and answer all questions with yes/y.

$ sudo mysql_secure_installation   [On Debian/Ubuntu]
# mysql_secure_installation        [On CentOS/RHEL]

6. Then login to MariaDB database to create a database for LibreNMS (remember to use a strong/secure password in a production environment).

$ sudo mysql -u root -p
MariaDB [(none)]> CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
MariaDB [(none)]> CREATE USER 'librenms'@'localhost' IDENTIFIED BY '=@!#@%$libre';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

7. Afterwards, disable MySQL strict mode for now (compatibility with MySQL strict mode is yet to be added).

$ sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf    [On Debian/Ubuntu]
# vi /etc/my.cnf        [On CentOS/RHEL]

Within the [mysqld] section please add.

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

Then restart the database server to effect the changes.

$ sudo systemctl restart mysql     [On Debian/Ubuntu]
# systemctl restart mariadb        [On CentOS/RHEL]

Step 4: Configure and Start PHP-FPM

8. Next, set your date.timezone in the php.ini to your current time zone, for example “Africa/Kampala”, as shown in the following screenshot.

------------ On Debian/Ubuntu ------------ 
$ sudo vim /etc/php/7.0/fpm/php.ini
$ sudo vim /etc/php/7.0/cli/php.ini

------------ On CentOS/RHEL ------------ 
# vi /etc/php.ini
Set Time Zone in PHP File
Set Time Zone in PHP File

9. Next enable the mcrypt PHP module in Ubuntu and restart php-fpm as shown.

------------ On Debian/Ubuntu ------------ 
$ sudo phpenmod mcrypt
$ sudo systemctl restart php7.0-fpm

10. On CentOS/RHEL you need to make following changes in php-fpm configuration file.

# vi /etc/php-fpm.d/www.conf

Make following changes.

;user = apache
user = nginx

group = apache   ; keep group as apache

;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php7.2-fpm.sock

listen.owner = nginx
listen.group = nginx
listen.mode = 0660

11. Restart php-fpm service as shown.

# systemctl restart php-fpm

Step 5: Configure Nginx for LibreNMS

12. In this step, you need to configure a Nginx server block for librenms in order to access the web UI. Create a .conf file for it as shown.

$ sudo vim /etc/nginx/conf.d/librenms.conf     [On Debian/Ubuntu]
# vi /etc/nginx/conf.d/librenms.conf           [On CentOS/RHEL]         

Add the following config, edit server_name as required.

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.0-fpm.sock;
 }
 location ~ /\.ht {
  deny all;
 }
}

13. Then save and exit the file. Also remove the default server block configuration and restart the Nginx server.

------------ On Debian/Ubuntu ------------ 
$ sudo rm /etc/nginx/sites-enabled/default
$ sudo systemctl restart nginx

------------ On CentOS/RHEL ------------ 
# systemctl restart nginx

NOTE: On CentOS/RHEL, you will need to disable the default site section, if this is the only site you are hosting. Delete the server section from /etc/nginx/nginx.conf file.

14. Also on CentOS/RHEL, you need to install the policy tool for SELinux and Configure the contexts needed by LibreNMS using following commands.

------------ On CentOS/RHEL ------------ 
# yum install policycoreutils-python
# semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/logs(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/logs(/.*)?'
# restorecon -RFvv /opt/librenms/logs/
# semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/rrd(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/rrd(/.*)?'
# restorecon -RFvv /opt/librenms/rrd/
# setsebool -P httpd_can_sendmail=1
# setsebool -P httpd_execmem 1

15. Allow fping by creating the file http_fping.tt with the following contents.

On CentOS/RHEL
module http_fping 1.0;

require {
type httpd_t;
class capability net_raw;
class rawip_socket { getopt create setopt write read };
}

#============= httpd_t ==============
allow httpd_t self:capability net_raw;
allow httpd_t self:rawip_socket { getopt create setopt write read };

16. Then run these commands.

------------ On CentOS/RHEL ------------ 
# checkmodule -M -m -o http_fping.mod http_fping.tt
# semodule_package -o http_fping.pp -m http_fping.mod
# semodule -i http_fping.pp

17. If you are using Firewall on CentOS/RHEL, enable HTTP/HTTPS access through firewall.

------------ On CentOS/RHEL ------------ 
# firewall-cmd --zone public --add-service http
# firewall-cmd --permanent --zone public --add-service http
# firewall-cmd --zone public --add-service https
# firewall-cmd --permanent --zone public --add-service https

Step 6: Configure SNMPD for LibreNMS

18. Now use the sample snmp configuration to create your configuration file and open it for editing, as follows.

------------ On Debian/Ubuntu ------------ 
$ sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
$ sudo vim /etc/snmp/snmpd.conf

------------ On CentOS/RHEL ------------ 
# cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
# vi /etc/snmp/snmpd.conf

Find the string RANDOMSTRINGGOESHERE and change it to your own community string as shown in screenshot.

Set SNMP String
Set SNMP String

19. Next, download a shell script on your system, which helps to detect which OS and if it is Linux then it will detect which Linux distribution, you are using:

------------ On Debian/Ubuntu ------------ 
$ sudo curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
$ sudo chmod +x /usr/bin/distro
$ sudo systemctl restart snmpd

------------ On CentOS/RHEL ------------ 
# curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
# chmod +x /usr/bin/distro
# systemctl restart snmpd

Step 7: Create Cron and Configure Logrotate

20. Now run the command below to setup a cron job for LibreNMS.

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

21. Next, all LibreNMS logs are recorded in /opt/librenms/logs, you can need to configure these logs to be auto-rotated, using the logrotate config file provided, like this.

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

Then set the appropriate permissions on the LibreNMS installation root directory and log files.

------------ On Debian/Ubuntu ------------
$ sudo chown -R librenms:librenms  /opt/librenms
$ sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs
$ sudo setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs

------------ On CentOS/RHEL ------------ 
# chown -R librenms:librenms /opt/librenms
# setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs
# setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs

Step 8: Access LibreNMS Web Installer

22. Next, use the following URL to access the web installer and follow the on-screen instructions.

http://librenms.tecmint.lan/install.php

For this address to work on a local machine, you need to setup a local DNS using the hosts file (/etc/hosts), for local domain resolution or testing purposes before going live.

192.168.43.31 tecmint.lan
192.168.43.31 librenms.tecmint.lan
Setup Local DNS for Domain
Setup Local DNS for Domain

23. You will see the installation welcome page as shown in the following screenshot, click Next Stage to continue.

LibreNMS Web Installer
LibreNMS Web Installer

24. Then enter the settings (database host, port, username and user password) for the LibreNMS database and click Next Stage to proceed.

LibreNMS Database Settings
LibreNMS Database Settings

25. The web installer will now start importing the MySQL database, this will take some time. Note that the process will try to pause at certain points, simple click on Retry to continue with the importation process.

LibreNMS Database Importing
LibreNMS Database Importing

26. Once the database importation is complete, you should see the message “Database is up to date!”, as shown in the screenshot below. Then click on Goto Add User to proceed.

LibreNMS Database Updated
LibreNMS Database Updated

27. Next, add a LibreNMS user, specify username, password and email, then click on Add User to effect the changes.

Add LibreNMS User
Add LibreNMS User

28. Now click on create the LibreNMS configuration for your system, by clicking Generate Config.

Generate Librenms Config
Generate Librenms Config
LibreNMS Configuration
LibreNMS Configuration

29. Once the config is generated, as shown in the previous screenhot, copy it and save it in the root directory of your installation, in a file called /opt/librenms/config.php.

# vi /opt/librenms/config.php
LibreNMS Configuration
<?php
## Have a look in defaults.inc.php for examples of settings you can set here. DO NOT EDIT defaults.inc.php!

### Database config
$config['db_host'] = 'localhost';
$config['db_port'] = '3306';
$config['db_user'] = 'librenms';
$config['db_pass'] = '=@!#@%$libre';
$config['db_name'] = 'librenms';
$config['db_socket'] = '';

// This is the user LibreNMS will run as
//Please ensure this user is created and has the correct permissions to your install
$config['user'] = 'librenms';

### Locations - it is recommended to keep the default
#$config['install_dir']  = "/opt/librenms";

### This should *only* be set if you want to *force* a particular hostname/port
### It will prevent the web interface being usable form any other hostname
#$config['base_url']        = "http://librenms.company.com";

### Enable this to use rrdcached. Be sure rrd_dir is within the rrdcached dir
### and that your web server has permission to talk to rrdcached.
#$config['rrdcached']    = "unix:/var/run/rrdcached.sock";

### Default community
$config['snmp']['community'] = array("public");

### Authentication Model
$config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth
#$config['http_auth_guest'] = "guest"; # remember to configure this user if you use http-auth

### List of RFC1918 networks to allow scanning-based discovery
#$config['nets'][] = "10.0.0.0/8";
#$config['nets'][] = "172.16.0.0/12";
#$config['nets'][] = "192.168.0.0/16";

# Update configuration
#$config['update_channel'] = 'release';  # uncomment to follow the monthly release channel
#$config['update'] = 0;  # uncomment to completely disable updates

30. Save and close the file. Then return to the web installer to continue with the installation process, by clicking Finish Install.

Finish LibreNMS Installation
Finish LibreNMS Installation

31. Now your LibreNMS installation is complete, you can click on “validate your install and fix any issues”, the login page should appear.

Validate LibreNMS Install
Validate LibreNMS Install

32. Next, enter your user credentials to access the validation page.

LibreNMS Login Page
LibreNMS Login Page

33. From the installation validation process, LibreNMS has discovered two issues, one is that devices have not been added (this is a warning for now), and secondly, we have not set the appropriate permission on the config file (/opt/librenms/config.php) which was manually added, as shown in the screen shot below.

LibreNMS Permission Issues
LibreNMS Permission Issues

Now run the following command to set the correct permission on the config file.

$ sudo chown -R librenms:librenms /opt/librenms/config.php 

34. To add devices, go to: http://librenms.tecmint.lan/addhost. After adding devices, you can go to the home page and add various dashboards.

LibreNMS Dashboard
LibreNMS Dashboard

That’s It! You can find more information, including installation and setup on the LibreNMS Documentation at https://docs.librenms.org/.

LibreNMS is a fully featured network monitoring system that supports a variety of network hardware. We hope that this was a lucid installation guide, if you have any questions, reach us via the feedback form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

13 Comments

Leave a Reply
    • @Jean,

      To restart LibreNMS, you need to restart the web server and the services it relies on.

      sudo systemctl restart apache2
      OR
      sudo systemctl restart nginx
      sudo systemctl restart php-fpm
      
      Reply
  1. There is a bad gateway error due to mistake in /etc/nginx/conf.d/librenms.conf file. There should be fastcgi_pass unix:/var/run/php-fpm/php7.2-fpm.sock;

    Reply
    • @jj

      Correct, this depends on your PHP version. If you have PHP 7.2, then use fastcgi_pass unix:/var/run/php-fpm/php7.2-fpm.sock; or if you have PHP 7.0, use fastcgi_pass unix:/var/run/php-fpm/php7.0-fpm.sock; and so on. Many thanks for sharing this.

      Reply
  2. Hi Aaron,

    Another info about librenms:

    • can be used with many printers (it show info about consumables ), and switches/routers.
    • on the librenms site you can find virtual disks (vmdk format) ready to use.
    • can send mails on some events (like link up/down).
    • can check many services (ssh, mysql, …)

    It is a very good tool, in my case with more then 20 snmp devices (10 are 24 ports switches) during almost one year I do not have any problem (and I make updates very often)

    Reply
  3. @Aaron Kili

    There is another typo for CentOS 7 because there is no service named snmp. It is named snmpd not snmp.

    It should be:-

    # systemctl start nginx php--fpm mariadb snmpd
    # systemctl enable nginx php--fpm mariadb snmpd
    

    Also the part where you make changes to the nginx configuration files does not refer to the default files installed on CentOS 7 after installing nginx.

    Everything is now in /etc/nginx/conf.d/ the file default.conf is there.

    nginx.conf contains only the following:-

    user  nginx;
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
    
        include /etc/nginx/conf.d/*.conf;
    }
    

    Please revisit the nginx configuration area while looking at the files in a current version of CentOS 7 as so much in your how-to is different to current files in CentOS 7 that I cannot work out what to do.

    Thanks,
    Michael K.

    Reply
  4. Stuck on Step 1 on RHEL 7.4, please somebody review for me:

    [root@rhel-74 student]# systemctl nginx start php7.0-fpm mariadb snmp
    Unknown operation ‘nginx’.

    [root@rhel-74 student]# systemctl start nginx php7.0-fpm mariadb snmp
    Failed to start php7.0-fpm.service: Unit not found.
    Failed to start snmp.service: Unit not found.

    Reply
    • @David

      Sorry, there is a typo in the article. From the output of the second command, you do not have PHP7.0-FPM and SNMP services installed on your system. Ensure that you install all required packages like this:

      # yum install epel-release
      # rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
      # yum install composer cronie fping git ImageMagick jwhois mariadb mariadb-server mtr MySQL-python net-snmp net-snmp-utils nginx nmap php72w php72w-cli php72w-common php72w-curl php72w-fpm php72w-gd php72w-mysqlnd php72w-process php72w-snmp php72w-xml php72w-zip python-memcached rrdtool

      Then start the services like this, the correct commands are here:

      # systemctl start nginx php--fpm mariadb snmp 
      # systemctl enable nginx php--fpm mariadb snmp
      
      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.