LibreNMS is a free and open-source fully featured auto discovering network monitoring tool that is based on PHP, MySQL and uses SNMP protocol. It supports various hardware such as Cisco, Juniper, Foundry, and operating systems including Linux, Windows, FreeBSD, etc.
In this article, I will discuss how to install LibreNMS in Ubuntu Linux.
Prerequisites
You should have access to a user account that has sudo privileges.
How to install LibreNMS in Ubuntu
For running LibreNMS we require a database server, PHP, and a web server. Follow the given steps to install all the required packages and LibreNMS on your system.
Installing web server
We will use Nginx as a web server so if you are installing Nginx on your system you should not have another web server installed.
First, run the given command to make sure the apt repository is updated –
sudo apt update
Now if you have apache installed simply remove it by using –
sudo apt -y remove apache2
Use the following command to install Nginx –
sudo apt -y install nginx
Once the package gets installed use the following command to start and enable Nginx services –
sudo systemctl start nginx
sudo systemctl enable nginx
Make sure Nginx services are active and running –
sudo systemctl status nginx
Installing PHP
Next, we need to install Php on our system you can use the following command to install PHP and other required packages-
sudo apt -y install wget php php-{pear,cgi,common,curl,mbstring,gd,mysql,bcmath,imap,json,xml,snmp,fpm,zip}
You can verify the installation of PHP by using the given command –
php -v
Configure PHP-FPM
Use the following command to edit both php.ini files –
sudo nano /etc/php/*/fpm/php.ini
sudo nano /etc/php/*/cli/php.ini
In the Date section set your own time zone.
Save both the files and restart PHP-FPM services –
sudo systemctl restart php*-fpm.service
Installing and configuring database server
We will use MariaDB as our database server. Use the following command to install it on your system –
sudo apt install mariadb-server
Press y and then enter if it asks for your confirmation.
LibreNMS is not fully compatible with MYSQL strict mode so disable it for now –
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
In mysqld
section add the given lines –
[mysqld]
innodb_file_per_table=1
sql-mode=""
lower_case_table_names=0
Save this file and exit.
Now restart the MariaDB services –
sudo systemctl restart mariadb
Once the database server is set up, create a database for LibreNMS.
First, use the following command to log in to the MariaDB server –
sudo mysql -u root
Next, create a database for LibreNMS by using the given query-
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Use the given query to create a user –
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'StrongPassword';
Grant all the privileges to the user on the created database –
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
FLUSH PRIVILEGES;
exit
Installing LibreNMS
In this section, we will download and install LibreNMS on our system. First, use the given command to install git if it is not installed already –
sudo apt install git -y
LibreNMS will run under its own user called librenms
so use the following command to add a new user –
sudo useradd -r -M -d /opt/librenms librenms
getent passwd librenms
Add the created user to the group www-data –
sudo usermod -a -G librenms www-data
Use the following command to install some prerequisite packages to your system –
sudo apt install rrdtool whois fping imagemagick graphviz mtr-tiny nmap python3 python3-pip python3-mysqldb snmp snmpd python3-memcache mtr-tiny composer acl unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd -y
Clone LibreNMS from GitHub –
git clone https://github.com/librenms/librenms.git librenms
Move the downloaded folder librenms
to /opt
–
sudo mv librenms/ /opt/
Configure snmpd
Next, configure snmpd –
sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
sudo nano /etc/snmp/snmpd.conf
Add the following string to your own community –
com2sec readonly default LibreStr0ngSecret
Next download the distro –
curl -o distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x distro
sudo mv distro /usr/bin/distro
Restart snmpd –
sudo systemctl restart snmpd
Configure PHP-FPM
Copy default PHP-FPM www.conf file by using –
sudo cp /etc/php/*/fpm/pool.d/www.conf /etc/php/*/fpm/pool.d/librenms.conf
Now open and edit librenms.conf
file by using –
sudo nano /etc/php/*/fpm/pool.d/librenms.conf
Change [www]
to [librenms]
:
Change user
and group
to librenms –
user = librenms
group = librenms
Change listen
to a unique name –
listen = /run/php-fpm-librenms.sock
Create LibreNMS cron job
Create the cron job by using the given command –
sudo cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
Copy logrotate configuration
Use the following command to rotate the old logs of directory /opt/librenms/log
s –
sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
Provide the required permissions –
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/
Run composer install –
sudo su - librenms
./scripts/composer_wrapper.php install --no-dev
exit
Enable lnms command –
sudo ln -s /opt/librenms/lnms /usr/bin/lnms
sudo cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
Configure Nginx
Now create the VirtualHost definition for Nginx to be used by LibreNMS.
sudo nano /etc/nginx/conf.d/librenms.conf
Add the given content to this file –
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(/|$) { fastcgi_pass unix:/run/php-fpm-librenms.sock; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi.conf; } location ~ /\.(?!well-known).* { deny all; } }
Check the syntax by using –
sudo nginx -t
Finally restart the Nginx –
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
Restart PHP-FPM services –
sudo systemctl restart php7.4-fpm.service
Access LibreNMS Web interface
Open a browser and enter the given URL –
http://server_ip
For example –
http://librenms.example.com/install.php
First, confirm that preinstall check is successful –
Next, enter your database credentials i.e. user name, password, and database name, and click on the Check Credentials button.
Once the database credential check is successful click on Build Database.
On the next screen, enter create a new user choose a user name, enter the password for it and enter your email finally click on Add User.
Next click on validate your install to fix any issue and finish the installation.
Finally, you can log in to LibreNMS by entering the username and password that you have created –
For more information on the usage of LibreNMS, you can visit its official website.
Conclusion
Ok, so we hope you have set up LibreNMS successfully on your Ubuntu system. Now for any query you can write us in the comments below.