Install and Configure LibreNMS on Debian 11

In this article, we want to teach you How To Install and Configure LibreNMS on Debian 11.

LibreNMS is an auto-discovering PHP/MySQL/SNMP-based network monitoring which includes support for a wide range of network hardware and operating systems including Cisco, Linux, FreeBSD, Juniper, Brocade, Foundry, HP, and many more.
It is a tool in the Network Monitoring category of a tech stack.

How To Install and Configure LibreNMS on Debian 11

Before you start to install LibreNMS on Debian 11, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Debian 11.

Now follow the steps below to install LibreNMS on Debian 11.

Install MariaDB on Debian 11

First, update your local package index with the following command:

sudo apt update

Then, use the following command to install MariaDB on Debian 11:

sudo apt install mariadb-server -y

When your installation is completed, secure your MariaDB by running the script below and setting a root password for it:

sudo mysql_secure_installation

You will be asked some questions:

Enter current password for root (enter for none): 
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] 
Reload privilege tables now? [Y/n] Y

When you are done, you need to edit your MariaDB configuration file. Open the file with your favorite text editor, here we use vi:

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

Find the [mysqld] section and add the following lines in the section:

innodb_file_per_table=1
lower_case_table_names=0

When you are done, save and close the file.

Now restart your MariaDB service with the command below to apply the changes:

sudo systemctl restart mariadb

Next, log in to your MariaDB shell with the following command:

sudo mysql -u root -p

From your MariaDB shell, you need to create a database for your LibreNMS. Here we named it librenms you can replace it with your desired name.

MariaDB [(none)]> CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Also, you need to create a user for your LibreNMS. Here we named it orca you can choose your own name.

Remember to replace the password with a strong password.

MariaDB [(none)]> CREATE USER 'orca'@'localhost' IDENTIFIED BY 'securepassword';

Here you need to grant all the privileges to the LibreNMS database with the command below:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenms.* TO 'orca'@'localhost';

Then, flush the privileges and exit from your MariaDB console:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Install Nginx and PHP on Debian 11

LibreNMS installation on Debian 11, requires an Nginx web server, and PHP, and some dependencies too.

To install them on Debian 11, you can run the following command:

sudo apt install nginx-full nmap php-cli php-curl php-fpm php-gd php-json php-mbstring php-mysql php-snmp php-xml php-zip python3-dotenv python3-pip python3-pymysql python3-redis python3-setuptools python3-systemd rrdtool snmp snmpd whois acl curl composer fping git graphviz imagemagick mtr-tiny

When your packages are installed, you need to edit the php.ini file to set your time zone.

Open the file with your favorite text editor, here we use vi:

sudo vi /etc/php/7.4/fpm/php.ini

Find the date.timzone line and uncomment it by removing the “;” from the beginning of the line and setting it to UTC:

date.timezone = UTC

When you are done, save and close the file.

Set up LibreNMS on Debian 11

First of all, you need to create a user for LibreNMS on Debian 11 with the command below:

sudo useradd librenms -d /opt/librenms -M -r -s /bin/bash

Then, add the LibreNMS user to the www-data group with the following command:

sudo usermod -a -G librenms www-data

Now you can download the latest version of LibreNMS from the Git to the /opt directory with the command below:

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

Set the correct permissions and ownership for the LibreNMS with the following commands:

$ sudo chown -R librenms:librenms /opt/librenms
$ sudo chmod 771 /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/

After, switch to the LibreNMS user with the following command:

su - librenms

Now switch to the LibreNMS directory:

cd /opt/librenms

Install PHP Composer on Debian 11 with the command below:

./scripts/composer_wrapper.php install --no-dev

When your installation is completed, exit from the LibreNMS user:

exit

Here you need to create a separate configuration file for PHP-FPM with the following command:

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

Now edit the librenms.conf configuration file with your favorite text editor, here we use vi:

sudo vi /etc/php/7.4/fpm/pool.d/librenms.conf

Find the directives below and change them as shown below:

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

When you are done, save and close the file.

Restart PHP-FPM service to apply the changes:

sudo systemctl restart php7.4-fpm

Configure Nginx as a reverse proxy for LibreNMS

At this point, you need to set Nginx as a reverse proxy for LibreNMS. You need to create a virtual host file for Librenms on Debian 11 with the command below:

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

Add the following contents to the file:

Remember to replace the domain name with your own.

server {
  listen 80;
  server_name libre.yourdomain.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/php7.4-fpm.sock;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   include fastcgi.conf;
  }
  location ~ /\.(?!well-known).* {
   deny all;
  }
}

When you are done, save and close the file.

Restart Nginx to apply the changes:

sudo systemctl restart nginx php7.4-fpm

Next, copy the cron job configuration file to enable automatic discovery and polling for newly added devices with the command below:

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

Also, copy the log rotate configuration file to rotate the old logs:

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

Access LibreNMS Web Installation

At this point, you can access the LibreNMS web installation by typing your domain name in your web browser:

http://your-domain-name

You will see the pre-installation of LibreNMS, make sure that all checks are successfully then, click on the database icon.

LibreNMS pre-installation

In the Database screen, enter your database credentials and click on the check credentials.

LibreNMS database credentials

You will see the following screen, you need to click on the key icon.

Configure LibreNMS database

On the next page, set your admin credentials and click on the add user button.

LibreNMS admin user on Debian 11

When you are finished, click on the yes button and you will see the LibreNMS login screen. Enter your admin user and password to see your LibreNMS dashboard.

Librenms login screen on debian11

Now you will see your LibreNMS dashboard on Debian 11.

Librenms dashboard on debian 11

Conclusion

At this point, you learn to install LibreNMS on Debian 11.

Hope you enjoy using it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!