You are on page 1of 18

POSTED ONMARCH 2, 2020 

BY RAMNEEK

How to Install LibreNMS on CentOS 8


LibreNMS is an open-source network monitoring tool. We can monitor a wide range
of network devices such as Cisco, Juniper, Foundry, FreeBSD, Brocade, HP,
different operating systems such as Linux, FreeBSD, Windows as well and pretty
much anything that supports SNMP polling.

It’s feature set includes automatic discovery, customizable alerts, API access, billing
system for ports on the network, automatic updates and many more. It also has
multiple authentication methods like MySQL, HTTP, LDAP, Radius, Active Directory.

We can also get the LibreNMS native Android and iOS app so that we can monitor
our devices while roaming everywhere.

Installation

For this tutorial, we will be using CentOS 8 as the host operating system. Here is a
brief overview of the steps we will be following in the tutorial.

1. Some pre-requisite operations


2. Configuring SELinux
3. Installing Dependencies and setting user permission
4. Setup Database
5. Web engine configuration (Nginx)
6. Setup Web Interface
7. Adding a device to monitor

Step 1: Pre-Requisites

Before we begin with the installation let us make sure that our system is up to date.

dnf -y update

Now let’s install all repos which are required to install LibreNMS on Centos 8. All
dependencies are found in both Epel and Remi repository. Remi repo to get the
latest PHP package and EPEL repo to satisfy the dependencies.

dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm


Step 2: SELinux

Before we can start with our installation it is advised that we disable SELinux or set it
to permissive mode so that it will not hinder the installation process. To do this, we
will edit the SELinux config file.

vi /etc/selinux/config

Here we set it to the permissive mode


Make sure to reboot your server after changing the SELinux config.

Step 3: Dependencies

Let’s install the packages required for LibreNMS to run on Ubuntu 20.

dnf install bash-completion cronie fping git ImageMagick mariadb-server mtr net-
snmp net-snmp-utils nginx nmap php74-php-fpm php74-php-cli php74-php-common php74-
php-curl php74-php-gd php74-php-json php74-php-mbstring php74-php-process php74-
php-snmp php74-php-xml php74-php-zip php74-php-mysqlnd python3 python3-PyMySQL
python3-redis python3-memcached python3-pip rrdtool unzip

*Enable PHP 7.4*

dnf module reset php

dnf module enable php:remi-7.4

Now let’s create LibreNMS user.

useradd librenms -d /opt/librenms -M -r -s /usr/bin/bash


Finally, it’s time to clone the latest LibreNMS repo under /opt

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

Since we have a new user to manage LibreNMS, we are required to provide the user
with the privileges and set permissions for directories.

chown -R librenms:librenms /opt/librenms

chmod 771 /opt/librenms

setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs


/opt/librenms/bootstrap/cache/ /opt/librenms/storage/

setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs


/opt/librenms/bootstrap/cache/ /opt/librenms/storage/

We are provided with a PHP script that will install the composer dependencies. To
execute that script we need to switch to librenms user.

*Install Composer*

dnf install php-cli php-json php-zip wget unzip

curl -sS https://getcomposer.org/installer |php

mv composer.phar /usr/local/bin/composer

*IMPORTANT*

dnf install php php-opcache php-gd php-curl php-mysqlnd

su - librenms

./scripts/composer_wrapper.php install --no-dev

exit
Step 4: Setting up Database

We will be using MariaDB on Centos8 for LibreNMS. It is a fork of MySQL and is


quite similar to mysql-server. We have already installed the MariaDB in the
dependencies section.

systemctl start mariadb

systemctl enable mariadb

To set up MariaDB, we will use

mysql_secure_installation

Here we will:

 Set up root password for database


 Remove anonymous users
 Disallow root login remotely
 Remove test databases
 Reload Privileges table

We will now create our database which will be used by LibreNMS. First login as the
root user with the password you set.

mysql -u root -p
Next we are required to create a database and a user, Do not forget to change the
‘password’ below to something secure

CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';

FLUSH PRIVILEGES;

exit

In the MariaDB config file, we need to add two lines.

vi /etc/my.cnf.d/mariadb-server.cnf

Add the following lines under [mysqld] section

innodb_file_per_table=1

lower_case_table_names=0
Then restart MariaDB

systemctl restart mariadb

Step 5: PHP-FPM and Nginx set up

For PHP-FPM to work with Nginx, we are required to make changes to the config file

cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/librenms.conf

vi /etc/php-fpm.d/librenms.conf

We will edit the following values.

# Change "www" to "librenms"

[librenms]

# Change user and group to "librenms"

user = librenms

group = librenms

# Change listen to a unique name *check your work!*

listen = /run/php-fpm/www.sock

*to*

listen = /run/php-fpm-librenms.sock

PHP-FPM should be now ready to go.

For Nginx, we will make a config file.

vi /etc/nginx/conf.d/librenms.conf

Now add the following lines in the librenms.conf file and replace server_name with
your IP Address or FQDN.

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;

Also, we should not forget to remove the default server section from the nginx.conf
file.

vi /etc/nginx/nginx.conf
Here
we removed the contents of server section
Now start and enable the Nginx so that it will start with system restart

systemctl start nginx

systemctl enable nginx

Step 6: Miscellaneous:

FIREWALLD ACCESS
We can either disable the firewalld

systemctl stop firewalld

systemctl disable firewalld

Or we can allow access through the firewalld by using the following commands.

firewall-cmd --zone public --add-service http

firewall-cmd --permanent --zone public --add-service http

firewall-cmd --zone public --add-service https

firewall-cmd --permanent --zone public --add-service https

SNMPD CONFIG
Copy the sample config file to its required destination

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

We have to edit the RANDOMSTRINGGOESHERE provided in the snmpd.conf file.


vi /etc/snmp/snmpd.conf

Now we will run the following commands to get it set up and started

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

chmod +x /usr/bin/distro

systemctl enable snmpd

systemctl restart snmpd

CRON JOB
LibreNMS has it’s own cron jobs that are used to poll and discover the devices in
your network, copy it’s cron file and paste it inside /etc/cron.d directory.

cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms

LOGROTATE
LibreNMS logs can be found in /opt/librenms/logs directory which can grow up to be
quite large at some time in future. We can use the logrotate config provided to
counter this problem.

cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms

TIMEZONES
It is important for each component that we have installed to work on the same
timezone as our server.

On CentOS
To check timezone on CentOS 8 we can use
timedatectl

If you want to change it, we will first look at available timezones

timedatectl list-timezones | grep -i continent

Change the ‘continent’ with your continent to make the search easier. Now to


change the timezone we will use. Edit the following command with your timezone
instead of Europe/London.

timedatectl set-timezone Europe/London

PHP-FPM
Time zone can be set in the php.ini file found in /etc

vi /etc/php.ini

Edit the date_timezone under the [Module Setting] section. Use the same timezone
as used above.

Now restart php-fpm and we are good to go.

systemctl restart php-fpm

Step 7: Web Installer

Now on your browser, open the address of your server, In our case, it was
192.168.122.86. Yours might be different. It will take you to the web interface for the
next steps in the setup process.
Enter the database user password when prompted.
Next, it will build the Database. If you do not see any errors then we are good to go.

Then we will be creating a user to manage LibreNMS web interface.


Now click on ‘validate your install and fix any issues’ To validate our install.
We will be using the same user we created in the web interface to login
If you see the above screen then it means that LibreNMS is properly installed and we
are good to go for further configuration.

Step 8: Adding a New Device

We will be adding a Linux device running Debian 10. We will be using SNMP to
collect and organize information from our device

On the device, we will install snmpd

apt install snmpd

Now replace the snmpd.conf file with the example below. And also change the
community string appropriately.
# Change RANDOMSTRINGGOESHERE to your preferred SNMP community string

com2sec readonly default RANDOMSTRINGGOESHERE

group MyROGroup v2c readonly

view all included .1 80

access MyROGroup "" any noauth exact all none none

syslocation Rack, Room, Building, City, Country [GPSX,Y]

syscontact Your Name <your@email.address>

#Distro Detection

extend .1.3.6.1.4.1.2021.7890.1 distro /usr/bin/distro

#Hardware Detection (uncomment to enable)

#extend .1.3.6.1.4.1.2021.7890.2 hardware '/bin/cat


/sys/devices/virtual/dmi/id/product_name'

#extend .1.3.6.1.4.1.2021.7890.3 manufacturer '/bin/cat


/sys/devices/virtual/dmi/id/sys_vendor'

#extend .1.3.6.1.4.1.2021.7890.4 serial '/bin/cat


/sys/devices/virtual/dmi/id/product_serial'

Note: Restart snmpd service after changing it's config file.

Now we will head to the add device section in the Web Interface

Add your hostname or IP in its respective section. The default SNMP port is 161 so
we will enter the port as 161. At last enter the community string in the Community
section
After a few minutes, you will be able to see your device in the devices section.

You have successfully installed your LibreNMS server on Centos 8.Thank you for
reading this blog, if you guys have any questions or you got stuck anywhere please
feel free to mention in the comment section below.

CATEGORIESLIBRENMS, MONITORING AND ALERTING

You might also like