LibreNMS is a powerful monitoring tool that supports auto-discovery with multiple protocols, including SNMP, ARP, OSPF, and BGP. It allows you to monitor various operating systems, including Linux, Windows, and BSDs, by utilizing the SNMP protocol. SNMP (Simple Network Management Protocol) is available on most OS and offers different versions, with v3 being the most secure. In this comprehensive guide, we will walk you through the step-by-step process of installing and configuring LibreNMS on your AlmaLinux 9 server.
Prerequisites
Before we begin, ensure that you have the following prerequisites in place:
- An AlmaLinux 9 server (e.g., almalinux9.test.host) with a non-root user having sudo/root privileges.
Installing Dependencies
To start the installation process, we need to add the EPEL and Remi repositories to your system. These repositories provide additional packages required by LibreNMS. Open your terminal and run the following commands:
sudo dnf install -y epel-release sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Next, we need to reset the default PHP repository module and enable the PHP Remi repository for version 8.1. Execute the following commands:
sudo dnf module reset php sudo dnf module enable php:remi-8.1
Now, let’s install the necessary package dependencies for LibreNMS by running the command below:
sudo dnf install -y 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-redis python3-memcached python3-pip python3-systemd rrdtool unzip
Creating System User
In this step, we will create a dedicated system user called “librenms” to run LibreNMS. Open your terminal and execute the following command:
sudo useradd librenms -d /opt/librenms -M -r -s "$(which bash)"
Configuring PHP-FPM
In this section, we will configure PHP-FPM (FastCGI Process Manager) for LibreNMS. PHP-FPM is a PHP FastCGI implementation that provides better performance and resource utilization for web applications. Let’s proceed with the following steps:
- Set the system timezone by running the command below:
sudo timedatectl set-timezone Europe/Berlin sudo ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
- Open the
/etc/php.inifile using your preferred text editor:
sudo nano /etc/php.ini
- Uncomment the
date.timezoneparameter and set it to your desired timezone. For example:
date.timezone=Europe/Stockholm
- Save and exit the file.
- Copy the default PHP-FPM pool configuration to a new file called
librenms.conf:
sudo cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/librenms.conf sudo nano /etc/php-fpm.d/librenms.conf
- Update the following lines in the
librenms.conffile:
[librenms] user = librenms group = librenms listen = /run/php-fpm/librenms.sock
- Save and exit the file.
- Start and enable the PHP-FPM service:
sudo systemctl start php-fpm sudo systemctl enable php-fpm
- Verify the status of the PHP-FPM service:
sudo systemctl status php-fpm
If everything is configured correctly, you should see the status as “active (running)”.
- Additionally, you can verify the PHP-FPM sock file for LibreNMS by running:
ss -pl | grep php-fpm
Configuring MariaDB Server
Now we will configure the MariaDB server to work with LibreNMS. MariaDB is a popular open-source relational database management system. Follow these steps to configure it:
- Open the
/etc/my.cnf.d/mariadb-server.cnffile using your preferred text editor:
sudo nano /etc/my.cnf.d/mariadb-server.cnf
- Insert the following configurations under the
[mysqld]section:
innodb_file_per_table=1 lower_case_table_names=0
- Save and exit the file.
- Start and enable the MariaDB service:
sudo systemctl start mariadb sudo systemctl enable mariadb
- Secure your MariaDB installation by running the following command:
sudo mysql_secure_installation
Follow the prompts to set up the root password, disable remote login for the root user, remove the test database, and remove anonymous users.
- Create a new database and user for LibreNMS by logging into the MariaDB server:
sudo mariadb -u root -p
- Inside the MariaDB prompt, run the following queries to create the database and user:
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'librenmspassword'; GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost'; FLUSH PRIVILEGES;
Make sure to replace 'librenmspassword' with a strong password of your choice.
Downloading and Installing LibreNMS
In this section, we will download the LibreNMS source code, set up ownership and permissions, and install PHP dependencies using the included composer_wrapper script.
- Clone the LibreNMS repository to the
/opt/librenmsdirectory:
sudo git clone https://github.com/librenms/librenms.git /opt/librenms
- Change the ownership of the
/opt/librenmsdirectory to thelibrenmsuser:
sudo chown -R librenms:librenms /opt/librenms
- Set the proper permissions for LibreNMS 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/
- Switch to the
librenmsuser:
su - librenms
- Install PHP dependencies for LibreNMS using the
composer_wrapperscript:
./scripts/composer_wrapper.php install --no-dev
- Exit the
librenmsuser:
exit
Configuring SELinux
If SELinux is enabled on your AlmaLinux 9 server, we need to configure it to allow LibreNMS to function properly. Follow these steps:
- Install the necessary SELinux utilities:
sudo dnf install -y policycoreutils-python-utils
- Set up SELinux labeling for LibreNMS:
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 setsebool -P httpd_can_sendmail=1 setsebool -P httpd_execmem 1 chcon -t httpd_sys_rw_content_t /opt/librenms/.env
- Create a new SELinux module configuration file:
sudo nano http_fping.tt
- Insert the following configuration into the file:
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 };
- Save and exit the file.
- Compile and add the SELinux module:
sudo checkmodule -M -m -o http_fping.mod http_fping.tt sudo semodule_package -o http_fping.pp -m http_fping.mod sudo semodule -i http_fping.pp
Configuring Firewalld
To allow access to LibreNMS via HTTP and HTTPS, we need to configure firewalld. Follow these steps:
- Open the necessary ports for HTTP and HTTPS:
sudo firewall-cmd --add-service={http,https} --permanent sudo firewall-cmd --reload
- Verify the updated firewall rules:
sudo firewall-cmd --list-all
You should see both HTTP and HTTPS protocols listed in the output.
Configuring SNMP Service
SNMP (Simple Network Management Protocol) is essential for monitoring network devices. In this section, we will configure the snmpd service for LibreNMS.
- Copy the default SNMP configuration file:
sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf sudo nano /etc/snmp/snmpd.conf
- Update the SNMP community string in the configuration file:
# Change RANDOMSTRINGGOESHERE to your preferred SNMP community string com2sec readonly default RANDOMSTRINGGOESHERE
- Save and exit the file.
- Download the LibreNMS agent tool for detecting Linux and UNIX OSs:
sudo curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro sudo chmod+x /usr/bin/distro
- Start and enable the snmpd service:
sudo systemctl start snmpd sudo systemctl enable snmpd
- Verify the status of the snmpd service:
sudo systemctl status snmpd
Ensure that the service is active and running.
Additional LibreNMS Settings
There are a few additional configurations we need to set up for LibreNMS. Follow these steps:
- Create a symlink for the LibreNMS command-line tool
lnmsand its bash completion:
sudo ln -s /opt/librenms/lnms /usr/bin/lnms sudo cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
- Copy the LibreNMS cron configuration:
sudo cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
- Copy the logrotate configuration for LibreNMS:
sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
- Copy the LibreNMS scheduler service and timer:
sudo cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/ sudo systemctl daemon-reload
- Start and enable the LibreNMS scheduler service:
sudo systemctl enable librenms-scheduler.timer sudo systemctl start librenms-scheduler.timer
Configuring Nginx
In this section, we will configure Nginx as the web server for LibreNMS. Follow these steps:
- Create a new Nginx server block configuration file:
sudo nano /etc/nginx/conf.d/librenms.conf
- Insert the following configuration, replacing
librenms.example.iowith your desired domain name:
server {
listen 80;
server_name librenms.Example.io;
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
If the syntax is correct, you will see a message indicating that the test is successful.
- Start and enable the Nginx service:
sudo systemctl start nginx sudo systemctl enable nginx
- Verify the status of the Nginx service:
sudo systemctl status nginx
Make sure the service is active and running.
Installing LibreNMS via Web Browser
Now that all the configurations are in place, you can proceed with the installation of LibreNMS through your web browser.
- Launch your web browser and visit the domain name associated with your LibreNMS installation (e.g.,http://librenms.test.host).
- On the first page, LibreNMS will perform an environment check. Ensure that all prerequisite checks pass, then click on the database icon to continue.
- Enter the database details you created earlier and click “Check Credentials”.
- If the credentials are correct, click “Build Database” to migrate the LibreNMS database.
- Click on the key icon to set up the admin user and password for LibreNMS. Provide the necessary details, then click “Add User”.
- Finally, click “Finish Install” to complete the installation process.
Once the installation is complete, you will be redirected to the LibreNMS login page. Enter the admin username and password you set up earlier, then click “Login”. You should now have access to the LibreNMS dashboard to monitor your devices and networks.
Conclusion
Congratulations! You have successfully installed and configured LibreNMS on your AlmaLinux 9 server. With LibreNMS, you can now monitor your network devices, operating systems, and various metrics. Remember to explore the LibreNMS documentation for additional features and customization options.
If you’re looking for reliable and scalable cloud hosting solutions, consider Shape.host’s Linux SSD VPS services. Shape.host offers high-performance virtual private servers with top-notch security and support. Visit Shape.host to learn more about their hosting solutions.
Now it’s time to unleash the power of LibreNMS and gain valuable insights into your network infrastructure. Happy monitoring!