{"id":12990,"date":"2022-05-31T22:57:50","date_gmt":"2022-05-31T19:57:50","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12990"},"modified":"2024-03-09T12:28:51","modified_gmt":"2024-03-09T09:28:51","slug":"install-librenms-on-rocky-linux","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-librenms-on-rocky-linux\/","title":{"rendered":"Install LibreNMS on Rocky Linux"},"content":{"rendered":"\n

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

Install LibreNMS on Rocky Linux<\/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 EPEL repository<\/h3>\n\n\n\n
sudo dnf install epel-release<\/code><\/pre>\n\n\n\n

Install Required Packages<\/h3>\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>. We will use PHP 7.4 in this tutorial.<\/p>\n\n\n\n

To be able to install PHP 7.4 on Rocky Linux, enable repo modules for PHP 7.4 as follows;<\/p>\n\n\n\n

sudo dnf module reset php<\/code><\/pre>\n\n\n\n
sudo dnf module enable php:7.4<\/code><\/pre>\n\n\n\n
sudo dnf install bash-completion cronie fping git httpd ImageMagick \\\nmariadb-server mtr net-snmp net-snmp-utils nmap php-fpm php-cli \\\nphp-common php-curl php-gd php-json php-mbstring php-process \\\nphp-snmp php-xml php-zip php-mysqlnd python3 python3-PyMySQL \\\npython3-devel python3-redis python3-memcached python3-pip \\\npython3-systemd rrdtool unzip policycoreutils-python-utils<\/code><\/pre>\n\n\n\n

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

Start and enable MariaDB server to run on system boot;<\/p>\n\n\n\n

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

Check status;<\/p>\n\n\n\n

systemctl status mariadb<\/code><\/pre>\n\n\n\n
\u25cf mariadb.service - MariaDB 10.3 database server\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/mariadb.service; enabled; vendor preset: disabled)\n   Active: active (running) since Tue 2022-05-31 13:23:16 EDT; 9s ago\n     Docs: man:mysqld(8)\n           https:\/\/mariadb.com\/kb\/en\/library\/systemd\/\n  Process: 38942 ExecStartPost=\/usr\/libexec\/mysql-check-upgrade (code=exited, status=0\/SUCCESS)\n  Process: 38872 ExecStartPre=\/usr\/libexec\/mysql-prepare-db-dir mariadb.service (code=exited, status=0\/SUCCESS)\n  Process: 38848 ExecStartPre=\/usr\/libexec\/mysql-check-socket (code=exited, status=0\/SUCCESS)\n Main PID: 38911 (mysqld)\n   Status: \"Taking your SQL requests now...\"\n    Tasks: 30 (limit: 11256)\n   Memory: 64.3M\n   CGroup: \/system.slice\/mariadb.service\n           \u2514\u250038911 \/usr\/libexec\/mysqld --basedir=\/usr\n\nMay 31 13:23:15 librenms.kifarunix-demo.com systemd[1]: mariadb.service: Succeeded.\nMay 31 13:23:15 librenms.kifarunix-demo.com systemd[1]: Stopped MariaDB 10.3 database server.\nMay 31 13:23:15 librenms.kifarunix-demo.com systemd[1]: Starting MariaDB 10.3 database server...\nMay 31 13:23:15 librenms.kifarunix-demo.com mysql-prepare-db-dir[38872]: Database MariaDB is probably initialized in \/var\/lib\/mysql already, nothing is done.\nMay 31 13:23:15 librenms.kifarunix-demo.com mysql-prepare-db-dir[38872]: If this is not the case, make sure the \/var\/lib\/mysql is empty before running mysql-prepare-db-dir.\nMay 31 13:23:15 librenms.kifarunix-demo.com mysqld[38911]: 2022-05-31 13:23:15 0 [Note] \/usr\/libexec\/mysqld (mysqld 10.3.32-MariaDB) starting as process 38911 ...\nMay 31 13:23:16 librenms.kifarunix-demo.com systemd[1]: Started MariaDB 10.3 database server.\n<\/code><\/pre>\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\/my.cnf.d\/mariadb-server.cnf<\/code><\/pre>\n\n\n\n

Restart MariaDB Service;<\/p>\n\n\n\n

sudo systemctl restart mariadb<\/code><\/pre>\n\n\n\n

Install LibreNMS<\/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;<\/p>\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
sed -i.bak 's\/;date.timezone =\/date.timezone = America\\\/Santiago\/' \/etc\/php.ini<\/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

Update LibreNMS SELinux Policies;<\/h3>\n\n\n\n
exit<\/code><\/pre>\n\n\n\n
semanage fcontext -a -t httpd_sys_content_t '\/opt\/librenms\/html(\/.*)?'<\/code><\/pre>\n\n\n\n
semanage fcontext -a -t httpd_sys_rw_content_t '\/opt\/librenms\/(logs|rrd|storage)(\/.*)?'<\/code><\/pre>\n\n\n\n
restorecon -RFvv \/opt\/librenms<\/code><\/pre>\n\n\n\n
setsebool -P httpd_can_sendmail=1<\/code><\/pre>\n\n\n\n
setsebool -P httpd_execmem 1<\/code><\/pre>\n\n\n\n
chcon -t httpd_sys_rw_content_t \/opt\/librenms\/.env<\/code><\/pre>\n\n\n\n
setsebool -P httpd_graceful_shutdown 1<\/code><\/pre>\n\n\n\n
setsebool -P httpd_can_network_connect 1<\/code><\/pre>\n\n\n\n
setsebool -P httpd_can_network_relay 1<\/code><\/pre>\n\n\n\n
setsebool -P nis_enabled 1<\/code><\/pre>\n\n\n\n

Be sure to always check the logs for any denied requests.<\/p>\n\n\n\n

tail -f \/var\/log\/audit\/audit.log | grep denied<\/code><\/pre>\n\n\n\n

Create LibreNMS Nginx Site configuration file<\/h3>\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

\ncat > \/etc\/nginx\/conf.d\/librenms.conf << '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-fpm\/www.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 nginx<\/strong><\/code> to librenms<\/code><\/strong> user;<\/p>\n\n\n\n

sed -i.bak 's\/nginx;\/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\/= apache\/= librenms\/g' \/etc\/php-fpm.d\/www.conf<\/code><\/pre>\n\n\n\n

Restart Nginx and PHP-FPM services<\/h3>\n\n\n\n

Verify Nginx for any syntax;<\/p>\n\n\n\n

nginx -t<\/code><\/pre>\n\n\n\n

Sample output if no errors;<\/p>\n\n\n\n

nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n\n\n\n

Restart the services;<\/p>\n\n\n\n

systemctl restart nginx php-fpm<\/code><\/pre>\n\n\n\n

Enable to run on boot;<\/p>\n\n\n\n

systemctl enable nginx php-fpm<\/code><\/pre>\n\n\n\n

Check the status;<\/p>\n\n\n\n

systemctl status nginx php-fpm<\/code><\/pre>\n\n\n\n
\u25cf nginx.service - The nginx HTTP and reverse proxy server\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/nginx.service; disabled; vendor preset: disabled)\n  Drop-In: \/usr\/lib\/systemd\/system\/nginx.service.d\n           \u2514\u2500php-fpm.conf\n   Active: active (running) since Tue 2022-05-31 14:20:29 -04; 6s ago\n  Process: 49866 ExecStart=\/usr\/sbin\/nginx (code=exited, status=0\/SUCCESS)\n  Process: 49860 ExecStartPre=\/usr\/sbin\/nginx -t (code=exited, status=0\/SUCCESS)\n  Process: 49857 ExecStartPre=\/usr\/bin\/rm -f \/run\/nginx.pid (code=exited, status=0\/SUCCESS)\n Main PID: 49867 (nginx)\n    Tasks: 3 (limit: 11256)\n   Memory: 5.1M\n   CGroup: \/system.slice\/nginx.service\n           \u251c\u250049867 nginx: master process \/usr\/sbin\/nginx\n           \u251c\u250049868 nginx: worker process\n           \u2514\u250049869 nginx: worker process\n\nMay 31 14:20:29 librenms.kifarunix-demo.com systemd[1]: Starting The nginx HTTP and reverse proxy server...\nMay 31 14:20:29 librenms.kifarunix-demo.com nginx[49860]: nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nMay 31 14:20:29 librenms.kifarunix-demo.com nginx[49860]: nginx: configuration file \/etc\/nginx\/nginx.conf test is successful\nMay 31 14:20:29 librenms.kifarunix-demo.com systemd[1]: Started The nginx HTTP and reverse proxy server.\n\n\u25cf php-fpm.service - The PHP FastCGI Process Manager\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/php-fpm.service; disabled; vendor preset: disabled)\n   Active: active (running) since Tue 2022-05-31 14:20:29 -04; 5s ago\n Main PID: 49863 (php-fpm)\n   Status: \"Ready to handle connections\"\n    Tasks: 6 (limit: 11256)\n   Memory: 17.2M\n   CGroup: \/system.slice\/php-fpm.service\n           \u251c\u250049863 php-fpm: master process (\/etc\/php-fpm.conf)\n           \u251c\u250049870 php-fpm: pool www\n           \u251c\u250049871 php-fpm: pool www\n           \u251c\u250049872 php-fpm: pool www\n           \u251c\u250049873 php-fpm: pool www\n           \u2514\u250049874 php-fpm: pool www\n\nMay 31 14:20:29 librenms.kifarunix-demo.com systemd[1]: php-fpm.service: Succeeded.\nMay 31 14:20:29 librenms.kifarunix-demo.com systemd[1]: Stopped The PHP FastCGI Process Manager.\nMay 31 14:20:29 librenms.kifarunix-demo.com systemd[1]: Starting The PHP FastCGI Process Manager...\nMay 31 14:20:29 librenms.kifarunix-demo.com systemd[1]: Started The PHP FastCGI Process Manager.\n<\/code><\/pre>\n\n\n\n

Finalize LibreNMS installation on Web Browser<\/h3>\n\n\n\n

Open Nginx web server on firewall if any is running.<\/p>\n\n\n\n

firewall-cmd --add-port={80,443}\/tcp --permanent\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\n

Next, access LibreNMS using the url http:\/\/server-name<\/strong>.<\/p>\n\n\n\n

LibreNMS Pre-install Checks;<\/p>\n\n\n\n

\"\"<\/figure><\/div><\/a><\/div>\n\n\n\n

LibreNMS Database Connection Settings. We already supplied the credentials before, hence everything should be ok.<\/p>\n\n\n\n

\"Install<\/figure><\/div><\/a><\/div>\n\n\n\n

Create LibreNMS Administrative User<\/p>\n\n\n\n

\"Install<\/figure><\/a><\/div>\n\n\n\n

Click Finish install<\/strong> to finalize the LibreNMS setup.<\/p>\n\n\n\n

\"Install<\/figure><\/div><\/a><\/div>\n\n\n\n

Validate LibreNMS installation by clicking the validate your install<\/strong> link.<\/p>\n\n\n\n

\"\"<\/figure><\/a><\/div>\n\n\n\n

You should be redirected to the login page.<\/p>\n\n\n\n

\"\"<\/figure><\/a><\/div>\n\n\n\n

Validation will then proceed and results are displayed on the dashboard.<\/p>\n\n\n\n

\"\"<\/figure><\/div><\/a><\/div>\n\n\n\n

If you experience SELnux issues with fping, you can sort as follows;<\/p>\n\n\n\n

cat > fping.pp << 'EOL'\nmodule fping 1.0;\n\nrequire {\ntype httpd_t;\nclass capability net_raw;\nclass rawip_socket { getopt create setopt write read };\n}\n\n#============= httpd_t ==============\nallow httpd_t self:capability net_raw;\nallow httpd_t self:rawip_socket { getopt create setopt write read };\nEOL\n<\/code><\/pre>\n\n\n\n

Next, install the fping SELinux policy modules;<\/p>\n\n\n\n

checkmodule -M -m -o fping.mod fping.tt<\/code><\/pre>\n\n\n\n
semodule_package -o fping.pp -m fping.mod<\/code><\/pre>\n\n\n\n
semodule -i fping.pp<\/code><\/pre>\n\n\n\n

You may see that there is a warning about hosts having not been added to LibreNMS yet.<\/p>\n\n\n\n

Add Hosts to LibreNMS Server for Monitoring<\/a><\/p>\n\n\n\n

That marks the end of our tutorial on how to install LibreNMS.<\/p>\n\n\n\n

In the meantime, read more in the documentation page<\/a>.<\/p>\n\n\n\n

Other Tutorials<\/h3>\n\n\n\n

Install LibreNMS on Ubuntu 22.04\/Ubuntu 20.04<\/a><\/p>\n\n\n\n

Easily Install and Setup Cacti on Ubuntu 20.04<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

Follow through this tutorial to learn how to install LibreNMS on Rocky Linux. LibreNMS is a fully featured MySQL\/PHP and SNMP based network monitoring system.<\/p>\n","protected":false},"author":1,"featured_media":12965,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[72,121],"tags":[5253,5257,5255,5254,5256],"class_list":["post-12990","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-monitoring","category-howtos","tag-install-librenms-on-rocky-linux","tag-librenms","tag-librenms-monitoring-server","tag-rocky-linux-librenms","tag-rocky-linux-librenms-monitoring-server","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12990"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=12990"}],"version-history":[{"count":12,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12990\/revisions"}],"predecessor-version":[{"id":20486,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12990\/revisions\/20486"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/12965"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=12990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=12990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=12990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}