Network monitoring

Install LibreNMS on Ubuntu 22.04

LibreNMS is a powerful, open-source network monitoring solution that provides comprehensive insights into your network’s performance and health.

At Emerald Security, we frequently deploy LibreNMS to monitor critical infrastructure for our clients.

This guide provides step-by-step instructions to install LibreNMS on a fresh Ubuntu 22.04 server, ensuring a secure and reliable setup.

Table of Contents

Prerequisites

Before starting, ensure you have:

  • A clean Ubuntu 22.04 server (LTS) with at least 2GB of RAM and 20GB of disk space.
  • Root or sudo privileges.
  • A domain name or static IP address for accessing the web interface.
  • Basic familiarity with Linux command-line operations.

📝 Note
Always perform installations and configurations as a non-root user with sudo privileges unless otherwise specified.

Installation Instructions

Step 1 - Update the System

Start by updating your Ubuntu 22.04 server to ensure all packages are current.

sudo apt update && sudo apt upgrade -y

Step 2 - Install Required Dependencies

LibreNMS requires several packages, including a web server, database, and PHP. Install these dependencies using the following command:

sudo apt install -y apache2 mariadb-server mariadb-client php php-mysql php-gd php-snmp php-curl php-mbstring php-xml php-bcmath php-zip php-pear python3 python3-pip python3-dev composer fping imagemagick whois mtr-tiny nmap acl unzip git

Step 3 - Configure MariaDB

LibreNMS uses MariaDB as its database backend. Secure the MariaDB installation and create a database for LibreNMS.

  1. Run the secure installation script:

    sudo mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, disallow remote root login, and remove the test database.

  1. Log in to MariaDB:

    sudo mysql -u root -p
  2. Create a database and user for LibreNMS:

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

Replace StrongPassword123 with a secure password of your choice.

Step 4 - Install LibreNMS

  1. Create a directory for LibreNMS and set appropriate permissions:

    sudo mkdir -p /opt/librenms
    sudo useradd -r -M -d /opt/librenms librenms
    sudo chown -R librenms:librenms /opt/librenms
    sudo chmod 770 /opt/librenms
    sudo setfacl -d -m g::rwx /opt/librenms
  2. Clone the LibreNMS repository:

    sudo -u librenms git clone https://github.com/librenms/librenms.git /opt/librenms
  3. Install PHP dependencies using Composer:

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

Step 5 - Configure Apache Web Server

  1. Create an Apache virtual host configuration for LibreNMS:

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

    Add the following configuration, replacing your-domain.com with your domain or server IP:

    <VirtualHost *:80>
        ServerName your-domain.com
        DocumentRoot /opt/librenms/html
        AllowEncodedSlashes NoDecode
        <Directory "/opt/librenms/html">
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
        ErrorLog /opt/librenms/logs/error.log
        CustomLog /opt/librenms/logs/access.log combined
    </VirtualHost>
  2. Enable the site and required Apache modules:

    sudo a2ensite librenms.conf
    sudo a2enmod rewrite
    sudo systemctl restart apache2

Step 6 - Configure LibreNMS

  1. Copy the sample configuration file and edit it:

    sudo -u librenms cp /opt/librenms/config.php.default /opt/librenms/config.php
    sudo nano /opt/librenms/config.php

    Update the following settings in config.php:

    <?php
    $config['db']['host'] = 'localhost';
    $config['db']['database'] = 'librenms';
    $config['db']['username'] = 'librenms';
    $config['db']['password'] = 'StrongPassword123';

    Replace StrongPassword123 with the password you set earlier.

  2. Initialize the database:

    sudo -u librenms php /opt/librenms/build-base.php
  3. Set up log rotation:

    sudo -u librenms ln -s /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
    sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms

Step 7 - Configure SNMP (Optional)

If you plan to monitor devices using SNMP, ensure the snmpd service is installed and configured:

sudo apt install -y snmpd
sudo nano /etc/snmp/snmpd.conf

Add a basic community string for monitoring:

rocommunity public localhost

Restart the SNMP service:

sudo systemctl restart snmpd

Step 8 - Complete the Installation via Web Interface

  1. Open your browser and navigate to http://your-domain.com or http://your-server-ip.
  2. Follow the web-based installer to complete the setup. Ensure the pre-install checks pass, and enter the database credentials when prompted.
  3. Create an admin user for LibreNMS.

Step 9 - Secure the Installation with SSL

To secure your LibreNMS instance, install a Let’s Encrypt SSL certificate using Certbot:

  1. Install Certbot:

    sudo apt install -y certbot python3-certbot-apache
  2. Obtain and install an SSL certificate:

    sudo certbot --apache -d your-domain.com

    Follow the prompts to configure HTTPS and redirect HTTP traffic to HTTPS.

Step 10 - Set Up Polling and Discovery

  1. Add a device to monitor:

    sudo -u librenms /opt/librenms/addhost.php <device-ip> public v2c

    Replace <device-ip> with the IP address of the device you want to monitor and public with your SNMP community string.

  2. Run a manual discovery and poll:

    sudo -u librenms /opt/librenms/discovery.php -h all
    sudo -u librenms /opt/librenms/poller.php -h all
  3. Ensure cron jobs are running for automated polling and discovery:

    sudo -u librenms /opt/librenms/cronic /opt/librenms/discovery-wrapper.py 1
    sudo -u librenms /opt/librenms/cronic /opt/librenms/poller-wrapper.py 1

Step 11 - Verify the Installation

  • Log in to the LibreNMS web interface and verify that your devices are being monitored.
  • Check the /opt/librenms/logs/librenms.log file for any errors.
  • Ensure that graphs and alerts are populating correctly.

Troubleshooting Tips

  • Web interface not loading: Verify Apache is running (sudo systemctl status apache2) and check the virtual host configuration.
  • Database connection errors: Confirm the credentials in /opt/librenms/config.php match those set in MariaDB.
  • SNMP issues: Ensure the monitored device has SNMP enabled and the community string matches.
  • Permission errors: Recheck ownership and permissions for /opt/librenms (sudo chown -R librenms:librenms /opt/librenms).

Conclusion

You’ve successfully installed LibreNMS on Ubuntu 22.04! This setup provides a robust platform for monitoring your network infrastructure.

For advanced configurations, such as setting up alerts or integrating with other tools, refer to the LibreNMS documentation.

Stay tuned to the Emerald Security Insights for more tech tutorials and best practices!

Your next project starts here

Let’s build something that works.

A new building, a camera system for the back forty, or a network that needs a fresh start. Tell us what you’re working with — the first conversation is free.

Or email hello@emeraldsecurity.net