Quantcast
Channel: Tech Support
Viewing all articles
Browse latest Browse all 880

How to Install and Configure LibreNMS on Ubuntu 16.04 Server

$
0
0

LibreNMS is an open source autodiscovering PHP/MySQL/SNMP based network monitoring which includes support for a wide range of network hardware and operating systems including Cisco, Linux, FreeBSD, Juniper, Brocade, Foundry, HP and many more.


Features

Automatic discovery: Automatically discover your entire network using CDP, FDP, LLDP, OSPF, BGP, SNMP and ARP.
Customisable alerting: Highly flexible alerting system, notify via email, irc, slack and more.
API Access: A full API to manage, graph and retrieve data from your install.
Billing system: Generate bandwidth bills for ports on your network based on usage or transfer.
Automatic Updates: Stay upto date automatically with bug fixes, new features and more.
Distributed Polling: Horizontal scaling to grow with your network.
iPhone App: Native iPhone App is available which provides core functionality.
Android App: Native Android App is available which provides core functionality.


Authentication methods:

MySQL
HTTP
LDAP
Radius
Active Directory

In this tutorial, we will show you how to install and configure LibreNMS on Ubuntu 16.04 server with Nginx as webserver and MariaDB as database.


Prerequisites

One Ubuntu 16.04 Server with a non-root user having sudo privileges


Installing Required Packages

The first step we must do for installing LibreNMS Monitoring Tools is to install some packages needed on the server.

sudo apt update
apt install fping imagemagick whois mtr-tiny nmap python-mysqldb snmpd  rrdtool git snmp graphviz


Installing Nginx Webserver

We will install nginx using apt command from the repository using the following command:

sudo apt install nginx

When installation done, start the service and make it persistent on reboot with the following commands:

sudo systemctl start nginx
sudo systemctl enable nginx


Installing PHP-FPM

We will install PHP, PHP-FPM, and all extensions/modules needed for LibreNMS installation using the following command:

sudo apt install php7.0-cli php7.0-mysql php7.0-gd php7.0-snmp php-pear php7.0-curl php7.0-fpm php7.0-mcrypt php7.0-json php-net-ipv4 php-net-ipv6

Next, we need to add some configuration to php.ini files. We need to define the default timezone in php.ini file and make sure the timezone matches with the current timezone used by the system.

You can check the currently timezone used by the system with the following command.

sudo timedatectl

Now go to the PHP configuration directory and edit php.ini files for the cli and fpm config.

cd /etc/php/7.0/
sudo nano fpm/php.ini
sudo nano cli/php.ini

Uncomment the 'date.time' line and change the value with your system timezone.

date.time = Asia/Pakistan

Uncomment cgi configuration below, change the value to 0.

cgi.fix_pathinfo = 0

Save and exit.

Start the service and make it persistent on system reboot with the following command:

sudo systemctl start php7.0-fpm
sudo systemctl enable php7.0-fpm


Installing MariaDB

We will install, configure and create a new database and a new user for the LibreNMS installation.

sudo apt install mariadb-server mariadb-client mariadb

When installation completed, start the service and make it persistent:

sudo systemctl start mysql
sudo systemctl enable mysql

Now we need to configure the root password for mariadb. We can use the 'mysql_secure_installation' command to configure the root password.

mysql_secure_installation

You will be asked about the new root password - type your password and press 'Enter' to continue.

Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Now, we will create a new database named 'librenms', a new user named 'librenms' with password 'PASSW0RD'.

Log in to the mariadb shell using the following command.

sudo mysql -u root -p
Type the ROOT Password:

Run mariadb queries below to create a new database and user, and grant all privileges on the database to the new user.

CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'PASSW0RD';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
FLUSH PRIVILEGES;

For the LibreNMS installation, we need to add some configuration to the configuration file. Go to the '/etc/mysql/' directory and edit the mariadb configuration file.

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

Add  configuration below under the '[mysqld]' section.

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

Save and exit.

sudo systemctl restart mysql

We are done with mariadb database configuration.


Download LibreNMS

First create a new system user named 'librenms', define '/opt/librenms' as the default home directory for the user, and assign the new 'librenms' user to the www-data group.

sudo useradd librenms -d /opt/librenms -M -r
sudo usermod -a -G librenms www-data

Now go to the '/opt/' directory and download the LibreNMS source code using the git command.

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

Create a new directory for libreNMS log files and rrd files.

sudo mkdir -p /opt/librenms/{logs,rrd}

Change ownership permissions for the 'rrd' directory to '775', and change the owner of the 'librenms' directory to the 'librenms' user and group.

sudo chmod -R 775 /opt/librenms/rrd/
sudo chown -R librenms:librenms /opt/librenms/

Configure LibreNMS Virtualhost. Go to the 'nginx' configuration directory and create a new virtual host file 'librenms'

cd /etc/nginx/
sudo nano sites-available/librenms

Add the following LibreNMS Virtual host configuration.

server {

    # Add your own domain name
    listen      80;
    server_name labserver.techsupportpk.com;

    # LibreNMS Webroot directory
    root        /opt/librenms/html;
    index       index.php;

    # LibreNMS logs
    access_log  /opt/librenms/logs/access_log;
    error_log   /opt/librenms/logs/error_log;
    
    # Enabling Gzip compression on Nginx
    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;
    }

    # PHP-FPM handle all .php files requests
    location ~ \.php {
        include fastcgi.conf;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Save and exit.

Now, activate the virtualhost.

ln -s /etc/nginx/sites-available/librenms /etc/nginx/sites-enabled/

Test the nginx configuration and make sure there is no error. Then restart the service.

sudo nginx -t
sudo systemctl restart nginx

Now, we need to allow ssh, http, https and the port used by snmpd 161 udp type from the ufw firewall.

sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw allow 161/udp
sudo ufw enable

Run the 'ufw status' command to see the firewall status.

sudo ufw status


Installing LibreNMS

We need to install LibreNMS through the web browser. Open your web browser, type the LibreNMS domain name 'http://labserver.techsupportpk.com' in the address bar and press Enter.

You will be redirected to the install.php page showing the result of PHP module support checks.

Make sure all status is green as shown below.

Click 'Next Stage' to continue.


Fill all the database info with your own db.

DB User: librenms
DB Pass: PASSW0RD
DB Name: librenms

Click Next Stage


Wait for the installer script to import sample of database to our database - do not close the browser tab during this process.

Once done, click 'Goto Add User'.


Type your admin user, email, and password.

Click 'Add User'.



Click the 'Generate Config' button.


And you will get a config file similar to the one shown below.


Copy the php config script, and return back to your terminal session. Goto the '/opt/librenms' directory and create the 'config.php' file manually.

cd /etc/librenms/
sudo nano config.php

Paste the configuration there, and change the ownership of the file to librenms user and group.

sudo chown librenms:librenms config.php

Return back to your web browser and click the 'Finish Install' button.

You are reached to last page from the librenms web installer as shown below.


Post Configuration

After the installation through web browser is complete, we need to do few more steps.

Backup default configuration file and copy the sample configuration to the '/etc/snmp/' directory.

sudo mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.aseli
sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf

Edit the new configuration.

sudo nano /etc/snmp/snmpd.conf

Replace the 'RANDOMSTRINGGOESHERE' line with your own community name 'TECHNOCRACY', as shown below.

com2sec readonly  default         technocracy

Save and exit.

Now, we need to download the distro detection script. Download it using curl, then make the script executable, then finally, restart the snmp service.

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

Go to the librenms directory and copy sample configuration for Crontab and Logrotate.

cd /opt/librenms/

Copy the configuration.

sudo cp librenms.nonroot.cron /etc/cron.d/librenms
sudo cp misc/librenms.logrotate /etc/logrotate.d/librenms

Now restart the cron service and reload the logrotate configuration.

sudo systemctl restart cron
sudo logrotate -f /etc/logrotate.conf

Wait for some time until the cron script is running on the system. Once that is done, validate with 'validate.php' script.

Go to the librenms directory and run the validate script.

cd /opt/librenms/
sudo ./validate.php

If your installation is correct, you will get the result as shown below.


You are done.

Viewing all articles
Browse latest Browse all 880

Latest Images

Trending Articles



Latest Images