Comprehensive Guide To Install LibreNMS on Rocky Linux 8

Posted on

Comprehensive Guide To Install LibreNMS on Rocky Linux 8

Comprehensive Guide To Install LibreNMS on Rocky Linux 8

In this tutorial, we’ll walk you through How To Install LibreNMS on Rocky Linux 8. LibreNMS is a powerful, auto-discovering PHP/MySQL/SNMP-based network monitoring system. It boasts extensive support for a vast array of network hardware and operating systems, including industry giants like Cisco, Linux, FreeBSD, Juniper, Brocade, Foundry, HP, and countless others. This guide provides a comprehensive, step-by-step approach to setting up LibreNMS on your Rocky Linux 8 server.

To get started, ensure you have a non-root user with sudo privileges configured on your server and a basic firewall set up. You can refer to our guide on Initial Server Setup with Rocky Linux 8 for assistance. Additionally, you’ll need a domain name pointed to your server’s IP address.

1. Set up LibreNMS on Rocky Linux 8

First, update your local package index:

sudo dnf update -y

Install Epel Repository

Next, install the Extra Packages for Enterprise Linux (EPEL) repository:

sudo dnf install epel-release -y

Install Remi Repository

Install the Remi repository to access the latest PHP versions:

sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

Enable PHP 8.1

Enable the PHP 8.1 Remi repository:

sudo dnf module enable php:remi-8.1 -y

With the repositories configured, let’s install the necessary packages and dependencies.

Install Required Packages and Dependencies

Use the following command to install the required packages and dependencies for Install LibreNMS on Rocky Linux 8:

sudo dnf install bash-completion cronie fping git ImageMagick mariadb-server mtr net-snmp net-snmp-utils nginx nmap php-fpm php-cli php-common php-curl php-gd php-gmp php-json php-mbstring php-process php-snmp php-xml php-zip php-mysqlnd python3 python3-PyMySQL python3-devel python3-redis python3-memcached python3-pip python3-systemd rrdtool unzip gcc

Start and enable the required services:

# sudo systemctl enable nginx php-fpm mariadb snmpd
# sudo systemctl start nginx php-fpm mariadb snmpd

Configure Firewall

Allow HTTP and HTTPS traffic through the firewall:

# sudo firewall-cmd --permanent --zone public --add-service http
# sudo firewall-cmd --permanent --zone public --add-service https

Reload the firewall to apply the changes:

sudo firewall-cmd --reload

2. Create LibreNMS User on Rocky Linux 8

Create a dedicated user for running LibreNMS:

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

3. Download LibreNMS from Source on Rocky Linux 8

Navigate to the /opt directory:

cd /opt

Clone the LibreNMS source code from GitHub:

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

Set the correct ownership and permissions for the /opt/librenms directory:

# sudo chown -R librenms:librenms /opt/librenms
# sudo chmod 771 /opt/librenms

Configure Access Control Lists (ACLs) for specific directories:

# 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/

4. Install PHP Dependencies for LibreNMS on Rocky Linux

Switch to the librenms user and install PHP dependencies:

# su - librenms
# ./scripts/composer_wrapper.php install --no-dev

Exit from the librenms user:

exit

5. Configure PHP-FPM for LibreNMS

Edit the /etc/php.ini file and set the timezone:

sudo vi /etc/php.ini

Uncomment the date.timezone directive and set it to your timezone (e.g., America/New_York):

date.timezone = America/New_York

Copy the default PHP-FPM pool configuration:

cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/librenms.conf

Edit the /etc/php-fpm.d/librenms.conf file:

sudo vi /etc/php-fpm.d/librenms.conf

Change the pool name to [librenms]:

[librenms]

Set the user and group directives to librenms:

user = librenms
group = librenms

Change the listen option to /run/php-fpm-librenms.sock:

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

Restart PHP-FPM:

sudo systemctl restart php-fpm

6. Configure MariaDB for LibreNMS

Edit the MariaDB configuration file /etc/my.cnf.d/mariadb-server.cnf:

sudo vi /etc/my.cnf.d/mariadb-server.cnf

Add the following configuration under the [mysqld] section:

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

Restart MariaDB:

sudo systemctl restart mariadb

Log in to the MariaDB shell:

sudo mysql

Create the LibreNMS database, user, and grant privileges:

MariaDB [(none)]> CREATE DATABASE librenmsdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB [(none)]> CREATE USER 'librenmsuser'@'localhost' IDENTIFIED BY 'password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenmsdb.* TO 'librenmsuser'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;

Exit the MariaDB shell:

MariaDB [(none)]> exit

7. Set up Nginx server block configuration for LibreNMS

Create an Nginx server block configuration file /etc/nginx/conf.d/librenms.conf:

sudo vi /etc/nginx/conf.d/librenms.conf

Add the following configuration, replacing domain-name with your actual domain name:

server {
    listen       80;
    server_name domain-name;
    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;
    }
}

Verify the Nginx configuration:

sudo nginx -t

Restart Nginx:

sudo systemctl restart nginx

8. Set up SELinux Rules For LibreNMS on Rocky Linux 8

Install the required package:

sudo dnf install policycoreutils-python-utils

Edit the SELinux configuration file /etc/selinux/config:

sudo vi /etc/selinux/config

Set SELINUX to enforcing:

SELINUX=enforcing

Reboot the server:

reboot

Apply SELinux rules:

# semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/html(/.*)?'
# semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/(rrd|storage)(/.*)?'
# semanage fcontext -a -t httpd_log_t "/opt/librenms/logs(/.*)?"
# semanage fcontext -a -t bin_t '/opt/librenms/librenms-service.py'
# restorecon -RFvv /opt/librenms
# chcon -t httpd_sys_rw_content_t /opt/librenms/.env

Allow Nginx access to certain services:

# setsebool -P httpd_can_sendmail=1
# setsebool -P httpd_execmem 1

Create a new http_fping.tt file:

sudo vi http_fping.tt

Add the following content:

module http_fping 1.0;

require {
type httpd_t;
class capability net_raw;
class rawip_socket { getopt create setopt write read };
}

#============= httpd_t ==============
allow httpd_t self:capability net_raw;
allow httpd_t self:rawip_socket { getopt create setopt write read };

Convert and add the SELinux rule:

# checkmodule -M -m -o http_fping.mod http_fping.tt
# semodule_package -o http_fping.pp -m http_fping.mod
# semodule -i http_fping.pp

9. Configure LibreNMS on Rocky Linux 8

Enable the lnms command and copy bash completion:

# ln -s /opt/librenms/lnms /usr/bin/lnms
# cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/

Copy the LibreNMS cron configuration:

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

Copy the logrotate configuration:

sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms

Copy the snmpd service configuration:

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

Edit the /etc/snmp/snmpd.conf file:

sudo vi /etc/snmp/snmpd.conf

Change the default community password:

# Change RANDOMSTRINGGOESHERE to your preferred SNMP community string
com2sec readonly  default           YOUR_SNMP_COMMUNITY

Download the distro binary and make it executable:

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

Restart snmpd:

sudo systemctl restart snmpd

10. Access LibreNMS Dashboard Web GUI

Edit your /etc/hosts file:

sudo vi /etc/hosts

Add your server’s IP address and domain name:

your-server-ip   your-domain

Access the LibreNMS web interface in your browser using your domain name. Follow the on-screen instructions to complete the installation, including database configuration, user creation, and final validation.

Conclusion

This comprehensive guide has shown you Install LibreNMS on Rocky Linux 8. LibreNMS is a robust solution for network monitoring and management, offering automatic network discovery, real-time monitoring, and alerting capabilities for various network devices. Now you can effectively monitor and manage your network infrastructure.

Alternative Solutions:

While the above guide provides a thorough method for installing LibreNMS, here are two alternative approaches you can consider:

1. Using Docker Compose:

Docker provides a containerization platform that can simplify the deployment of complex applications like LibreNMS. Docker Compose allows you to define and manage multi-container Docker applications. This method offers a consistent environment, reduces dependency conflicts, and simplifies updates.

  • Explanation: Docker containers encapsulate all necessary dependencies, ensuring LibreNMS runs consistently across different environments. Docker Compose simplifies the management of multiple containers (e.g., LibreNMS, MariaDB, Redis) and their interactions.

  • Steps:

    1. Install Docker and Docker Compose: Follow the official Docker documentation to install Docker Engine and Docker Compose on your Rocky Linux 8 server.
    2. Create a docker-compose.yml file: Define the services for LibreNMS, MariaDB, and potentially Redis in a docker-compose.yml file. Example structure below.
    3. Configure Environment Variables: Set necessary environment variables for database credentials, time zone, and other LibreNMS settings.
    4. Run docker-compose up -d: This command will build and start the containers in detached mode.
  • Code Example (docker-compose.yml):

    version: "3.8"
    services:
      db:
        image: mariadb:10.6
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: your_root_password
          MYSQL_DATABASE: librenms
          MYSQL_USER: librenms
          MYSQL_PASSWORD: your_librenms_password
        volumes:
          - db_data:/var/lib/mysql
    
      librenms:
        image: librenms/librenms:latest
        restart: always
        ports:
          - "80:80"
          - "443:443"
        environment:
          DB_HOST: db
          DB_DATABASE: librenms
          DB_USERNAME: librenms
          DB_PASSWORD: your_librenms_password
          PUID: 1000  # Replace with the UID of the librenms user on your host
          PGID: 1000  # Replace with the GID of the librenms user on your host
          TZ: America/New_York
        volumes:
          - librenms_data:/opt/librenms
          - ./logs:/opt/librenms/logs
        depends_on:
          - db
    
    volumes:
      db_data:
      librenms_data:

2. Using a Pre-Built Virtual Appliance:

Several providers offer pre-built virtual appliances (VM images) that come with LibreNMS pre-installed and configured. This is the quickest and easiest method for deploying LibreNMS, as it eliminates the need for manual installation and configuration.

  • Explanation: A virtual appliance is a self-contained package that includes the operating system, LibreNMS software, and all necessary dependencies. You can import the appliance into a virtualization platform like VMware, VirtualBox, or KVM and start using LibreNMS immediately.

  • Steps:

    1. Choose a Virtual Appliance Provider: Search for available LibreNMS virtual appliances. Some popular options include TurnKey Linux and Bitnami.
    2. Download the Appliance Image: Download the virtual appliance image in a format compatible with your virtualization platform (e.g., OVA, VMDK).
    3. Import the Appliance: Import the downloaded image into your chosen virtualization platform.
    4. Configure Network Settings: Configure the network settings for the virtual machine, such as IP address, gateway, and DNS servers.
    5. Access LibreNMS: Once the virtual machine is running, access the LibreNMS web interface through your browser using the configured IP address or domain name. You might need to change the VM IP to one on your LAN network.

By using these methods to Install LibreNMS on Rocky Linux 8 you can potentially save time and effort in the installation process. They also provide a more consistent and manageable environment for your network monitoring solution.

Leave a Reply

Your email address will not be published. Required fields are marked *