Home / How To / How to set up LibreNMS Monitoring Tool with Nginx on Ubuntu 20.04

How to set up LibreNMS Monitoring Tool with Nginx on Ubuntu 20.04



LibreNMS is a free open source network monitoring tool for Linux operating systems. You can monitor various operating systems such as Linux, Windows, FreeBSD and several network devices such as Cisco, Juniper, Foundry, FreeBSD, Brocade and many more with LibreNMS. It uses SNMP, ARP, CDP, FDP, LLDP, OSPF and BGP protocols to automatically detect the entire network. It has a simple and user-friendly web interface that helps you monitor all devices from the browser. It has a rich set of features including automatic detection, customizable alerts, API access, automatic updates and many more.

In this tutorial we will show you step by step instructions on how to install LibreNMS on Ubuntu 20.04.

Conditions

  • A server running Ubuntu 20.04.
  • A root password is configured on.

Getting Started

First, it is recommended that you update your system packages to the latest version. You can do this with the following command:

apt-get update -y

After updating all packages, install all the dependencies required for LibreNMS with the following command:

apt-get install rrdtool whois fping imagemagick graphviz mtr-tiny nmap python3-mysqldb snmp snmpd python3-pip python3-memcache mtr-tiny acl unzip git curl wget -y

Once all the dependencies are installed, you can move on to the next step.

Install LEMP Server

Next, you need to install Nginx web server, MariaDB server, PHP and other PHP extensions on your server. You can install them all by running the following command:

apt-get install nginx mariadb-server php php-pear php-cgi php-common php-curl php-mbstring php-gd php-mysql php-bcmath php-imap php-json php-xml php-snmp php-fpm php-zip -y

After installing all the packages, you need to set the time zone in your php.ini file.

First find the system time zone with the following command:

cat /etc/timezone

You should see the following output:

Etc/UTC

Then edit both the php.ini file with the following command:

nano /etc/php/7.4/fpm/php.ini
nano /etc/php/7.4/cli/php.ini

Define the system time zone as below:

date.timezone = Etc/UTC

Save and close the file when you are done. Then restart the PHP-FPM service to apply the changes:

systemctl restart php7.4-fpm

When you are done, you can move on to the next step.

Configure MariaDB database

Next, you need to create a database and users for LibreNMS.

First log in to the MariaDB shell with the following command:

mysql

Once logged in, create a database and user with the following command:

MariaDB [(none)]> create database librenmsdb CHARACTER SET utf8 COLLATE utf8_unicode_ci;
MariaDB [(none)]> grant all privileges on librenmsdb.* to [email protected] IDENTIFIED by "password";

Then flush the permissions and exit the MariaDB shell with the following command:

MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

Then edit the MariaDB configuration file and add some desired settings:

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

Add the following lines inside [mysqld] section:

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

Save and close the file, and then restart the MariaDB service to apply the changes:

systemctl restart mariadb

At this point, your MariaDB is configured. You can now move on to the next step.

Install and configure LibreNMS

You must first create a separate user to run LibreNMS. You can add it with the following command:

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

Then add the librenms user to the www data group with the following command:

usermod -a -G librenms www-data

Then change the directory to / opt and download the latest version of LibreNMS with the following command:

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

Then create a log file for LibreNMS with the following command:

touch /opt/librenms/logs/librenms.log

Then copy the SNMP sample configuration file with the following command:

cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf

Then edit the snmpd.conf file:

nano /etc/snmp/snmpd.conf

Find the following line:

com2sec readonly  default RANDOMSTRINGGOESHERE

And replaced it with the following line:

com2sec readonly  default mysnmpserverkey        

Save and close the file, then download SNMP distro binary and copy it to the desired location:

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

Then restart the SNMP service to apply the changes:

systemctl restart snmpd

Then you also need to copy the LibreNMS cron and logrotate file to the desired location. You can copy them using the following command:

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

Then change the directory to librenms and install the necessary dependencies with the following command:

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

Once all the dependencies are installed, you can change the ownership of the librenms directory and grant the necessary permissions with the following command:

chown -R www-data:librenms /opt/librenms
chmod -R 775 /opt/librenms
setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/

When you are done, you can move on to the next step.

Configure Nginx for LibreNMS

Next, you need to create a Nginx virtual host configuration file for LibreNMS. You can create it with the following command:

nano /etc/nginx/conf.d/librenms.conf

Add the following lines:

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.4-fpm.sock;
 }
 location ~ /.ht {
  deny all;
 }
}

Save and close the file and check Nginx for syntax errors using the following command:

nginx -t

You should see the following output:

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

Then restart the Nginx service to apply the changes:

systemctl restart nginx

You can also verify the status of the Nginx service with the following command:

systemctl status nginx

You should get the following output:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-09-05 06:15:20 UTC; 4min 5s ago
       Docs: man:nginx(8)
    Process: 28239 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 28250 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 28253 (nginx)
      Tasks: 3 (limit: 2353)
     Memory: 3.4M
     CGroup: /system.slice/nginx.service
             ??28253 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??28254 nginx: worker process
             ??28255 nginx: worker process

Sep 05 06:15:20 ubuntu2004 systemd[1]: Starting A high performance web server and a reverse proxy server...
Sep 05 06:15:20 ubuntu2004 systemd[1]: Started A high performance web server and a reverse proxy server.

When you are done, you can move on to the next step.

Go to the LibreNMS web interface

Now open your browser and access LibreNMS with URL http://librenms.example.com. You will be redirected to the control page before installation:

Check before installation

Make sure all the necessary add-ons are installed, then click Database settings. You should see the following page:

Configure the database

Enter your database username, database name, password and click Verify References button. Once successful, you should see the following page:

Create the database

Now click on Build Database button. You should see the following page:

Configure database

Then click on Administration user creative button. You should see the following page:

Create administrator users

Enter your admin username, email address, password and click add User button. You should see the following page:

The installation is complete

Then click on End installation button. You should see the following page:

Finish the installation

Then click on “validate your installationYou should see the LibreNMS login page:

Log in to LibreNMS

Enter your LibreNMS admin username, password and click Sign in button. You should see the LibreNMS Dashboard:

LibreNMS configuration

Conclusion

Congratulations! you have installed and configured LibreNMS network monitoring tool on Ubuntu 20.04 server. You can now add a device or host and start monitoring from the LibreNMS Dashboard. Feel free to ask me if you have any questions.


Source link