{"id":12979,"date":"2022-05-30T20:19:52","date_gmt":"2022-05-30T17:19:52","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12979"},"modified":"2024-03-09T12:31:44","modified_gmt":"2024-03-09T09:31:44","slug":"install-librenms-on-debian","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-librenms-on-debian\/","title":{"rendered":"Install LibreNMS on Debian 11\/Debian 10"},"content":{"rendered":"\n

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

Install LibreNMS on Debian 11\/Debian 10<\/h2>\n\n\n\n

Create LibreNMS system User Account<\/h3>\n\n\n\n

To begin with, create non privileged system user account for LibreNMS by executing the command below;<\/p>\n\n\n\n

sudo useradd -d \/opt\/librenms -M -r -s \/bin\/bash librenms<\/code><\/pre>\n\n\n\n

Install Required Packages<\/h3>\n\n\n\n

Run system update;<\/p>\n\n\n\n

sudo apt update<\/code><\/pre>\n\n\n\n

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.<\/p>\n\n\n\n

The minimum supported PHP version is 7.3<\/strong>.<\/p>\n\n\n\n

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

if Apache is installed alongside the packages above, simply run the command below to remove it;<\/p>\n\n\n\n

apt remove --purge --auto-remove apache2 -y<\/code><\/pre>\n\n\n\n

Create Database and Database User for LibreNMS<\/h3>\n\n\n\n

Run the initial security script to remove the test tables, disable remote root login, remove test tables\/databases\/anonymous users.<\/p>\n\n\n\n

mysql_secure_installation<\/code><\/pre>\n\n\n\n

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.<\/p>\n\n\n\n

mysql -u root -p -e \"create database librenmsdb character set utf8mb4 collate utf8mb4_unicode_ci\"<\/code><\/pre>\n\n\n\n
mysql -u root -p -e \"create user librenmsuser@localhost identified by 'StronGP@ssw0RD'\"<\/code><\/pre>\n\n\n\n
mysql -u root -p -e \"grant all on librenmsdb.* to librenmsuser@localhost\"<\/code><\/pre>\n\n\n\n
mysql -u root -p -e \"flush privileges\"<\/code><\/pre>\n\n\n\n

Configure InnoDB to use one tablespace file per InnoDB table and enable the preservation of the lettercase of database and table names;<\/p>\n\n\n\n

sed -i.bak -e '\/\\[mysqld\\]\/a innodb_file_per_table=1\\nlower_case_table_names=0' \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<\/code><\/pre>\n\n\n\n

Install LibreNMS on Debian<\/h3>\n\n\n\n

Next, install LibreNMS by cloning its Github repository to home directory, \/opt\/librenms<\/strong><\/code>, defined above for the librenms<\/strong> user;<\/p>\n\n\n\n

git clone https:\/\/github.com\/librenms\/librenms.git \/opt\/librenms<\/code><\/pre>\n\n\n\n

Set ownership, permission and access control lists for the LibreNMS directories and files;<\/h3>\n\n\n\n
chown -R librenms:librenms \/opt\/librenms\nchmod 771 \/opt\/librenms<\/code><\/pre>\n\n\n\n
setfacl -d -m g::rwx \/opt\/librenms\/rrd \/opt\/librenms\/logs \/opt\/librenms\/bootstrap\/cache\/ \/opt\/librenms\/storage\/<\/code><\/pre>\n\n\n\n
setfacl -R -m g::rwx \/opt\/librenms\/rrd \/opt\/librenms\/logs \/opt\/librenms\/bootstrap\/cache\/ \/opt\/librenms\/storage\/<\/code><\/pre>\n\n\n\n

Install LibreNMS PHP dependencies<\/h3>\n\n\n\n

As user librenms, install required PHP dependencies;<\/p>\n\n\n\n

sudo -Hiu librenms \/opt\/librenms\/scripts\/composer_wrapper.php install --no-dev<\/code><\/pre>\n\n\n\n

Set the Database Connection credentials<\/h3>\n\n\n\n
sudo -Hiu librenms vim \/opt\/librenms\/.env<\/code><\/pre>\n\n\n\n
DB_HOST=localhost\nDB_DATABASE=librenmsdb\nDB_USERNAME=librenmsuser\nDB_PASSWORD=StronGP@ssw0RD<\/code><\/pre>\n\n\n\n

Update System and PHP timezone;<\/h3>\n\n\n\n

Ensure that you update your system and PHP timezone accordingly.<\/p>\n\n\n\n

timedatectl set-timezone America\/Santiago<\/code><\/pre>\n\n\n\n
grep -irl ';date.timezone =' \/etc\/php\/ | xargs -I {} sed -i.bak 's\/;date.timezone =\/date.timezone = America\\\/Santiago\/' {}<\/code><\/pre>\n\n\n\n

Configure LibreNMS SNMPD<\/h3>\n\n\n\n

Copy the default SNMP configuration file;<\/p>\n\n\n\n

cp \/opt\/librenms\/snmpd.conf.example \/etc\/snmp\/snmpd.conf<\/code><\/pre>\n\n\n\n

Edit the SNMPD and update the community string.<\/p>\n\n\n\n

vim \/etc\/snmp\/snmpd.conf<\/code><\/pre>\n\n\n\n

Replace the RANDOMSTRINGGOESHERE<\/strong> with your string.<\/p>\n\n\n\n

Save and exit the file<\/p>\n\n\n\n

Next, download and install system distribution detection script;<\/p>\n\n\n\n

curl -o \/usr\/bin\/distro https:\/\/raw.githubusercontent.com\/librenms\/librenms-agent\/master\/snmp\/distro<\/code><\/pre>\n\n\n\n

Make the script executable;<\/p>\n\n\n\n

chmod +x \/usr\/bin\/distro<\/code><\/pre>\n\n\n\n

Start and enable SNMPD services;<\/p>\n\n\n\n

systemctl enable --now snmpd<\/code><\/pre>\n\n\n\n

Install LibreNMS Cron Job<\/h3>\n\n\n\n

Copy the default cron job in place;<\/p>\n\n\n\n

cp \/opt\/librenms\/librenms.nonroot.cron \/etc\/cron.d\/librenms<\/code><\/pre>\n\n\n\n

Enable Cron jobs log rotation;<\/p>\n\n\n\n

cp \/opt\/librenms\/misc\/librenms.logrotate \/etc\/logrotate.d\/librenms<\/code><\/pre>\n\n\n\n

Create global LibreNMS shortcuts;<\/p>\n\n\n\n

ln -s \/opt\/librenms\/lnms \/usr\/local\/bin\/lnms<\/code><\/pre>\n\n\n\n

Enable LibreNMS bash completion;<\/p>\n\n\n\n

cp \/opt\/librenms\/misc\/lnms-completion.bash \/etc\/bash_completion.d\/<\/code><\/pre>\n\n\n\n

Import LibreNMS database schema into the database.<\/p>\n\n\n\n

su - librenms<\/code><\/pre>\n\n\n\n
.\/lnms migrate<\/code><\/pre>\n\n\n\n

Create LibreNMS Nginx Site configuration file<\/h3>\n\n\n\n

Remove the default Nginx site configuration.<\/p>\n\n\n\n

exit<\/code><\/pre>\n\n\n\n
rm -rf \/etc\/nginx\/sites-enabled\/default<\/code><\/pre>\n\n\n\n

Next, run the commands below to install LibreNMS Nginx site configuration. Be sure to replace the PHP-FPM socket path accordingly.<\/strong><\/p>\n\n\n\n

On Debian 10 with PHP 7.3;<\/p>\n\n\n\n

\ncat > \/etc\/nginx\/sites-enabled\/librenms << 'EOL'\nserver {\n listen      80;\n server_name librenms.kifarunix-demo.com;\n root        \/opt\/librenms\/html;\n index       index.php;\n\n charset utf-8;\n gzip on;\n 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;\n location \/ {\n  try_files $uri $uri\/ \/index.php?$query_string;\n }\n location ~ [^\/]\\.php(\/|$) {\n  fastcgi_pass unix:\/run\/php\/php7.3-fpm.sock;\n  fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n  include fastcgi.conf;\n  fastcgi_read_timeout 240;\n }\n location ~ \/\\.(?!well-known).* {\n  deny all;\n }\n}\nEOL\n<\/code><\/pre>\n\n\n\n

On Debian 11 with PHP 7.4;<\/p>\n\n\n\n

\ncat > \/etc\/nginx\/sites-enabled\/librenms << 'EOL'\nserver {\n listen      80;\n server_name librenms.kifarunix-demo.com;\n root        \/opt\/librenms\/html;\n index       index.php;\n\n charset utf-8;\n gzip on;\n 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;\n location \/ {\n  try_files $uri $uri\/ \/index.php?$query_string;\n }\n location ~ [^\/]\\.php(\/|$) {\n  fastcgi_pass unix:\/run\/php\/php7.4-fpm.sock;\n  fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\n  include fastcgi.conf;\n  fastcgi_read_timeout 240;\n }\n location ~ \/\\.(?!well-known).* {\n  deny all;\n }\n}\nEOL\n<\/code><\/pre>\n\n\n\n

Change Nginx web user from www-data<\/strong><\/code> to librenms<\/code><\/strong> user;<\/p>\n\n\n\n

sed -i.bak 's\/www-data\/librenms\/' \/etc\/nginx\/nginx.conf<\/code><\/pre>\n\n\n\n

Change the PHP FPM user from www-data<\/code> to librenms<\/code><\/strong> user created above.<\/p>\n\n\n\n

sed -i.bak 's\/www-data\/librenms\/g' \/etc\/php\/*\/fpm\/pool.d\/www.conf<\/code><\/pre>\n\n\n\n