Sunday, April 21, 2024
HomeHow toHow to Install LibreNMS Monitoring Tool on Ubuntu 22.04

How to Install LibreNMS Monitoring Tool on Ubuntu 22.04

LibreNMS is a free and open-source monitoring tool written in PHP/MySQL/SNMP. It is a community-based fork of the Observium with the GPL license.

LibreNMS supports a wide range of hardware and operating systems, such as Cisco, Linux, Juniper, and many more. It supports auto-discovery network services using CDP, OSPF, BGP, SNMP, and ARP. It provides a customizable user dashboard that you can configure as you need and also comes with a customizable alerting system. Also, the LibreNMS is an extensible monitoring system with integration supports such as NFSen, collectd, etc.

LibreNMS supports multiple authentication methods, including local MySQL, Radius, LDAP, and Active Directory. This feature is useful if you have an infrastructure with centralized authentication. LibreNMS also provides a billing system that makes administrator easier to check and generate bandwidth usage and the bill for each user.

This guide will teach you how to install and configure the LibreNMS monitoring tool on the latest Ubuntu 22.04 server. This tutorial will cover some additional configurations of the LEMP Stack for the LibreNMS installation.

Prerequisites

  • An Ubuntu 22.04 Server
  • A non-root user with the root privileges

Installing Packages Dependencies

First, you will be installing package dependencies for the LibreNMS. This will include the LEMP Stack, some Python tools, and some networking tools such as SNMP, whois, and rrdtool.

Before installing any packages, run the apt command below to update and refresh your Ubuntu repository.

sudo apt update

Now install package dependencies for LibreNMS using the apt command below.

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

Input Y to confirm and press ENTER to continue. And the installation for dependencies will begin, wait until all installation is completed.

Downloading and Installing LibreNMS

After installing package dependencies, you will install the LibreNMS from the source code.

Firstly, you must add the new user named ‘librenms’. This user will be used to run the LibreNMS monitoring tool application. You can add the user “librenms” using the below command.

useradd librenms -d /opt/librenms -M -r -s "$(which bash)"

The command will create a new user “librenms” with the home directory /opt./librenms and the default shell bash.

Now move to the /opt directory and download the source code of the LibreNMS monitoring tool using the git command as below.

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

You will get a new directory named librenms inside the /opt.

Next, run the following command to change the ownership and permission of the /opt/librenms directory.

The ownership must be user “librenms” and the permission “771” that allows librenms user to read, write and execute inside that directory.  The setfacl command is used to set up the file access control lists inside the directory rrd (for storing rrd graph), logs for storing logs, the cache for storing LibreNMS cache, and storage for the data directory.

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

Now log in to the user “librenms” using the below command.

su - librenms

Lastly, install all PHP dependencies for LibreNMS monitoring using the PHP script “composer_wrapper.php”.

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

Below is the screenshot during the installation of PHP package dependencies for LibreNMS.

Below is the screenshot of when LibreNMS installation is completed. As you can see, the installer script will install some additional Python tools from the PyPi repository.

Configure Timezone for PHP

In this step, you will now be setting up the timezone for PHP by editing the php.ini configuration file.

Edit the configuration php.ini using nano editor.

sudo nano /etc/php/8.1/fpm/php.ini
sudo nano /etc/php/8.1/cli/php.ini

Uncomment the option date.timezone and add your timezone as below. In this example, the timezone will be Etc/UTC.

date.timezone = Etc/UTC

Save and close the file when you are done.

Next, run the timedatectl command below to set up the timezone for your system to Etc/UTC.

sudo timedatectl set-timezone Etc/UTC

Lastly, restart the PHP-FPM service to apply new changes to the php.ini configuration file.

sudo systemctl restart php8.1-fpm

You have now completed the timezone configuration for PHP and your Ubuntu system.

Configuring MariaDB Server

The LibreNMS monitoring tool requires some specific configuration on the MariaDB server. In this step, you will edit the MariaDB server configuration and create a new database and user for LibreNMS.

Edit the MariaDB server configuration 50-server.cnf using nano editor.

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

Under the “[mysqld]” section, add the below configuration.

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

Save and close the file when you are done.

Next, run the systemctl commands below to enable and restart the MariaDB service. This will enable the MariaDB service to start at system startup and apply new changes to the MariaDB server configuration.

sudo systemctl enable mariadb
sudo systemctl restart mariadb

You have now completed the MariaDB server configuration.

Now log in to the MariaDB shell using the mysql command below.

sudo mysql -u root -p

Run the following queries to create a new database librenms, the user librenms, and password is “password“.

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

Lastly, type exit to log out from the MariaDB shell. And now you have to create the database and user for the LibreNMS monitoring tool.

Configuring PHP-FPM Pool for LibreNMS

After configuring the MariaDB server, you will be setting up the PHP-FPM pool for LibreNMS. PHP-FPM allows you to create multiple process pools for each of your applications. This enables you to specify a pool for a specific application, in his case LibreNMS monitoring tool.

The PHP-FPM pool configuration is available at /etc/php/8.1/fpm/pool.d directory with the default pool configuration www.conf.

Now run the command below to copy the default pool configuration from www.conf to librenms.conf.

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

Edit the pool configuration librenms.conf using nano editor.

sudo nano /etc/php/8.1/fpm/pool.d/librenms.conf

Change the default pool name from “[www]” to “[librenms]” as below.

[librenms]

Change the default user and group to “librenms“.

user = librenms
group = librenms

Now change the listen socket for PHP-FPM to /run/php-fpm-librenms.sock as eblow.

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

Save and close the file when you are done.

Next, run the command below to restart the PHP-FPM service and make new changes to the pool configuration.

sudo systemctl restart php8.1-fpm

Lastly, if you check all available sock files on your system, you can see the sock file /run/php-fpm-librenms.sock, which belongs to the PHP-FPM pool librenms.

You can check the sock file using the following command.

ss -pln

Configuring Nginx Server Blocks for LibreNMS

You have completed the configuration of the MariaDB server and PHP-FPM for LibreNMS, now you will be setting up Nginx server blocks for the LibreNMS monitoring tool.

Create a new Nginx server blocks librenms.conf using nano editor.

sudo nano /etc/nginx/sites-available/librenms.conf

Copy the following configuration and paste it into the file. Also, change the default domain name librenms.hwdomain.io with your domain.

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

Save and close the file when you are done.

Next, activate the server blocks configuration librenms.conf, then verify Nginx configuration using the following command.

sudo ln -s /etc/nginx/sites-available/librenms.conf /etc/nginx/sites-enabled/
sudo nginx -t

If you get the output like test-successful, then your configuration is correct.

Lastly, you can restart the nginx service to apply new server blocks configuration librenms.conf.

sudo systemctl restart nginx

At this point, your LibreNMS installation is now accessible through the domain name librenms.hwdomain.io.

Additional Configuration for LibreNMS

Before you start the LibreNMS installation, you will need some additional configuration for your Ubuntu system. All of this configuration is needed for LibreNMS.

First, you will need to create a symbolic link (symlink) of the LibreNMS binary file to the /usr/bin directory, which allows users to execute the command lnms from the shell.

sudo ln -s /opt/librenms/lnms /usr/bin/lnms

Now copy the lnms command-completion for bash shell to the /etc/bash_completion.d/ directory.

sudo cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/

Next, you will need to configure the SNMP service for the LibreNMS monitoring tool. The SNMP service can be used to add and monitor servers or devices.

Copy the sample configuration of the SNMP service provided by LibreNMS to the /etc/snmp/snmp.conf. Then edit the configuration using nano editor.

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

Change the default community password “RANDOMSTRINGGOESHERE” for the SNMP service with your strong password.

com2sec readonly default RANDOMSTRINGGOESHERE

save and close the file when you are done.

Now run the below command to download the binary script LibreNMS agent for checking Linux distribution to the /usr/bin/ directory and also make it executable.

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

Now enable the snmpd service and restart the service to apply the new configuration.

systemctl enable snmpd
systemctl restart snmpd

You have now completed the snmp configuration for LibreNMS.

Lastly, run the following command to cron script and logrotate configuration for LibreNMS.

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

Now you can start the LibreNMS installation from the web browser.

Start Web Installer LibreNMS

Open your web browser and visit the LibreNMS installation domain name (for e.g http://librenms.hwdomain.io) and you should see the LibreNMS installation page below.

First, you can see the pre-install check page. Be sure all requirements are checked with green status, which means all requirements for LibreNMS installation have been passed.

Click the database icon on top to continue.

Enter details of the MariaDB database for your LibreNMS installation and click the Check Credentials button.

Click the Build Database button to start the database configuration. This will import all necessary tables for LibreNMS. When all process is completed, you can see the message “Database seeding completed successfully“.

Now click the key icon on top to start configuring the LibreNMS user.

Enter details admin user for LibreNMS installation and click Add User.

When the installation is completed, you can see the following page. The .env file and config.php file have been written with a new configuration.

Also, you must validate your LibreNMS installation by clicking the link “validate your install“.

Now, you will be redirected to the LibreNMS login page. Input your admin user and password, then click Login.

Once you have logged in, you can see the following LibreNMS validation page. Be sure all status of the LibreNMS is on the green color with Ok, which means all configuration for LibreNMS is correct.

Now, you are ready to add a host machine or hardware to your LibreNMS monitoring tool.

Conclusion

Congratulation! You have now learned to install the LibreNMS monitoring tool on the latest Ubuntu 22.04 with the newest PHP 8, MariaDB server, and Nginx web server. You have also learned how to configure the LibreNMS to complete the installation.


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here


spot_img

Most Popular