Skip to content

Install LibreNMS

Note

This assumes the Ubuntu initial configurations have been perfomed as found here.

Note

Installation instructions sourced from LibreNMS' official documentation.

Install required packages

sudo apt install acl curl fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php-cli php-curl php-fpm php-gd php-gmp php-json php-mbstring php-mysql php-snmp php-xml php-zip rrdtool snmp snmpd unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd python3-pip whois traceroute

Add LibreNMS User

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

Download LibreNMS

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

Set Permissions

sudo chown -R librenms:librenms /opt/librenms
sudo chmod 771 /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/

Install PHP Dependencies

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

Set Timezone

Set timezone in both of the php ini files. In my case, it is America/New_York. You can look up the correct timezone here.

sudo nano /etc/php/8.1/fpm/php.ini
sudo nano /etc/php/8.1/cli/php.ini

Configure MariaDB

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Within the [mysqld] section add:

innodb_file_per_table=1
lower_case_table_names=0

Enable MariaDB at boot and restart:

sudo systemctl enable mariadb
sudo systemctl restart mariadb

Start MariaDB client:

sudo mysql -u root

Run the following query on the db, changing the password to something secure:

CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
exit

Configure PHP-FPM

Duplicate the default config file:

sudo cp /etc/php/8.1/fpm/pool.d/www.conf /etc/php/8.1/fpm/pool.d/librenms.conf

Modify the config file:

sudo nano /etc/php/8.1/fpm/pool.d/librenms.conf
  • Change [www] to [librenms]
  • Change user and group to librenms
  • Change listen to /run/php-fpm-librenms.sock

Since I will not run any other PHP web applications on this server, delete the www.conf file:

sudo rm /etc/php/8.1/fpm/pool.d/www.conf

Configure Web Server

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

Add the following configuration, editing the server_name:

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;
 }
}

Remove the default site:

sudo rm /etc/nginx/sites-enabled/default

Restart nginx:

sudo systemctl restart nginx

Restart php:

sudo systemctl restart php8.1-fpm

Enable LNMS Command Completion

This feature grants you the opportunity to use tab for completion on lnms commands as you would for normal linux commands.

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

Configure SNMPD

Make a copy the example file:

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

Edit the config file:

sudo nano /etc/snmp/snmpd.conf
  • Edit the text which says RANDOMSTRINGGOESHERE and set your own community string.

Download the distro information file:

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

Enable and restart the snmpd service:

sudo systemctl enable snmpd
sudo systemctl restart snmpd

Add Cron Job

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

Enable the Scheduler

sudo cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/
sudo systemctl enable librenms-scheduler.timer
sudo systemctl start librenms-scheduler.timer

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

Web Installer

Now head to the web installer and follow the on-screen instructions.

http://ipaddress/install

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

Add Devices

You can now add devices from the web interface by clicking on Devices > Add Device. Provided the instructions found here were followed, you can add an Ubuntu host using:

  • Hostname or IP: ipaddress
  • SNMP: ON
  • SNMP Version: v2c 161 udp
  • Port Association Mode: ifIndex
  • Community: use the snmp configured on the server
  • Force add: OFF