Introduction
LibreNMS is an auto discovering PHP/MySQL/SNMP based network monitoring which includes support for a wide range of network hardware and operating systems including Cisco, Linux, FreeBSD, Juniper, Brocade, Foundry, HP and many more. To install LibreNMS on Debian 10 / Debian 11 Linux system, follow the following steps.
Some key features of LibreNMS includes:
- Auto discovery.
- Multiple environment sensors support.
- Alerting.
- Multiple protocols data collection (STP, OSPF, BGP etc)
- VLAN, ARP and FDB table collection.
- Customizable Dashboards.
- Device Backup integration (Oxidized, RANCID)
- Distributed Polling.
Step 1: Install required dependency packages
We need to install all dependency packages required by LibreNMS to function.
sudo apt update
sudo apt install software-properties-common
Debian 11:
sudo apt install curl acl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap python3-memcache python3-mysqldb python3-pip rrdtool snmp snmpd whois
Debian 10:
sudo apt install curl acl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap python-memcache python-mysqldb python-pip rrdtool snmp snmpd whois
Step 2: Install PHP and required extensions
Use the guide below to install PHP 7.3 and PHP Extensions on your server
Commands to be run are:
sudo apt -y install php php-common
sudo apt -y install php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
Step 3: Add librenms user to the system
Run the following commands on your Debian 10 terminal to add librenms user.
sudo useradd librenms -d /opt/librenms -M -r
sudo usermod -aG librenms www-data
Step 4: Clone LibreNMS from git
Let us now download LibreNMS files into our server using git.
cd /opt
sudo git clone https://github.com/librenms/librenms.git
cd ~/
Step 5: Set Requisite Permissions
LibreNMS user requires special rights on the directories and files it is going to access. Set them by running the commands below
sudo chown -R librenms:librenms /opt/librenms
sudo chmod 770 /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/
Step 6: Install PHP dependencies
Run the commands below to install all dependencies required by PHP on your Debian 10 server. This might take a while to complete.
sudo su - librenms
./scripts/composer_wrapper.php install --no-dev
exit
You should see an output similar to the one below
Step 7: Database Configuration
We installed MariaDB in step 1. Let us proceed to create a database for LibreNMS.
Login to your Database
sudo systemctl enable mysql
sudo systemctl restart mysql
sudo mysql -u root -p
Create Database and librenms user
Run the commands below to create database and user for LibreNMS:
CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'SafePassWord'; ## Make it Strong
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
FLUSH PRIVILEGES;
exit
Open MariaDB file and add the lines below under [mysqld] section
sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf
Add the following under [mysqld]
[mysqld]
innodb_file_per_table=1
lower_case_table_names=0
Restart MariaDB
sudo systemctl restart mysql
Step 8: Configure PHP-FPM
Let us ensure date.timezone is set in php.ini to a preferred time zone.
Under [Date] uncomment the date.timezone line and add your timezone.
$ sudo vim /etc/php/*/fpm/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Africa/Nairobi
$ sudo vim /etc/php/*/cli/php.ini
date.timezone = Africa/Nairobi
Restart PHP-FPM
sudo systemctl restart php*-fpm.service
Check service status:
$ systemctl status php*-fpm.service
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-09-15 00:27:24 UTC; 23s ago
Docs: man:php-fpm7.4(8)
Process: 33765 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/SUCCESS)
Main PID: 33761 (php-fpm7.4)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 3 (limit: 2340)
Memory: 11.3M
CPU: 63ms
CGroup: /system.slice/php7.4-fpm.service
├─33761 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
├─33763 php-fpm: pool www
└─33764 php-fpm: pool www
Sep 15 00:27:24 debian-bullseye-01 systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
Sep 15 00:27:24 debian-bullseye-01 systemd[1]: Started The PHP 7.4 FastCGI Process Manager.
Step 9: Configure Nginx Webserver
Since we chose Nginx as our preferred web server, it is time to add configurations so that we start serving LibreNMS pages.
Delete the default page that loads up after fresh installation of Nginx
sudo rm /etc/nginx/sites-enabled/default
Create a config file under conf.d directory:
sudo vim /etc/nginx/conf.d/libreconfig.conf
Add the following in it while modifying domain name
server {
listen 80;
server_name librenms.example.com; ## Input your Server name here.
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 /api/v0 {
try_files $uri $uri/ /api_v0.php?$query_string;
}
location ~ .php {
include fastcgi.conf;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
location ~ /.ht {
deny all;
}
}
Restart Nginx
sudo systemctl restart nginx
Step 10: Configure snmp daemon (snmpd)
LibreNMS uses SNMP extensively to collect metrics from remote devices and servers. Copy the sample config file to /etc
sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
sudo vim /etc/snmp/snmpd.conf
On the line below:
com2sec readonly default RANDOMSTRINGGOESHERE
##Change to for example:
com2sec readonly default teststring
Change RANDOMSTRINGGOESHERE to your own community string as demonstrated above.
Pull the file below, make it executable and restart snmp daemon
The file detects which OS and if it is Linux then it will detect which Linux Distribution
sudo curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
sudo chmod +x /usr/bin/distro
sudo systemctl restart snmpd
Step 11: Copy logrotate config
LibreNMS keeps logs in /opt/librenms/logs. Over time these can become large and be rotated out. To rotate out the old logs you can use the provided logrotate config file:
sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
Step 12: Set Cron job
This cron job does a lot of stuff such as checking for updates, autodiscovery of devices among many others.
sudo cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
Step 13: LibreNMS Web installer
Now head to the web installer and follow the on-screen instructions.
http:// IP or FQDN /install.php
The web installer might prompt you to create a config.php file in your librenms install location manually, copying the content displayed on-screen to the file. If you have to do this, please remember to set the permissions on config.php after you copied the on-screen contents to the file. Run:
sudo chown librenms:librenms /opt/librenms/config.php
Follow the installation process and you can take a look at the images below for guidance.
Input your DB User, DB pass and DB Name
Give it time to import DB
Add a user you will use to login to LibreNMS later.
Generate config
After the config has been generated, please run the following command
sudo chown librenms:librenms /opt/librenms/config.php
Finish Installation
Click on the “validate your install and fix any issues” link to finish up
After everything is done, you should see the login page below when you refresh your browser.
Recommended Linux books:
Conclusion
Now that we have installed LibreNMS monitoring tool, we still have some work to do. It includes adding devices, creating alerts, creating thresholds, performance tuning and much more. We hope the guide was helpful and we appreciate your visit. We suggest that you have a read of a few LibreNMS docs to get you going with the next steps.
You can also go through the guides below for your enjoyment.
- How To Install LibreNMS on CentOS 8 / RHEL 8
- Install and Configure Zabbix Server 4.4 on Debian 10 (Buster)
- Install LibreNMS Monitoring Tool on CentOS with Letsencrypt and Nginx
- How to Install and configure Zabbix agent Ubuntu and CentOS 7
- Install Zabbix Server on Ubuntu
- Install and Configure LibreNMS on Ubuntu with Nginx