UbuntuUbuntu Based

How To Install LibreNMS on Ubuntu 24.04 LTS

Install LibreNMS on Ubuntu 24.04

In this tutorial, we will show you how to install LibreNMS on Ubuntu 24.04 LTS. LibreNMS stands as a powerful, community-driven network monitoring system that provides comprehensive visibility into your network infrastructure. This feature-rich platform offers automated device discovery, detailed performance graphs, customizable alerting, and extensive SNMP support—all through an intuitive web interface. Ubuntu 24.04 LTS (Noble Numbat) serves as an excellent foundation for LibreNMS due to its stability, security features, and long-term support commitment.

This guide walks you through the complete process of installing and configuring LibreNMS on Ubuntu 24.04 LTS, from initial server preparation to adding your first monitored device. By following these instructions, you’ll establish a robust network monitoring solution that provides real-time insights into your infrastructure health.

Prerequisites

Before beginning the LibreNMS installation, ensure your system meets these requirements:

  • A server running Ubuntu 24.04 LTS with root or sudo privileges
  • Minimum hardware specifications:
    • CPU: 2+ cores (4+ recommended for larger networks)
    • RAM: 4GB minimum (8GB+ recommended)
    • Storage: 40GB+ (SSD recommended for optimal performance)
  • Static IP address configured on your server
  • Properly configured hostname and DNS settings
  • Basic Linux command line experience
  • Network ports 80/443 (web interface) and 161/162 (SNMP) accessible
  • Domain name (optional but recommended for production environments)

The complete installation typically takes 30-60 minutes, depending on your system resources and familiarity with Linux environments.

Preparing the Ubuntu 24.04 LTS Server

Start by updating your system packages to ensure you have the latest security patches and software versions:

sudo apt update
sudo apt upgrade -y

Set the correct timezone for accurate monitoring timestamps:

sudo timedatectl set-timezone Your/Timezone

Replace “Your/Timezone” with your actual timezone (e.g., America/New_York or Europe/London).

Configure your server’s hostname and update the hosts file:

sudo hostnamectl set-hostname librenms.example.com
sudo nano /etc/hosts

Add or modify this line in the hosts file:

127.0.1.1   librenms.example.com librenms

Verify network connectivity by testing internet access:

ping -c 4 google.com

For systems with limited RAM, create a swap file to improve performance:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Configure the firewall to allow necessary connections:

sudo apt install -y ufw
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 161/udp
sudo ufw allow 162/udp
sudo ufw enable

Installing Required Dependencies

LibreNMS requires several packages to function properly. Install them with the following commands:

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

Next, install PHP 8.2 which is required for the latest version of LibreNMS:

sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install -y php8.2 php8.2-fpm php8.2-cli php8.2-common php8.2-mysql php8.2-snmp php8.2-gd php8.2-xml php8.2-curl php8.2-mbstring php8.2-zip php8.2-json php8.2-opcache

These PHP extensions enable various LibreNMS functions including database connectivity, SNMP operations, image manipulation, and more.

Install additional utilities that enhance LibreNMS functionality:

sudo apt install -y acl composer

Database Configuration

LibreNMS stores configuration data, device information, and metrics in a database. Install MariaDB server:

sudo apt install -y mariadb-server

Secure your MariaDB installation:

sudo mysql_secure_installation

During this process, follow the prompts to:

  • Set a root password
  • Remove anonymous users
  • Disallow root login remotely
  • Remove the test database
  • Reload privilege tables

Now, create a database and user for LibreNMS:

sudo mysql -u root -p

At the MariaDB prompt, execute these commands:

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

Replace ‘your_strong_password’ with a secure password of your choice.

Optimize MariaDB performance by editing its configuration:

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

Add these lines under the [mysqld] section:

innodb_file_per_table=1
lower_case_table_names=0

Restart MariaDB to apply changes:

sudo systemctl restart mariadb

User and Directory Setup

Create a dedicated user for LibreNMS and set up the required directories:

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

Add the librenms user to the necessary groups:

sudo usermod -a -G www-data librenms
sudo usermod -a -G librenms www-data

These group assignments ensure proper permissions for both the LibreNMS application and the web server to operate securely.

Downloading and Installing LibreNMS

Clone the LibreNMS repository from GitHub to your server:

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

Set the proper permissions for security and functionality:

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

Install PHP dependencies using Composer:

cd /opt/librenms
sudo -u librenms composer install --no-dev

This command installs all required PHP libraries while excluding development dependencies, optimizing the installation for production use.

Configuring Web Server (Nginx)

Install Nginx to serve the LibreNMS web interface:

sudo apt install -y nginx

Create a configuration file for LibreNMS:

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

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 ~ \.php {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Replace “librenms.example.com” with your actual domain or server IP address.

For production environments, configure SSL/TLS using Let’s Encrypt:

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d librenms.example.com

Enable the site and test the Nginx configuration:

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

If the test is successful, restart Nginx:

sudo systemctl restart nginx

PHP Configuration

Configure PHP for optimal performance with LibreNMS:

sudo nano /etc/php/8.2/fpm/php.ini

Make the following changes:

date.timezone = Your/Timezone
memory_limit = 256M
upload_max_filesize = 16M
max_execution_time = 300
post_max_size = 16M

Restart PHP-FPM to apply changes:

sudo systemctl restart php8.2-fpm

SNMP Configuration

SNMP (Simple Network Management Protocol) is essential for LibreNMS to collect data from network devices. Configure SNMP on the local server:

sudo apt install -y snmpd

Back up the default configuration and create a new one:

sudo cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
sudo nano /etc/snmp/snmpd.conf

Replace the content with:

# Listen on all interfaces
agentAddress udp:161,udp6:[::1]:161

# Set basic system information
sysLocation    Data Center
sysContact     admin@example.com
sysName        librenms.example.com

# Configure SNMPv3 user (recommended for security)
createUser librenmsuser SHA "auth_password" AES "enc_password"
rouser librenmsuser

# Configure SNMPv2c (less secure but more compatible)
rocommunity public localhost
rocommunity6 public localhost

# Extend LibreNMS monitoring capabilities
extend .1.3.6.1.4.1.2021.7890.1 distro /opt/librenms/scripts/distro
extend .1.3.6.1.4.1.2021.7890.2 hardware /opt/librenms/scripts/hardware

Replace “auth_password” and “enc_password” with strong, unique passwords.

Restart the SNMP service:

sudo systemctl restart snmpd

Test your SNMP configuration:

snmpwalk -v3 -l authPriv -u librenmsuser -a SHA -A "auth_password" -x AES -X "enc_password" localhost system

LibreNMS Application Configuration

Configure the LibreNMS application:

cd /opt/librenms
sudo cp .env.example .env
sudo nano .env

Update the following settings:

APP_URL=https://librenms.example.com

DB_HOST=localhost
DB_DATABASE=librenms
DB_USERNAME=librenms
DB_PASSWORD=your_strong_password

# For email notifications (optional)
MAIL_DRIVER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=alerts@example.com
MAIL_PASSWORD=your_email_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=alerts@example.com
MAIL_FROM_NAME="LibreNMS"

Set proper permissions on the configuration file:

sudo chown librenms:librenms /opt/librenms/.env

Initialize the database:

sudo -u librenms php /opt/librenms/artisan key:generate
sudo -u librenms php /opt/librenms/artisan migrate

Create required directories and set permissions:

sudo mkdir -p /opt/librenms/logs /opt/librenms/rrd
sudo chown -R librenms:librenms /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/

Setting Up Cron Jobs

LibreNMS requires several scheduled tasks to function properly. Create a cron job file:

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

Make sure the cron job is executable:

sudo chmod 644 /etc/cron.d/librenms

These cron jobs handle essential functions including device discovery, polling, alert checking, and maintenance tasks.

Accessing the Web Interface

With everything configured, access the LibreNMS web interface by navigating to your server’s IP address or domain name in a web browser:

https://librenms.example.com

Follow the setup wizard to complete the initial configuration:

  1. Create an admin user with a strong password
  2. Review and adjust any initial settings
  3. Complete the installation

Install LibreNMS on Ubuntu 24.04

After logging in, you’ll see the LibreNMS dashboard. Take time to explore the interface – the top navigation provides access to devices, alerts, and settings, while the dashboard shows system status and recent events.

Adding Devices to Monitor

Let’s add your first device to monitor – the LibreNMS server itself:

  1. Go to Devices > Add Device
  2. Enter the following information:
    • Hostname: localhost or your server’s IP
    • SNMP Version: v3 (recommended for security)
    • Authentication: Enter the SNMPv3 credentials created earlier
    • Device Type: Server
  3. Click “Add Device”

LibreNMS will attempt to discover the device. If successful, you’ll see it in your devices list.

For auto-discovery of multiple devices:

  1. Go to Settings > Network Discovery
  2. Configure discovery ranges (IP networks to scan)
  3. Set discovery frequency and methods
  4. Save and enable discovery

Basic Security Measures

Enhance your LibreNMS installation’s security with these important measures:

  1. HTTPS Configuration: If you haven’t already, set up HTTPS using Let’s Encrypt:
    sudo apt install -y certbot python3-certbot-nginx
    sudo certbot --nginx -d librenms.example.com
  2. Implement fail2ban to protect against brute force attempts:
    sudo apt install -y fail2ban
    sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
    sudo nano /etc/fail2ban/jail.local

    Configure the nginx-http-auth section:

    [nginx-http-auth]
    enabled = true
    port    = http,https
    filter  = nginx-http-auth
    logpath = /var/log/nginx/error.log
    maxretry = 5
  3. User Authentication: In LibreNMS settings, configure password complexity requirements, session timeout periods, and failed login attempt limitations.
  4. Regular Updates: Keep your system secure with periodic updates:
    cd /opt/librenms
    sudo -u librenms git pull
    sudo -u librenms composer install --no-dev
    sudo -u librenms php artisan migrate

Troubleshooting

If you encounter issues during or after installation, try these troubleshooting steps:

  1. Run the validation script:
    cd /opt/librenms
    sudo -u librenms ./validate.php

    This will identify common issues and suggest solutions.

  2. Check log files for errors:
    tail -f /opt/librenms/logs/librenms.log
  3. Database Connection Issues:
    • Verify your database credentials in the .env file
    • Ensure MariaDB is running: sudo systemctl status mariadb
    • Test the connection: mysql -u librenms -p librenms
  4. Web Server Issues:
    • Check Nginx configuration: sudo nginx -t
    • Examine error logs: tail -f /var/log/nginx/error.log
  5. SNMP Problems:
    • Verify SNMP service status: sudo systemctl status snmpd
    • Test SNMP functionality with snmpwalk
    • Check SNMP configuration for syntax errors
  6. Permission Issues:
    sudo chown -R librenms:librenms /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/

Performance Optimization

For optimal LibreNMS performance, especially in larger environments:

  1. Database Optimization:
    sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

    Add these settings:

    [mysqld]
    innodb_file_per_table=1
    lower_case_table_names=0
    innodb_buffer_pool_size=4G
    join_buffer_size=4M
    sort_buffer_size=4M
  2. Enable Caching:
    sudo apt install -y redis-server

    Update your .env file:

    CACHE_DRIVER=redis
    REDIS_HOST=127.0.0.1
  3. For larger networks, consider distributed polling by configuring additional pollers to distribute the monitoring load across multiple servers.
  4. Monitor resource usage on your LibreNMS server itself to proactively address any performance constraints before they impact monitoring quality.

Congratulations! You have successfully installed LibreNMS. Thanks for using this tutorial for installing LibreNMS with Nginx on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the LibreNMS website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button