= 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 === Add MariaDB repository on to the ubuntu system `sudo apt-get install software-properties-common` Run the command below to add Repository Key to the system `sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8` Once the PGP key is imported, proceed to add repository URL to your Ubuntu 18.04 server: `sudo add-apt-repository 'deb [arch=amd64] http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic main` then Install MariaDB {{{#!bash sudo apt update sudo apt -y install mariadb-server mariadb-client }}} You will be prompted to provide MariaDB root password. Enter Class password and Press `` and confirm the new password to install MariaDB. Confirm MariaDB version and successful connectivity by `mysql –u root -p` Next, 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: {{{#!cfg 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` {{{#!mysql 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 {{{#!sh 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 {{{#!TXT 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 }}} 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` and `sudo vim /etc/php/7.2/cli/php.ini` Change date.timezone under `[Date]` section: {{{#!cfg [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` === Installation of NGINX === For this setup, we will use Nginx as a web server for LibreNMS, install it by running: `sudo apt-get install nginx` == Installation of 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: {{{#!sh sudo useradd -r -M -d /opt/librenms librenms getent passwd librenms }}} it will giva an output like, {{{#!TXT 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 {{{#!sh 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: {{{#!TXT 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. }}} Next, move the folder librenms to /opt `sudo mv librenms/ /opt/` Change permission of the directory: {{{#!sh sudo chown -R librenms:librenms /opt/librenms/ sudo chmod -R 775 /opt/librenms/ }}} Configure snmpd {{{#!sh 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. {{{#!sh 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 and 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``` Finally, fix all permissions {{{#!sh 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` {{{#!nginx server { listen 80; server_name librenms.instXY.ac.lk; 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: {{{#!TXT 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: {{{#!sh cd /opt/librenms ./scripts/composer_wrapper.php install --no-dev }}} Now open your web browser and start the installer: http://librenms.instXY.ac.lk/install.php Next, LibreNMS WebUI configurations