LibreNMS is a powerful, open-source network monitoring tool that allows you to effectively monitor various operating systems and network devices. With its extensive range of features and support for multiple protocols, LibreNMS is an essential tool for any Linux-based system administrator. In this step-by-step guide, we will walk you through the process of installing LibreNMS on Ubuntu 22.04, ensuring smooth and efficient network monitoring for your infrastructure.

Prerequisites

Before we begin, make sure you have the following:

  • A server running Ubuntu 22.04.
  • A configured root password for your server.

Getting Started

To start the installation process, it’s important to update your system packages to the latest version. Open the terminal and run the following command:

apt-get update -y

This will ensure that you have the most up-to-date packages installed on your system. Once the update process is complete, you can proceed to install the dependencies required for LibreNMS by running the following command:

apt-get install rrdtool whois fping imagemagick graphviz mtr-tiny nmap python3-mysqldb snmp snmpd python3-pip python3-memcache mtr-tiny acl unzip git curl wget -y

These dependencies are necessary for LibreNMS to function properly, enabling features like auto-discovery, API access, customizable alerts, and automatic updates.

Install Nginx, PHP, and MariaDB Server

Next, you will need to install Nginx server, PHP, and MariaDB server on your Ubuntu 22.04 system. These components are essential for running LibreNMS effectively. Run the following command to install them:

apt-get install nginx mariadb-server php php-pear php-cgi php-common php-curl php-mbstring php-gd php-mysql php-bcmath php-imap php-json php-xml php-snmp php-fpm php-zip -y

Once the installation is complete, you will need to set the system timezone in your php.ini file. Open the file using the following command:

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

Locate the line that specifies the timezone and modify it to match your desired timezone. For example, if you want to set the timezone to UTC, add the following line:

date.timezone = UTC

Save and close the file. To apply the changes, restart the PHP-FPM service by running the following command:

systemctl restart php8.1-fpm

With Nginx, PHP, and MariaDB server installed and configured, you are now ready to create a database for LibreNMS.

Create a LibreNMS Database

To store data for LibreNMS, you will need to create a dedicated database. Start by logging in to the MariaDB shell using the following command:

mysql

Once you are logged in, create a new database and user for LibreNMS with the following commands:

MariaDB[(none)]> create database librenmsdb CHARACTER SET utf8 COLLATE utf8_unicode_ci;
MariaDB[(none)]> grant all privileges on librenmsdb.* to librenms@localhost IDENTIFIED by "password";

Replace “password” with a strong password of your choice. After granting the necessary privileges, flush the privileges and exit the MariaDB shell:

MariaDB[(none)]> flush privileges;
MariaDB[(none)]> exit;

Next, you will need to modify the MariaDB configuration file to optimize it for LibreNMS. Open the file using the following command:

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

Inside the [mysqld] section, add the following lines:

innodb_file_per_table=1
sql-mode=""
lower_case_table_names=0

These settings ensure better performance and compatibility with LibreNMS. Save and close the file, then restart the MariaDB service to apply the changes:

systemctl restart mariadb

With the database set up, you can now proceed to install and configure LibreNMS.

Install and Configure LibreNMS

To install LibreNMS, you will need to create a dedicated user and directory for it. Start by creating the user with the following command:

useradd -r -M -d /opt/librenms librenms

Next, add the librenms user to the www-data group:

usermod -a -G librenms www-data

Change the directory to /opt and clone the latest version of LibreNMS using the following command:

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

Create a log file for LibreNMS:

touch /opt/librenms/logs/librenms.log

Copy the SNMP sample configuration file:

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

Edit the snmpd.conf file:

nano /etc/snmp/snmpd.conf

Locate the line that starts with com2sec readonly default and replace it with the following line:

com2sec readonlydefault mysnmpserverkey

Save and close the file. Download the SNMP distro binary and copy it to the desired location:

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

Restart the SNMP service to apply the changes:

systemctl restart snmpd

Next, copy the LibreNMS cron and logrotate files:

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

Change the directory to /opt/librenms and install the required dependencies:

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

Once the dependencies are installed, change the ownership and permissions of the LibreNMS directory:

chown -R www-data:librenms /opt/librenms
chmod -R 775 /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/

LibreNMS is now installed and configured on your Ubuntu 22.04 system. You can proceed to create an Nginx virtual host for LibreNMS.

Create Nginx Virtual Host for LibreNMS

To create an Nginx virtual host configuration file for LibreNMS, run the following command:

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

Add the following lines to the file:

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/php8.1-fpm.sock;
}

location ~ /\.ht {
deny all;
}
}

Save and close the file. To ensure that there are no syntax errors in the Nginx configuration, run the following command:

nginx -t

If the output shows that the configuration is successful, you can restart the PHP-FPM service:

systemctl restart php8.1-fpm

Next, restart the Nginx service to apply the changes:

systemctl restart nginx

You can check the status of the Nginx service by running the following command:

systemctl status nginx

If everything is working correctly, you should see a similar output:

● nginx.service - A high-performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-07-02 08:35:53 UTC; 8s ago
Docs: man:nginx(8)
Process: 49538 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 49539 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 49543 (nginx)
Tasks: 3 (limit: 4579)
Memory: 3.3M
CPU: 43ms
CGroup: /system.slice/nginx.service
├─49543 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─49544 nginx: worker process
├─49545 nginx: worker process
├─49546 nginx: worker process
├─49547 nginx: worker process
├─49548 nginx: worker process
├─49549 nginx: worker process
├─49550 nginx: worker process
├─49551 nginx: worker process
├─49552 nginx: worker process
├─49553 nginx: worker process
├─49554 nginx: worker process
├─49555 nginx: worker process
├─49556 nginx: worker process
├─49557 nginx: worker process
├─49558 nginx: worker process
├─49559 nginx: worker process
├─49560 nginx: worker process
├─49561 nginx: worker process
├─49562 nginx: worker process
├─49563 nginx: worker process
├─49564 nginx: worker process
├─49565 nginx: worker process
├─49566 nginx: worker process
├─49567 nginx: worker process
├─49568 nginx: worker process
├─49569 nginx: worker process
├─49570 nginx: worker process
├─49571 nginx: worker process
├─49572 nginx: worker process
├─49573 nginx: worker process
├─49574 nginx: worker process
├─49575 nginx: worker process
├─49576 nginx: worker process
├─49577 nginx: worker process
├─49578 nginx: worker process
├─49579 nginx: worker process
├─49580 nginx: worker process
├─49581 nginx: worker process
├─49582 nginx: worker process
└─49583 nginx: worker process

Jul 02 08:35:53 ubuntu2204 systemd[1]: Starting A high-performance web server and a reverse proxy server...
Jul 02 08:35:53 ubuntu2204 systemd[1]: Started A high-performance web server and a reverse proxy server.

With the Nginx virtual host set up, you can now access the LibreNMS web interface.

Access LibreNMS Web Interface

To access the LibreNMS web interface, open your web browser and enter the following URL:

http://librenms.example.com

Replace “librenms.example.com” with the appropriate domain or IP address. You will be redirected to the Pre-install check page, which ensures that all necessary extensions are installed. Once you have verified the extensions, click on the “Database settings” button.

On the Database settings page, provide the database username, database name, and password that you created earlier. Click on the “Check Credentials” button to verify the connection. If the credentials are correct, you will see a success message.

Next, click on the “Build Database” button to create the necessary tables in the database. Once the database is built, click on the “Admin user creation” button to create an admin account. Enter the admin username, email, and password, then click on the “Add User” button.

After creating the admin user, click on the “Finish installation” button. You will then be prompted to validate your installation. Enter your LibreNMS admin username and password, and click on the “Login” button.

Congratulations! You have successfully installed and configured LibreNMS on your Ubuntu 22.04 server. You can now start adding remote servers or network devices from the LibreNMS dashboard and enjoy effective network monitoring through the web browser.

For reliable and scalable cloud hosting solutions, consider Shape.host’s Linux SSD VPS services. Shape.host offers secure and efficient hosting options to empower businesses with seamless performance and robust security. Visit Shape.host for more information.