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

0

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 (Apache, MySQL, and PHP) / EMP (Nginx, MySQL, and PHP) stack and collects the monitoring metrics via SNMP protocol.

READ: How to Install LAMP stack on CentOS 7 / RHEL 7
READ: How 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
You might also like