wiki:Cnbp2019/Agenda/MonitoringLab

Version 1 (modified by admin, 6 years ago) ( diff )

--

Monitoring Lab Setup


Below are the requirements for running LibreNMS on Ubuntu 18.04:

  • Database Server – We will use MariaDB
  • PHP 7.2
  • Web Server – We will use Nginx

Install LEMP stack (MariaDB, Nginx, and PHP)

Installation of MariaDB

LibreNMS is not fully compatible with MySQL strict mode, for now, please disable this after mysql is installed.

sudo vim /etc/mysql/mariadb.cnf

Within the [mysqld] section please add:

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

Then restart mysql sudo systemctl restart mysql

Now you need to create a database for LibreNMS.

mysql –u root –p
MariaDB [(none)]> CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
MariaDB [(none)]> CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'Strongpassword';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

Installation of PHP

Ubuntu 18.04 has PHP 7.2 in its repositories. Install it by running the commands below on your terminal

sudo apt-get -y install wget php php-pear php-cgi php-common curl php-curl \
php-mbstring php-gd php-mysql php-gettext php-bcmath \
php-imap php-json php-xml php-snmp php-fpm php-zip

To confirm the php version installed, use the command php –v

it should give you a similar output as below

#php -v

PHP 7.2.8 (cli) (built: Jul 17 2018 09:50:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Configure and Start PHP-FPM Ensure date.timezone is set in php.ini to your preferred time zone: Edit both files: sudo vim /etc/php/7.2/fpm/php.ini sudo vim /etc/php/7.2/cli/php.ini

Change date.timezone under [Date] section: [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Asia/Colombo Restart php fpm: sudo systemctl restart php7.2-fpm.service

For this setup, we will use Nginx as a web server for LibreNMS, install it by running: sudo apt-get install nginx

Step 2: Download and Install LibreNMS We will download and install LibreNMS in this step. If you don’t have git, first install it: $ sudo apt-get install git

LibreNMS will run under its own user called librenms which we need to add: sudo useradd -r -M -d /opt/librenms librenms getent passwd librenms

output:

librenms:x:997:996::/opt/librenms:/bin/sh Add this user to web user group www-data sudo usermod -a -G librenms www-data

When done. proceed to install packages required by LibreNMS

sudo apt-get update sudo apt install rrdtool whois fping imagemagick graphviz mtr-tiny \ nmap python-mysqldb snmp snmpd python-memcache mtr-tiny acl

Clone LibreNMS source code from github: git clone https://github.com/librenms/librenms.git librenms

output: Cloning into 'librenms'... remote: Counting objects: 130428, done. remote: Compressing objects: 100% (27/27), done. remote: Total 130428 (delta 10), reused 10 (delta 4), pack-reused 130396 Receiving objects: 100% (130428/130428), 128.54 MiB | 19.52 MiB/s, done. Resolving deltas: 100% (88754/88754), done. Checking out files: 100% (8476/8476), done.

Move the folder librenms to /opt

sudo mv librenms/ /opt/

Change permission of the directory: sudo chown -R librenms:librenms /opt/librenms/ sudo chmod -R 775 /opt/librenms/

Configure snmpd sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf sudo vim /etc/snmp/snmpd.conf

Edit the text which says RANDOMSTRINGGOESHERE and set your own community string.

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

Restart snmpd

sudo systemctl restart snmpd

Create LibreNMS Cron job Run the command below to set cron job:

sudo cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms 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

Fix LibreNMS Permissions Finally, fix all permissions sudo chown -R librenms:librenms /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/

Configure Nginx: Let’s create the VirtualHost definition for Nginx to be used by LibreNMS. sudo vim /etc/nginx/conf.d/librenms.conf

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 /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/php7.2-fpm.sock;

} location ~ /\.ht {

deny all;

}

} Check syntax:

sudo nginx –t

output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

if all is okay, restart nginx:

sudo systemctl restart nginx

Run composer install:

cd /opt/librenms ./scripts/composer_wrapper.php install --no-dev

Now open your web browser and start the installer:

http://librenms.example.com/install.php

Note: See TracWiki for help on using the wiki.