Install and configure LibreNMS on Debian 10 with Nginx

Introduction

LibreNMS is an automatic discovery based on PHP / MySQL / SNMP network monitoring, which includes support for a wide range of network hardware and operating systems, including Cisco, Linux, FreeBSD, Juniper, Brocade, Foundry, HP, etc. To install LibreNMS on Debian 10 Buster, perform the following steps.

Step 1: Install required packages

We need to install all the dependencies required by LibreNMS to run.

sudo apt install software-properties-common
sudo apt update && sudo apt -y upgrade
sudo apt install nginx
sudo apt install curl acl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap python-memcache python-mysqldb rrdtool snmp snmpd whois

Step 2: Install PHP and required extensions

Use the following guide to install PHP 7.3 and PHP extensions on your server

How to install PHP / PHP on Debian 10 Buster

Step 3: Add librenms user to the system

Run the following command on a Debian 10 terminal to add the librenms user.

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

Step 4: Clone LibreNMS from git

Now let’s download the LibreNMS file to our server using git.

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

Step 5: Set the necessary permissions on the LibreNMS directory

LibreNMS users need special permissions on the directories and files they want to access. Set it up by running the following command

sudo chown -R librenms:librenms /opt/librenms
sudo chmod 770 /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 6: Install PHP dependencies

Run the following command to install all the dependencies required by PHP on your Debian 10 server. This may take some time to complete.

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

You should see output similar to the following

Step 7: Database configuration

We installed MariaDB in step 1. Let’s move on to creating a database for LibreNMS.

Log in to your database

sudo systemctl enable mysql
sudo systemctl restart mysql
sudo mysql -u root -p

Create database and librenms user

 CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
 CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'SafePassWord'; ## Make it Strong
 GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
 FLUSH PRIVILEGES;
 exit

Open MariaDB file and add the following lines below [mysqld] section

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

Add the following below [mysqld]

[mysql]
........
innodb_file_per_table=1
lower_case_table_names=0

Restart MariaDB

sudo systemctl restart mysql

Step 8: Configure PHP-FPM

Let’s make sure that date.timezone in php.ini is set to the preferred time zone.

sudo vim /etc/php/7.3/fpm/php.ini

Down [Date] Uncomment the date.timezone line and add your time zone.

  [Date]
 ; Defines the default timezone used by the date functions
 ; http://php.net/date.timezone
 date.timezone = Africa/Nairobi ## Place your time zone here
sudo vim /etc/php/7.3/cli/php.ini

Like above, below [Date] Uncomment the date.timezone line and add your time zone.

 [Date]
 ; Defines the default timezone used by the date functions
 ; http://php.net/date.timezone
 date.timezone = Africa/Nairobi   ## Place your time zone here 

Restart PHP-FPM

sudo systemctl restart php7.3-fpm

Step 9: Configure Nginx web server

Since we chose Nginx as our preferred web server, it is time to add configuration so that we can start serving LibreNMS pages.

Remove the default page loaded after a fresh install of Nginx

sudo rm /etc/nginx/sites-enabled/default

Create a configuration file in the conf.d directory and add the following content

sudo vim /etc/nginx/conf.d/libreconfig.conf
server {
  listen      80;
  server_name example.com;         ## Input your Server name here.
  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.3-fpm.sock;
  }
  location ~ /.ht {
   deny all;
  }
 }

Restart Nginx

sudo systemctl restart nginx

Step 10: Configure the snmp daemon (snmpd)

LibreNMS makes extensive use of SNMP to collect metrics from remote devices and servers. Copy the sample configuration file to / etc

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

In the following line:

com2sec readonly  default         RANDOMSTRINGGOESHERE
##Change to for example:
com2sec readonly  default         teststring

As mentioned above, change RANDOMSTRINGGOESHERE to your own community string.

Pull the file below to make it executable, then restart the snmp daemon

This file will detect which operating system, and if it is Linux, it will detect which Linux distribution.

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

Step 11: Copy the logrotate configuration

LibreNMS keeps logs in / opt / librenms / logs. Over time, they may grow larger and be eliminated. To rotate out the old logs, you can use the provided logrotate configuration file:

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

Step 12: Set up Cron to work

This cron job does a lot of work, such as checking for updates, automatically discovering devices, etc.

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

Step 13: LibreNMS Web Installer

Now go to the web installer and follow the instructions on the screen.

http:// IP or FQDN /install.php

The web installer may prompt you to manually create a config.php file in the librenms installation location and copy the content displayed on the screen to that file. If you have to do this, remember to set permissions on config.php after copying the screen contents to a file. run:

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

Following the installation process, you can view the images below for guidance.

Install and configure LibreNMS on Debian 10 with Nginx

Enter your database user, database pass and database name

Install and configure LibreNMS on Debian 10 with Nginx

Give it time to import the database

Install and configure LibreNMS on Debian 10 with Nginx

Install and configure LibreNMS on Debian 10 with Nginx

Add a user that you will use to log in to LibreNMS in the future.

Install and configure LibreNMS on Debian 10 with Nginx

Build configuration

Install and configure LibreNMS on Debian 10 with Nginx

After generating the configuration, run the following command

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

finish installation

Install and configure LibreNMS on Debian 10 with Nginx

Click the “Verify Installation and Resolve All Issues” link to complete

Install and configure LibreNMS on Debian 10 with Nginx

When all is done, when you refresh your browser, you should see the login page below.

Install and configure LibreNMS on Debian 10 with Nginx

in conclusion

Now that we have installed the LibreNMS monitoring tool, we still have a lot of work to do. It includes adding devices, creating alerts, creating thresholds, performance tuning, and more. I hope this guide is helpful and thank you for coming. We recommend you read some LibreNMS documentation Let you continue to the next step.

You can also follow these guidelines.

How to install LibreNMS on CentOS 8 / RHEL 8

Install and configure Zabbix Server 4.4 on Debian 10 (Buster)

Install LibreNMS monitoring tool on CentOS using Letsencrypt and Nginx

How to install and configure Zabbix Agent 4.0 on Ubuntu 18.04 and CentOS 7

Install Zabbix Server on Ubuntu 18.04

How to install and configure LibreNMS on Ubuntu 18.04 LTS using Nginx

Sidebar