6

How to Install LibreNMS Monitoring Tool on Debian 11

 2 years ago
source link: https://www.howtoforge.com/how-to-install-librenms-monitoring-tool-on-debian-11/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Install LibreNMS Monitoring Tool on Debian 11

LibreNMS is a free, open-source, web-based, and auto-discovering network monitoring tool written in PHP. It uses MySQL or MariaDB as a database backend and uses SNMP to discover the remote clients. It supports a wide range of network devices including, Linux, Cisco, Juniper, FreeBSD, HP, Windows, and more. It supports multiple authentication methods including, Radius, Active Directory, LDAP, MySQL, and more. It is simple, user-friendly, and easy for anyone to understand and use.

In this tutorial, I will explain how to install LibreNMS with Nginx on Debian 11.

Prerequisites

  • A server running Debian 11.
  • A valid domain name pointed with your server IP.
  • A root password is configured on your server.

Install and Configure MariaDB Database

First, you will need to install the MariaDB database server on your server. You can install it using the following command:

apt-get install mariadb-server -y

Once the install is completed, run the following script to secure the MariaDB installation and set a root password:

mysql_secure_installation

Answer all the questions as shown below:

Enter current password for root (enter for none): 
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] 
Reload privilege tables now? [Y/n] Y

Once the MariaDB is secured, edit the MariaDB configuration file and tweak some settings:

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

Add the following lines inside [mysqld] section:

innodb_file_per_table=1
lower_case_table_names=0

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

systemctl restart mariadb

Next, log in to MariaDB with the following command:

mysql -u root -p

Once you are log in, create a database and user for LibreNMS:

MariaDB [(none)]> CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB [(none)]> CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'securepassword';

Next, grant all the privileges to the LibreNMS database using the command below:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';

Finally, flush the privileges and exit from the MariaDB shell using the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Once you are done, you can proceed to the next step.

Install Nginx, PHP, and Required Dependencies

Next, you will need to install the Nginx web server, PHP, and other dependencies required by LibreNMS. You can install all of them by running the following command:

apt-get install nginx-full nmap php-cli php-curl php-fpm php-gd php-json php-mbstring php-mysql php-snmp php-xml php-zip python3-dotenv python3-pip python3-pymysql python3-redis python3-setuptools python3-systemd rrdtool snmp snmpd whois acl curl composer fping git graphviz imagemagick mtr-tiny

Once all the packages are installed, edit the php.ini file and set your time zone:

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

Change the following line:

date.timezone = UTC

Save and close the file when you are finished.

Install and Configure LibreNMS

First, create a dedicated user for LibreNMS using the following command:

useradd librenms -d /opt/librenms -M -r -s /bin/bash

Next, add the LibreNMS user to the www-data group with the following command:

usermod -a -G librenms www-data

Next, download the latest version of LibreNMS from the GitHub repository to the /opt directory:

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

Next, set ownership and permission of LibreNMS directory:

chown -R librenms:librenms /opt/librenms
chmod 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/

Next, change the user to LibreNMS with the following command:

su - librenms

Next, install the PHP composer using the following command:

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

Once the Composer and other PHP dependencies are installed, you should see the following output:

> @php artisan optimize
Configuration cache cleared!
Configuration cached successfully!
Route cache cleared!
Routes cached successfully!
Files cached successfully!
> @php artisan config:clear
Configuration cache cleared!
> scripts/dynamic_check_requirements.py || pip3 install --user -r requirements.txt || :
Requirement already satisfied: PyMySQL!=1.0.0 in /usr/lib/python3/dist-packages (from -r requirements.txt (line 1)) (0.9.3)
Requirement already satisfied: python-dotenv in /usr/lib/python3/dist-packages (from -r requirements.txt (line 2)) (0.15.0)
Requirement already satisfied: redis>=3.0 in /usr/lib/python3/dist-packages (from -r requirements.txt (line 3)) (3.5.3)
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from -r requirements.txt (line 4)) (52.0.0)
Collecting psutil>=5.6.0
  Downloading psutil-5.8.0-cp39-cp39-manylinux2010_x86_64.whl (293 kB)
Collecting command_runner>=1.3.0
  Downloading command_runner-1.3.0-py3-none-any.whl (17 kB)
Installing collected packages: psutil, command-runner
Successfully installed command-runner-1.3.0 psutil-5.8.0

Next, exit from the LibreNMS user using the command below:Advertisement

exit

Next, you will need to create a separate configuration file for PHP-FPM. You can create it with the following command:

cp /etc/php/7.4/fpm/pool.d/www.conf /etc/php/7.4/fpm/pool.d/librenms.conf

Next, edit the librenms.conf configuration file with your favorite editor:

nano /etc/php/7.4/fpm/pool.d/librenms.conf

Change [www-data] to [librenms] and also update the listening socket:

user = librenms
group = librenms
listen = /run/php-fpm-librenms.sock

Save and close the file then restart the PHP-FPM service to apply the configuration changes:

systemctl restart php7.4-fpm

Once you are finished, you can proceed to the next step.

Configure Nginx for LibreNMS

Next, you will need to create an 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 libre.yourdomain.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 ~ [^/]\.php(/|$) {
   fastcgi_pass unix:/run/php-fpm-librenms.sock;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   include fastcgi.conf;
  }
  location ~ /\.(?!well-known).* {
   deny all;
  }
}

Save and close the file then verify the Nginx for any syntax error with the following command:

nginx -t

If everything is fine, you will get the following output:

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

Finally, restart the Nginx to apply the changes.

systemctl restart nginx php7.4-fpm

You can also verify the Nginx status using the following command:

systemctl status nginx

You should see 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 Fri 2021-12-03 14:39:18 UTC; 18s ago
       Docs: man:nginx(8)
    Process: 39888 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 39892 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 39893 (nginx)
      Tasks: 2 (limit: 2341)
     Memory: 2.7M
        CPU: 42ms
     CGroup: /system.slice/nginx.service
             ??39893 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??39894 nginx: worker process

Dec 03 14:39:18 debian11 systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 03 14:39:18 debian11 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Dec 03 14:39:18 debian11 systemd[1]: Started A high performance web server and a reverse proxy server.

Next, copy the cron job configuration file to enable automatic discovery and polling for newly added devices.

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

Next, copy the logrotate configuration file to rotate the old logs.

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

Once you are finished, you can proceed to the next step.

Access LibreNMS Web Installation Wizard

At this point, LibreNMS is installed and configured with Nginx. You can now access the LibreNMS web-based setup using the URL http://libre.yourdomain.com. You should see the pre-install check page:

Make sure all checks are successfully then click on the database icon. You should see the database configuration page:

Provide your database information and click on the Check Credentials. You should see the following page:

Now,  click on the key icon to set up an admin user:

Provide your admin username, password then click on the Add User button. Once the user is created, you should see the following page:

Click on the Yes icon button. You should see the following page:

Now, open another tab in your web browser and type the URL https://libre.yourdomain.com/validate to validate the installation. You should see the following page:

Provide your admin username, password and click on the Login button. You should see the following page:

Conclusion

Congratulations! you have successfully installed LibreNMS with Nginx on Debian 11. You can now start to add remote devices to the LibreNMS and start monitoring them from the central location. Feel free to ask me if you have any questions.

Hitesh Jethva

About Hitesh Jethva

Over 8 years of experience as a Linux system administrator. My skills include a depth knowledge of Redhat/Centos, Ubuntu Nginx and Apache, Mysql, Subversion, Linux, Ubuntu, web hosting, web server, Squid proxy, NFS, FTP, DNS, Samba, LDAP, OpenVPN, Haproxy, Amazon web services, WHMCS, OpenStack Cloud, Postfix Mail Server, Security etc.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK