Newsletter Subscribe
Enter your email address below and subscribe to our newsletter
LibreNMS is a popular community-based tool that discovers all the available networks automatically. LibreNMS is a network monitoring tool that is based on PHP, MySQL, and SNMP.
It includes a wide range of network hardware support and Operating Systems support including Cisco, Linux, FreeBSD, Juniper, Brocade, Foundry, HP, and many more. In this guide, we are going to cover how you can install LibreNMS on Ubuntu with configuration.
Table of Contents
In this process, we are going to install LibreNMS with its other essential requirements such as NGINX, PHP, and MariaDB. So let’s start our step-by-step guide with system updation.
As we are going to download many tools, it is essential for us that we get the most recent and stable version of each of them. We can achieve it by updating our system and downloading updates (if any.). Utilize the following command for updating your system:
sudo apt update && sudo apt upgrade -y
NGINX is a highly efficient web server that is also getting positive reviews from new users. NGINX can also be used as a reverse proxy. Run the following command to install NGINX:
sudo apt install nginx -y
After installing NGINX, we have to enable it to take effect by the following command:
sudo systemctl start nginx
To check whether it is active, use the following command to check its status:
sudo systemctl status nginx
If you have an active firewall, it won’t allow connections to NGINX. To access NGINX without any issues, we have to allow it to pass through the firewall by the following command:
sudo ufw allow 'Nginx Full'
Now, let’s check the status of the firewall by the given command:
sudo ufw status
MariaDB is a replacement for MySQL which is developed by former members of MySQL. They were concerned about Oracle will make MySQL a closed source. Use the following command to install MariaDB:
sudo apt install mariadb-server mariadb-client -y
LibreNMS is not completely compatible with MySQL so it requires some changes in the configuration file. We are going to use nano as a text editor which is easy compared to Vim. Use the following command to open the configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Once the configuration file opens, paste the following lines under [mysqld] section:
innodb_file_per_table=1
sql-mode=""
lower_case_table_names=0
Use CTRL + O to save changes and CTRL + X to exit from nano.
Now, restart MariaDB by the following command to activate the changes that we made:
sudo systemctl restart mariadb
Once we are done with the configuration file, we are required to create a database for LibreNMS by the following command:
sudo mysql -u root
Now you will have to use the following command. But before pasting it, make sure that you change your username and password.
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
FLUSH PRIVILEGES;
exit
To install PHP, we are not required to add separate repository because Ubuntu already has PHP by default. Use following command to install PHP:
sudo apt -y install wget php php-{pear,cgi,common,curl,mbstring,gd,mysql,bcmath,imap,json,xml,snmp,fpm,zip}
To check PHP has been installed without any error, we can check its installed version by the following command:
php -v
We have to enter our current location to ensure we get the correct time. For that, we have to make changes to 2 configuration files. We are going to change those files one by one. Use the following command to open the first configuration file:
sudo nano /etc/php/*/fpm/php.ini
This is a large file so press CTRL + W and type date. You will get there. Now, we have to enter our time zone. In our case, it is Asia/Kolkata.
Similarly, let’s change our second configuration file. To open it, use the given command.
sudo nano /etc/php/*/cli/php.ini
Similarly, we are required to follow the same steps that we used in the previous step to enter our timezone. Enter your timezone under the date section and save it.
After configuring both files, let’s start PHP with the following command:
sudo systemctl restart php*-fpm.service
In this step, we are going to install LibreNMS from git. If you don’t have git installed, you can install it by the following command:
sudo apt install git -y
LibreNMS will be run by a user named librenms. But we have to create it by the following command:
sudo useradd -r -M -d /opt/librenms librenms
getent passwd librenms
Now, let’s add our newly created user to a web user group called www-data by the following command:
sudo usermod -a -G librenms www-data
Let’s install the required packages by LibreNMS. Use the following command to proceed further in the installation process:
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 by the following command:
git clone https://github.com/librenms/librenms.git librenms
We are required to move the librenms folder to /opt by given command:
sudo mv librenms/ /opt/
We are required to copy the configuration template by given command:
sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
Now, open configuration file situated at /etc/snmp/snmpd.conf by given command:
sudo nano /etc/snmp/snmpd.conf
You will have to replace your community string with text named RANDOMSTRINGGOESHERE
We have used LibreStr0ngSecret as a community string.
Press CTRL + O to save and CTRL + X to exit nano.
After configuring, let’s download the distro by the following command:
curl -o distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x distro
Now, let’s move downloaded distro to /usr/bin/ by given command:
sudo mv distro /usr/bin/distro
After all the configuration, we have to restart snmpd by the given command:
sudo systemctl restart snmpd
We have to copy default www.conf file by given command:
sudo cp /etc/php/8.0/fpm/pool.d/www.conf /etc/php/8.0/fpm/pool.d/librenms.conf
Now, open the copied file for editing by given command:
sudo nano /etc/php/8.0/fpm/pool.d/librenms.conf
change pool name is given in bracket [www] to [librenms]
Change user and group to librenms. As shown in the image:
Change Listen as given syntax:
listen = /run/php-fpm-librenms.sock
Run the following command to set cron job for LibreNMS:
sudo cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
LibreNMS keeps all the logs stored at /opt/librenms/logs. Over it gets large and be rotated out. To rotate out old logs, you can use the given configuration file:
sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
It will get errors if you try to write files and folders which has only read permission. Follow the given commands to change the permission of files and folders.
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/
Now, let’s run composer install for further configuration:
sudo su – librenms
you will get space for entering lines. Enter the following line of code:
./scripts/composer_wrapper.php install –no-dev
Hit Enter and type exit. It will start downloading files.
Now, enable lnms command completion by following command:
sudo ln -s /opt/librenms/lnms /usr/bin/lnms
sudo cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
We are going to create a VirtualHost definition for NGINX which LibreNMS will use. Create a new file using the following command:
sudo nano /etc/nginx/conf.d/librenms.conf
It will be black file, you have to enter following data after modification:
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;
}
}
Now, let’s check if the syntax was good enough to run by the given command:
sudo nginx -t
If it gives output with success, you are all good so far.
To remove the default file, use the following command:
sudo rm /etc/nginx/sites-enabled/default
Now, let’s restart NGINX by the given command:
sudo systemctl restart nginx
To restart PHP, use the following command:
sudo systemctl restart php8.0-fpm.service
That’s it, you have LibreNMS installed and configured on your system. You can access the Web interface of LibreNMS by going to http://your-domain.com/ or http://server-ip-address/
Yes, we found LibreNMS a great tool while using it. Because of its user-friendly interface, you can easily manage everything without messing up with Terminal.
No, you can’t use LibreNMS on Windows because it is not available for the Windows platform.
Related Posts:
Installing LibreNMS on managing it on Ubuntu is easy compared to other alternatives. By combining it with PHP, NGINX, and MariaDB, you will get to experience high performance with less complexity involved.