Install LibreNMS on CentOS 7 / Ubuntu 16.04 – A Network and Server Monitoring Tool

Install LibreNMS on CentOS 7 / Ubuntu 16.04 – A Network and Server Monitoring Tool

LibreNMS is an open source auto-discovering network monitoring tool for servers and network hardware. It supports a wide range of network hardware like Cisco, Juniper, Brocade, Foundry, HP and operating systems including Linux and Windows. LibraNMS is a community-based fork of Network monitoring tool “Observium“, released under GPLv3.

LibreNMS can discover your entire network using CDP, FDP, LLDP, OSPF, BGP, SNMP and ARP protocols. It’s alerting system can be highly customized to receive alerts via email, IRC, slack and more.

LibreNMS is based on AMP (ApacheMySQL, and PHP) / EMP (NginxMySQL, and PHP) stack and collects the monitoring metrics via SNMP protocol.

READHow to Install LAMP stack on CentOS 7 / RHEL 7
READHow to Install LAMP stack on Ubuntu 16.04

This tutorial covers the installation of LibreNMS on CentOS 7 / Ubuntu 16.04 and collecting the data from external machines via SNMP protocol.

Prerequisites:

Login as the root user or switch to root user as commands we run during the installation process requires root privilege.

su -

OR

sudo su -

Configure EPEL repository on CentOS 7 / RHEL 7.

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

Install and Configure MySQL / MariaDB:

As I said, LibreNMS needs AMP stack, so install MariaDB as a database server, a fork of MySQL.

### CentOS 7 / RHEL 7 ###

yum -y install mariadb-server mariadb

### Ubuntu 16.04 ###

apt-get update
apt-get -y install mariadb-server mariadb-client

To start MariaDB, run:

### CentOS 7 / RHEL 7 ###
 
systemctl restart mariadb

### Ubuntu 16.04 ###

systemctl restart mysql

To stop MariaDB, run:

### CentOS 7 / RHEL 7 ### 

systemctl stop mariadb

### Ubuntu 16.04 ###

systemctl stop mysql

To restart MariaDB, run:

### CentOS 7 / RHEL 7 ###

systemctl restart mariadb

### Ubuntu 16.04 ###

systemctl restart mysql

To check the status of MariaDB, run:

### CentOS 7 / RHEL 7 ###

systemctl status mariadb

### Ubuntu 16.04 ###

systemctl status mysql

To autostart at system startup, run:

### CentOS 7 / RHEL 7 ###

systemctl enable mariadb

### Ubuntu 16.04 ###

systemctl enable mysql

Once the MySQL / MariaDB installation is complete, run mysql_secure_installation command to secure the database server.

Create Database for LibreNMS:

login to MySQL:

mysql -u root -p

Now, create the database for LibreNMS installation with the following information.

DB Name: librenmsdb
User Name: librenmsuser
DB Password: librenmspassword

CREATE DATABASE librenmsdb;
CREATE USER 'librenmsuser'@'localhost' IDENTIFIED BY 'librenmspassword';
GRANT ALL PRIVILEGES ON librenmsdb.* TO 'librenmsuser'@'localhost';
exit

Disable MySQL strict mode for LibreNMS installation.

### CentOS 7 / RHEL 7 ###

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

### Ubuntu 16.04 ###

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

Add the below lines to the [mysqld] section.

innodb_file_per_table=1
sql-mode=""
lower_case_table_names=0

Restart MySQL service.

### CentOS 7 / RHEL 7 ###

systemctl restart mariadb

### Ubuntu 16.04 ###

systemctl restart mysql

Install and Configure Apache:

Install Apache server and PHP packages using the following command.

### CentOS 7 / RHEL 7 ###

yum -y install php php-cli php-gd php-mysql php-snmp php-pear php-curl php-common httpd net-snmp mariadb ImageMagick jwhois nmap mtr rrdtool MySQL-python net-snmp-utils cronie php-mcrypt fping git

pear install Net_IPv4-1.3.4

pear install Net_IPv6-1.2.2b2

### Ubuntu 16.04 ###

apt-get -y install libapache2-mod-php7.0 php7.0-cli php7.0-mysql php7.0-gd php7.0-snmp php-pear php7.0-curl snmp graphviz php7.0-mcrypt php7.0-json apache2 fping imagemagick whois mtr-tiny nmap python-mysqldb snmpd php-net-ipv4 php-net-ipv6 rrdtool git

a2enmod php7.0

a2dismod mpm_event

a2enmod mpm_prefork

phpenmod mcrypt

Set time zone in php.ini file.

For Centos: /etc/php.ini

For Ubuntu 16.04: /etc/php/7.0/apache2/php.ini and /etc/php/7.0/cli/php.ini

date.timezone = America/Chicago

Install and Configure LibreNMS:

Add librenms user

useradd librenms -d /opt/librenms -M -r

Make librenms user part of apache user (CentOS: apache or Ubuntu: www-data) group.

### CentOS 7 / RHEL 7 ###

usermod -a -G librenms apache

### Ubuntu 16.04 ###

usermod -a -G librenms www-data

Clone LibreNMS repo on /opt directory.

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

Set the permission.

cd /opt/librenms
mkdir rrd logs
chmod 775 rrd

Set ownership.

chown -R librenms:librenms /opt/librenms

Create Apache configuration file for LibreNMS Web Interface.

### CentOS 7 / RHEL 7 ###

vi /etc/httpd/conf.d/librenms.conf 

### Ubuntu 16.04 ###

nano /etc/apache2/sites-available/librenms.conf

Add the following configuration to the above file. Change librenms.itzgeek.local as per your requirement.

<VirtualHost *:80>
  DocumentRoot /opt/librenms/html/
  ServerName librenms.itzgeek.local
  CustomLog /opt/librenms/logs/access_log combined
  ErrorLog /opt/librenms/logs/error_log
  AllowEncodedSlashes NoDecode
  <Directory "/opt/librenms/html/">
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
  </Directory>
</VirtualHost>
Optional – Disable the default site in case your server going to host only this site.
### CentOS 7 / RHEL 7 ###

rm -f /etc/httpd/conf.d/welcome.conf

### Ubuntu 16.04 ###

a2dissite 000-default

SELinux (CentOS/RHEL):

Run the following commands on terminal to allow LibreNMS to write or read data through SELinux.

yum install -y policycoreutils-python
semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/logs(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/logs(/.*)?'
restorecon -RFvv /opt/librenms/logs/
setsebool -P httpd_can_sendmail=1
setsebool -P httpd_can_network_connect=1

Restart apache services.

### CentOS 7 / RHEL 7 ###

systemctl restart httpd

### Ubuntu 16.04 ###

a2ensite librenms.conf
a2enmod rewrite
systemctl restart apache2

Enable Apache service on system boot.

### CentOS 7 / RHEL 7 ###

systemctl enable httpd

### Ubuntu 16.04 ###

systemctl enable apache2

Firewall:

Allow apache through the firewall so that user can able to access LibreNMS portal from an external machine.

FirewallD:

firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload

UFW:

ufw allow 80/tcp
ufw reload

Setup LibreNMS:

Open a web browser and navigate it to below URL.

http://librenms.itzgeek.local

OR

http://fully-qualified-domain-name

OR

http://your.ip.add.ress

Click Next Stage on the installation page.

Install LibreNMS on CentOS 7 - Installation Wizard
Install LibreNMS on CentOS 7 – Installation Wizard

Stage 1: Enter the database information.

DB Name: librenmsdb
User Name: librenmsuser
DB Password: librenmspassword

Install LibreNMS on CentOS 7 - Database Details
Install LibreNMS on CentOS 7 – Database Details

Stage 2: Installer will start importing schemas and other important database entries.

Install LibreNMS on CentOS 7 - Importing DB
Install LibreNMS on CentOS 7 – Importing DB
Install LibreNMS on CentOS 7 - DB Import Completed
Install LibreNMS on CentOS 7 – DB Import Completed

Click on Goto Add User.

Stage 3: Create Admin user.

Install LibreNMS on CentOS 7 - User Creation
Install LibreNMS on CentOS 7 – User Creation

Stage 4: Generate config.

Install LibreNMS on CentOS 7 - Generating Config
Install LibreNMS on CentOS 7 – Generating Config

Stage 5: If you get any error like below.

Install LibreNMS on CentOS 7 - Error in Config file creation
Install LibreNMS on CentOS 7 – Error in Config file creation

Manually create a config.php under /opt/librenms directory.

vi /opt/librenms/config.php

Copy and paste the configurations shown in the error page to the above file.

Install LibreNMS on CentOS 7 - Copying Configurations
Install LibreNMS on CentOS 7 – Copying Configurations

Then, click on Finish install.

Stage 6: You can ignore the below error. Click on “here to login to your new install” to get a login page.

Install LibreNMS on CentOS 7 - Completion of LibreNMS Installation
Install LibreNMS on CentOS 7 – Completion of LibreNMS Installation

Login page:

Install LibreNMS on CentOS 7 - LibreNMS Login Page
Install LibreNMS on CentOS 7 – LibreNMS Login Page

LibreNMS Dashboard: (Illustration only – Dashboard may look like below after you have added devices to LibreNMS and customized front page)

Install LibreNMS on CentOS 7 - LibreNMS Dashboard
Install LibreNMS on CentOS 7 – LibreNMS Dashboard

Post Setup:

Once the LibreNMS setup is complete, perform below steps.

vi /opt/librenms/config.php

Add below information to “config.php” file.

$config['fping'] = "/usr/sbin/fping";

Copy the cronjob information so that automatic discovery and polling for newly added devices can happen automatically.

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

Copy the logrotate configurations.

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

Run validate.php as root in /opt/librenms directory.

cd /opt/librenms
./validate.php

Output:

==========================================================
Component | Version
--------- | -------
LibreNMS | d30e5660f942154bd72c1b3f6ff3846d3c1b7137
DB Schema | 199
PHP | 7.0.18-0ubuntu0.16.04.1
MySQL | 10.0.29-MariaDB-0ubuntu0.16.04.1
RRDTool | 1.5.5
SNMP | NET-SNMP 5.7.3
==========================================================

[OK] Database connection successful
[OK] Database schema correct

We suggest you add localhost (LibreNMS server) as your first device using LibreNMS web interface. To add your localhost or any devices in LibreNMS monitoring tool, you need to install and configure SNMP service, not applicable to Network devices.

Follow the below guide to add localhost as well as other machines in LibreNMS.

READHow to Add Devices to LibreNMS Monitoring Tool

That’s All.

Leave a Reply

Your email address will not be published. Required fields are marked *