How to Install LibreNMS on Ubuntu 20

LibreNMS is an open-source network monitoring tool. We can monitor a wide range of network devices such as Cisco, Juniper, Foundry, FreeBSD, Brocade, HP, different operating systems such as Linux, FreeBSD, Windows as well and pretty much anything that supports SNMP polling.

It’s feature set includes automatic discovery, customizable alerts, API access, billing system for ports on the network, automatic updates and many more. It also has multiple authentication methods like MySQL, HTTP, LDAP, Radius, Active Directory.

We can also get the LibreNMS native Android and iOS app so that we can monitor our devices while roaming everywhere.

Installation


For this tutorial, we will be using Ubuntu 20 as the host operating system. Here is a brief overview of the steps we will be following in the tutorial.

  1. Some pre-requisite operations
  2. Fulfilling the dependencies
  3. Setting up the database
  4. Web server configuration (Nginx)
  5. Set up the web interface
  6. Adding a device to monitor

Step 1: Pre-Requisites


Before we begin with the installation let us make sure that our system is up to date.

apt -y update 
apt -y upgrade

Step 2: Dependencies


Let us install the packages required for LibreNMS

apt install curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip 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 

Let us also create a user which will manage LibreNMS and add Nginx in LibreNMS group.

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

Since we have a fresh user made to manage LibreNMS, we will now provide the user with the privileges and set the permissions for the directories.

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/ 

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  

Step 3: Setting up the Database


To manage the data we will be using MariaDB. It is a fork of MySQL and is quite similar to mysql-server. We have already installed the MariaDB in the dependencies section.

systemctl start mariadb 
systemctl enable mariadb 

To set up MariaDB, we will use

mysql_secure_installation 

In the setup we will:

  • Set up a root password
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test databases
  • Reload privileges table

We will now create our database which will be used by LibreNMS. First login as the root user with the password you set.

mysql -uroot -p

We will now create the database and a user. Don’t forget to change the ‘password’ below to something secure.

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

We are required to add a couple of lines in the MariaDB config file.

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

In the [mysqld] section of the file, add the following lines

innodb_file_per_table=1 
lower_case_table_names=0 

Then restart MariaDB

systemctl restart mariadb

Step 4: Setting up Nginx

We will make a new config file under Nginx directory to serve LibreNMS

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

Add the following to the config file. And do not forget to change the server_name field as per your requirement

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

Don’t forget to replace server_name with your FQDN or IP Address in librenms.conf

Now we will remove the default config and restart Nginx

 rm /etc/nginx/sites-enabled/default 
 systemctl restart nginx 
 systemctl enable nginx

Step 5: Miscellaneous


Firewall Access

We can either disable the firewall(ufw) completely

ufw disable

Or we can allow access through the firewall using the following commands

ufw allow 80/tcp
ufw allow 443/tcp

Configuring SNMPD

Copy the config file provided to its required destination

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

We have to edit the RANDOMSTRINGGOESHERE provided in the snmpd.conf file.

 nano /etc/snmp/snmpd.conf  

Now we will run the following commands to get it set up and started

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

Cron Job

Cron Jobs are used to scheduling tasks that will run on the server.

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

Logrotate

LibreNMS logs can be found in /opt/librenms/logs directory which can grow up to be quite large at some time in future. We can use the logrotate config provided to counter this problem.

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

Timezones

It is important for each component installed to be on the same timezone

Ubuntu Timezone

You can check your current system timezone using the following command

 timedatectl 

If the timezone is not correct then you can change it using the following command

 timedatectl set-timezone your_time_zone 

PHP-FPM Timezone

Timezone can be changed in the php.ini file. under the module settings section. It is to be changed in both fpm and cli directory.

 nano /etc/php/7.4/fpm/php.ini
 nano /etc/php/7.4/cli/php.ini  
systemctl restart php7.4-fpm 
You can find date.timezone option under the same section in both files

MariaDB Timezone

If your system time was correct then you are not required to change the timezone in Mariadb. If it was not correct then follow the given instructions to change it.

First, we are required to be logged in as root user in MariaDB

mysql -uroot -p

To check the current time

select now()

If the time is correct and is aligned with the other applications then we are good to go if not then we can use either of the following commands to change it.

 SET GLOBAL time_zone = '+01:00' 
 SET GLOBAL time_zone = 'Europe/London'; 

Setting proper permissions

 chown -R librenms:librenms /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/ 

Step 6: Web Installer


Now on your browser, open the address of your server, In our case, it was 192.168.1.4. Yours might be different. It will take you to the web interface for the next steps in the setup process.

In stage 1 you will be prompted to enter the Database credentials.

Next, it will import the Database. If you do not see any errors then we are good to go.

Then you will be creating a user to manage LibreNMS web interface.

Now click on ‘validate your install and fix any issues’ To validate our install.

We will be using the same user we created in the web interface to login

If you see the below screen then it means that LibreNMS is properly installed.

Step 7: Adding a New Device


We will be adding a Linux device running Debian 10. We will be using SNMP to poll information from our device.

On the device, we will install snmpd

apt install snmpd

Now replace the snmpd.conf file with the example below. And also change the community string appropriately.

  # Change RANDOMSTRINGGOESHERE to your preferred SNMP community string 
 com2sec readonly  default         RANDOMSTRINGGOESHERE 

 group MyROGroup v2c        readonly 
 view all    included  .1                               80 
 access MyROGroup ""      any       noauth    exact  all    none   none 

 syslocation Rack, Room, Building, City, Country [GPSX,Y] 
 syscontact Your Name <your@email.address> 

 #Distro Detection 
 extend .1.3.6.1.4.1.2021.7890.1 distro /usr/bin/distro 

 #Hardware Detection (uncomment to enable) 
 #extend .1.3.6.1.4.1.2021.7890.2 hardware '/bin/cat /sys/devices/virtual/dmi/id/product_name' 
 #extend .1.3.6.1.4.1.2021.7890.3 manufacturer '/bin/cat /sys/devices/virtual/dmi/id/sys_vendor'
 #extend .1.3.6.1.4.1.2021.7890.4 serial '/bin/cat /sys/devices/virtual/dmi/id/product_serial' 

Now we will head to the add device section in the Web Interface

Add your hostname or IP in its respective section. The default SNMP port is 161 so we will enter the port as 161. At last enter the community string in the Community section

After a few minutes, you will be able to see your device in the devices section.


If you have any question or want to provide feedback please leave a comment in the comment section.

Leave a Reply

Your email address will not be published. Required fields are marked *