LibreNMS is a free, open-source, and robust network monitoring tool for Linux-based systems. It enables you to monitor various operating systems as well as network devices including Cisco, Juniper, Foundry, FreeBSD, Brocade, and more, all through a web interface. LibreNMS utilizes multiple network protocols like SNMP, ARP, CDP, FDP, LLDP, OSPF, and BGP for auto-discovering network devices and operating systems. It boasts numerous features such as auto-discovery, API access, customizable alerts, and automatic updates, among others.
This tutorial will guide you through the process of installing LibreNMS on Ubuntu 22.04, with detailed step-by-step instructions.
Prerequisites
- A server running Ubuntu 22.04
- A configured root password on your server
Getting Started
First, it is advisable to update your system packages to the latest versions. Execute the following command:
apt-get update -y
After updating, install all required dependencies for LibreNMS with this 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
Install Nginx, PHP, and MariaDB Server
Next, install Nginx server, MariaDB server, PHP, and necessary PHP extensions, using PHP-FPM as the PHP handler:
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
Set the timezone in your php.ini file:
nano /etc/php/8.1/fpm/php.ini nano /etc/php/8.1/cli/php.ini
Add the following line:
date.timezone = UTC
Save and close the file, then restart the PHP-FPM service:
systemctl restart php8.1-fpm
Create a LibreNMS Database
Create a database and user for LibreNMS:
Log in to the MariaDB shell:
mysql
Create the database and user:
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";
Flush privileges and exit:
MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit;
Edit the MariaDB configuration file for recommended settings:
nano /etc/mysql/mariadb.conf.d/50-server.cnf
In the [mysqld] section, add:
innodb_file_per_table=1 sql-mode="" lower_case_table_names=0
Restart MariaDB to apply changes:
systemctl restart mariadb
Install and Configure LibreNMS
Create a dedicated user for LibreNMS:
useradd -r -M -d /opt/librenms librenms
Add this user to the www-data group:
usermod -a -G librenms www-data
Download LibreNMS to the /opt directory:
cd /opt git clone https://github.com/librenms/librenms.git librenms
Create a log file:
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
Replace the line:
com2sec readonly default RANDOMSTRINGGOESHERE
With:
com2sec readonly default mysnmpserverkey
Download the SNMP distro binary:
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:
systemctl restart snmpd
Copy 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
Install dependencies:
cd /opt/librenms ./scripts/composer_wrapper.php install --no-dev
Change directory ownerships and set permissions:
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/
Create Nginx Virtual Host for LibreNMS
Create an Nginx virtual host configuration file:
nano /etc/nginx/conf.d/librenms.conf
Add the following configuration:
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; } }
Check Nginx configuration syntax:
nginx -t
Restart PHP and Nginx:
systemctl php8.1-fpm restart systemctl stop apache2 systemctl restart nginx
Verify Nginx status:
systemctl status nginx
Access LibreNMS Web Interface
Open your web browser and navigate to http://librenms.example.com to access LibreNMS. You will see the Pre-install check page:
Ensure all required extensions are installed, then proceed with configuring your database settings.
Follow the instructions on the subsequent pages to set up your database and admin user.
Conclusion
Congratulations! You have successfully installed and configured LibreNMS on your Ubuntu 22.04 server. You can now add remote servers or network devices for monitoring directly from the LibreNMS dashboard through your web browser.
FAQ
What should I do if I encounter a “502 Bad Gateway” error?
If you see a “502 Bad Gateway” error, ensure that the PHP-FPM service is running. You can restart it with the command systemctl restart php8.1-fpm
.
How can I verify that the Nginx configuration is correct?
To check the Nginx configuration, run nginx -t
. This will validate your configuration files for any syntax errors.
How do I update LibreNMS?
LibreNMS updates can be performed automatically. Ensure that your server is connected to the internet and updates should execute during cron jobs.
Can I use LibreNMS with other databases besides MariaDB?
While MariaDB is commonly used with LibreNMS installations, other MySQL-compatible databases may also work. However, it’s recommended to use MariaDB for a tested and stable environment.