Install LibreNMS on Debian 11/Debian 10

0
41

Follow through this tutorial to learn how to install LibreNMS on Debian 11/Debian 10. LibreNMS is a fully featured MySQL/PHP and SNMP based network monitoring system.

Install LibreNMS on Debian 11/Debian 10

To install LibreNMS on Debian 11/Debian 10 proceed as follows;

  • Create LibreNMS system User Account

To begin with, create non privileged system user account for LibreNMS by executing the command below;

sudo useradd -d /opt/librenms -M -r -s /bin/bash librenms
  • Run system update;
sudo apt update
  • Install Required Packages

LibreNMS is requires L[E/A]MP stack. Hence, run the command below to install the Webserver, Nginx, PHP, MariaDB and other required packages. Nginx is the recommended web server to use.

The minimum supported PHP version is 7.3.

sudo apt install --no-install-recommends nginx-full php nmap mtr-tiny \
php-{cli,curl,fpm,gd,gmp,json,mbstring,mysql,snmp,xml,zip} \
rrdtool snmp snmpd whois unzip python3-pymysql python3-dotenv acl curl \
python3-redis python3-setuptools python3-systemd python3-pip git python3-dev \
mariadb-server mariadb-client composer fping graphviz imagemagick

if Apache is installed alongside the packages above, simply run the command below to remove it;

apt remove --purge --auto-remove apache2 -y
  • Create Database and Database User for LibreNMS

Run the initial security script to remove the test tables, disable remote root login, remove test tables/databases/anonymous users.

mysql_secure_installation

Next, login to MariaDB database and create a database and database user for LibreNMS. The names used here are not standard. Feel free to use any suitable name.

mysql -u root -p -e "create database librenmsdb character set utf8mb4 collate utf8mb4_unicode_ci"
mysql -u root -p -e "create user [email protected] identified by '[email protected]'"
mysql -u root -p -e "grant all on librenmsdb.* to [email protected]"
mysql -u root -p -e "flush privileges"

Configure InnoDB to use one tablespace file per InnoDB table and enable the preservation of the lettercase of database and table names;

sed -i.bak -e '/\[mysqld\]/a innodb_file_per_table=1\nlower_case_table_names=0' /etc/mysql/mariadb.conf.d/50-server.cnf
  • Install LibreNMS on Debian 11/Debian 10

Next, install LibreNMS by cloning its Github repository to home directory, /opt/librenms, defined above for the librenms user;

git clone https://github.com/librenms/librenms.git /opt/librenms
  • Set ownership, permission and access control lists for the LibreNMS directories and files;
chown -R librenms:librenms /opt/librenms
chmod 771 /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/
  • Install LibreNMS PHP dependencies

As user librenms, install required PHP dependencies;

sudo -Hiu librenms /opt/librenms/scripts/composer_wrapper.php install --no-dev
  • Set the Database Connection credentials
sudo -Hiu librenms vim /opt/librenms/.env
DB_HOST=localhost
DB_DATABASE=librenmsdb
DB_USERNAME=librenmsuser
[email protected]
  • Update System and PHP timezone;

Ensure that you update your system and PHP timezone accordingly.

timedatectl set-timezone America/Santiago
grep -irl ';date.timezone =' /etc/php/ | xargs -I {} sed -i.bak 's/;date.timezone =/date.timezone = America\/Santiago/' {}
  • Configure LibreNMS SNMPD

Copy the default SNMP configuration file;

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

Edit the SNMPD and update the community string.

vim /etc/snmp/snmpd.conf

Replace the RANDOMSTRINGGOESHERE with your string.

Save and exit the file

Next, download and install system distribution detection script;

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

Make the script executable;

chmod +x /usr/bin/distro

Start and enable SNMPD services;

systemctl enable --now snmpd
  • Install LibreNMS Cron Job

Copy the default cron job in place;

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

Enable Cron jobs log rotation;

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

Create global LibreNMS shortcuts;

ln -s /opt/librenms/lnms /usr/local/bin/lnms

Enable LibreNMS bash completion;

cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/

Import LibreNMS database schema into the database.

su - librenms
./lnms migrate
  • Create LibreNMS Nginx Site configuration file

Remove the default Nginx site configuration.

exit
rm -rf /etc/nginx/sites-enabled/default

Next, run the commands below to install LibreNMS Nginx site configuration. Be sure to replace the PHP-FPM socket path accordingly.

On Debian 10 with PHP 7.3;

cat > /etc/nginx/sites-enabled/librenms << 'EOL'
server {
 listen      80;
 server_name librenms.kifarunix-demo.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/php7.3-fpm.sock;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi.conf;
  fastcgi_read_timeout 240;
 }
 location ~ /\.(?!well-known).* {
  deny all;
 }
}
EOL

On Debian 11 with PHP 7.4;

cat > /etc/nginx/sites-enabled/librenms << 'EOL'
server {
 listen      80;
 server_name librenms.kifarunix-demo.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/php7.4-fpm.sock;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi.conf;
  fastcgi_read_timeout 240;
 }
 location ~ /\.(?!well-known).* {
  deny all;
 }
}
EOL

Change Nginx web user from www-data to librenms user;

sed -i.bak 's/www-data/librenms/' /etc/nginx/nginx.conf

Change the PHP FPM user from www-data to librenms user created above.

sed -i.bak 's/www-data/librenms/g' /etc/php/*/fpm/pool.d/www.conf
  • Restart Nginx and PHP-FPM services

Verify Nginx for any syntax;

nginx -t

Sample output if no errors;

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

Restart the services;

systemctl restart nginx php7.3-fpm
systemctl restart nginx php7.4-fpm

Enable to run on boot;

systemctl enable nginx php7.4-fpm
systemctl enable nginx php7.3-fpm

Check the status;

systemctl status nginx php7.4-fpm
systemctl status nginx php7.3-fpm
● 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 Mon 2022-05-30 12:50:14 -04; 18s ago
     Docs: man:nginx(8)
  Process: 7418 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 7419 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 7420 (nginx)
    Tasks: 3 (limit: 2359)
   Memory: 3.8M
   CGroup: /system.slice/nginx.service
           ├─7420 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           ├─7421 nginx: worker process
           └─7422 nginx: worker process

May 30 12:50:13 debian systemd[1]: Starting A high performance web server and a reverse proxy server...
May 30 12:50:14 debian systemd[1]: Started A high performance web server and a reverse proxy server.

● php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2022-05-30 12:50:14 -04; 17s ago
     Docs: man:php-fpm7.3(8)
 Main PID: 7423 (php-fpm7.3)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3 (limit: 2359)
   Memory: 11.6M
   CGroup: /system.slice/php7.3-fpm.service
           ├─7423 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
           ├─7424 php-fpm: pool www
           └─7425 php-fpm: pool www

May 30 12:50:14 debian systemd[1]: Starting The PHP 7.3 FastCGI Process Manager...
May 30 12:50:14 debian systemd[1]: Started The PHP 7.3 FastCGI Process Manager.
  • Finalize LibreNMS installation on Web Browser

Open Nginx web server on firewall if any is running.

ufw allow 80/tcp

Next, access LibreNMS using the url http://server-name.

LibreNMS Pre-install Checks;

install librenms debian

LibreNMS Database Connection Settings. We already supplied the credentials before, hence everything should be ok.

Install LibreNMS on Debian 11/Debian 10

Create LibreNMS Administrative User

Install LibreNMS on Debian 11/Debian 10

Click Finish install to finalize the LibreNMS setup.

Install LibreNMS on Debian 11/Debian 10

Validate LibreNMS installation by clicking the validate your install link.

validate librenms install

You should be redirected to the login page.

librenms login page

Validation will then proceed and results are displayed on the dashboard.

Install LibreNMS on Debian 11/Debian 10

You may see that there is a warning about hosts having not been added to LibreNMS yet.

Add Hosts to LibreNMS Server for Monitoring

That marks the end of our tutorial on how to install LibreNMS on Debian 11/Debian 10.

In the meantime, read more in the documentation page.

Other Tutorials

Install LibreNMS on Ubuntu 22.04/Ubuntu 20.04

Easily Install and Setup Cacti on Ubuntu 20.04

LEAVE A REPLY

Please enter your comment!
Please enter your name here