×


Install LibreNMS on Ubuntu 20.04 LTS using Nginx - Step by step guide ?

LibreNMS is an open-source auto-discovering network monitoring tool for servers and network hardware. It supports a wide range of network hardware like Cisco, Juniper, Brocade, Foundry, HP, and operating systems including Linux and Windows. LibraNMS is a community-based fork of Network monitoring tool "Observium", released under GPLv3.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux System Software Installation queries.

In this context, we shall look into how to install LibreNMS on Ubuntu 20.04 LTS.


Steps to Install LibreNMS on Ubuntu 20.04 LTS Focal Fossa

1. Perform System Update

First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal:

$ sudo apt update
$ sudo apt upgrade


2. Install Nginx on the system

Nginx is a high-performance web server and very popular these days. It also can be used as a reverse proxy and caching server. Run the following command from the Terminal to install the Nginx webserver:

$ sudo apt install nginx

Once installed, check to see if the Nginx service is running:

$ sudo systemctl start nginx
$ sudo systemctl status nginx

Now if you have your UFW firewall running, you will need to allow connections to Nginx:

$ sudo ufw allow OpenSSH
$ sudo ufw allow 'Nginx Full'

Next, Check the firewall status:

$ sudo ufw status

The output you will get is given below:

Status: active
To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)


3. Install MariaDB on the system

MariaDB is a drop-in replacement for MySQL. It is developed by former members of the MySQL team who are concerned that Oracle might turn MySQL into a closed-source product.

Run the following command to install MariaDB:

$ sudo apt install mariadb-server mariadb-client

Once complete, you can verify MariaDB is installed by running the below command:

$ sudo systemctl status mariadb

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

$ mysql_secure_installation

Then, Configure it like this:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

To log into MariaDB, use the following command (note that it's the same command you would use to log into a MariaDB database):

$ mysql -u root -p


4. Install PHP on the system

Unlike Apache, Nginx does not contain native PHP processing. For that, we have to install PHP-FPM (FastCGI Process Manager). 

Run the following command to install PHP7.4 and some common extensions:

$ sudo apt install php7.4 php7.4-fpm php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl

Once installed, check the PHP version:

$ php --version


5. Install LibreNMS on the system

You can install the packages required for LibreNMS:

$ sudo install apt install curl composer fping git graphviz imagemagick rrdtool snmp snmpd whois unzip python python3-pip

Now we will grab the LibreNMS source from the GitHub repository:

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

Next, create a user that will manage LibreNMS and add Nginx to the LibreNMS group:

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

We will need to change some folders permissions:

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

After that, we are provided with a PHP script that will install the composer dependencies. To execute that we will use the following command. To execute this script we need to switch to LibreNMS user:

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


6. Configure MariaDB for LibreNMS

Here, we will need to log in to the MariaDB console and create a database for the LibreNMS. Run the following command:

$ mysql -u root -p

This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for LibreNMS installation:

MariaDB [(none)]> CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
MariaDB [(none)]> CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'YOUR-PASSWD';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

Once done, open the MariaDB configuration file and add the following lines under [mysqld] section:

$ nano /etc/mysql/mariadb.conf.d/50-server.cnf

Within the [mysqld] section please add:

innodb_file_per_table=1 
lower_case_table_names=0

Then, restart MariaDB for the changes to take effect:

$ sudo systemctl restart mariadb


7. Configure Nginx for LibreNMS

Create the VirtualHost definition for Nginx to be used by LibreNMS:

$ nano /etc/nginx/conf.d/librenms.conf

Add the following to the config file:

server { 
  listen      80; 
  server_name librenms.linuxapt.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.4-fpm.sock;
  } 
  location ~ /\.ht { 
   deny all; 
  } 
 }

Now, we can restart the Nginx web server so that the changes take place:

$ sudo systemctl restart nginx


8. Configure Firewall

Allow Nginx through the firewall so that the user can able to access the LibreNMS portal from an external machine:

$ ufw allow 80/tcp
$ ufw allow 443/tcp
$ ufw reload


How to access LibreNMS Web Interface ?

LibreNMS will be available on HTTP port 80 by default. 

Open your favorite browser and navigate to http://your-domain.com/ or http://server-ip-address/ and complete the required steps to finish the installation.

Also you can perform the below actions:

  • Click on Database.
  • Provide the database name, User name & password.
  • Click on Check credentials.
  • Click on Build Database.
  • Once Build has been done.
  • Click on Add user.
  • Provide a username,password & Email-address.
  • Click on Add User.
  • Once User is successfully added.
  • Click on the following checksum.
  • Click on Validate your install option.
  • Provide the User name & password.
  • Click on Login.



[Need help in fixing Nginx configuration issues ? We can help you. ]


Conclusion

This article covers the process of installing LibreNMS on your Ubuntu 20.04 LTS Focal Fossa system. In fact, LibreNms works and supports protocols such as SNMP, LLDP, OSPF, ARP, CDP, BGP and FDP to auto-discover the network.  You can also use LibreNms to monitor many network hardware (such as Cisco, Juniper, Foundry, FreeBSD, Brocade) and even operating systems such as Windows, Linux, and FreeBSD.