LibreNMS is a free, open source and powerful network monitoring system based on the SNMP protocol. It supports all major distributions, including Linux, FreeBSD and network devices such as Cisco, Juniper, Brocade, Foundry and many more. It automatically detects your entire network via the CDP, FDP, LLDP, OSPF, BGP, SNMP and ARP protocols.
Features
- Comprehensive device support.
- Mobile-friendly web UI.
- Notification via email, Slack and Ic.
- Automatic updates and billing system.
- Supports multiple authentication methods such as LDAP, Active Directory, HTTP and MySQL.
- Support for distributed polling.
In this tutorial we explain how to install the LibreNMS monitoring system on CentOS 8 with Apache.
Prerequisites
- A server running CentOS 8.
- A root password is set up on your server.
Install the required dependencies
Before you start, you need to install the EPEL repository and other required dependencies on your system. You can install them all with the following command:
dnf install epel-release -y dnf install zip unzip git cronie wget fping net-snmp net-snmp-utils yum-utils nmap whois mtr rrdtool curl -y
Once all packages are installed, you can proceed to the next step.
Install LAMP server
Next, you need to install the Apache web server, MariaDB, PHP, and other PHP extensions in your system. You can install them all by running the following command:
dnf install httpd mariadb-server php php-cli php-common php-curl php-gd php-mbstring php-mysqlnd php-process php-snmp php-xml php-zip php-json -y
Once all packages are installed, start the Apache and MariaDB service and enable them so that they start after a system reboot:
systemctl start httpd systemctl enable httpd systemctl start mariadb systemctl enable mariadb
Configure MariaDB database
First secure the MariaDB installation with the following command:
mysql_secure_installation
Answer all questions as shown below:
Enter current password for root (enter for none): Set 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] Y Reload privilege tables now? [Y/n] Y
Once the MariaDB is secured, log into the MariaDB shell with the following command:
mysql -u root -p
Enter your MariaDB root password and create a database and user for LibreNMS with the following command:
MariaDB [(none)]> CREATE DATABASE libredb CHARACTER SET utf8 COLLATE utf8_unicode_ci; MariaDB [(none)]> CREATE USER 'libreuser'@'localhost' IDENTIFIED BY 'password';
Next, grant the LibreNMS database all permissions with the following command:
MariaDB [(none)]> GRANT ALL PRIVILEGES ON libredb.* TO 'libreuser'@'localhost';
Delete the authorizations and exit the MariaDB shell with the following command:
MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;
Now open the MariaDB configuration file and change some settings:
nano /etc/my.cnf.d/mariadb-server.cnf
Add the following lines to the [mysqld] section:
innodb_file_per_table=1 lower_case_table_names=0
Save and close the file. Then restart the MariaDB service to apply the changes:
systemctl restart mariadb
Install Composer
Composer is a dependency manager for PHP. It is used to install dependencies required by PHP-based applications.
First, download the Composer setup file with the following command:
curl -sS https://getcomposer.org/installer -o composer-setup.php
Next, use the following command to check whether the installation script is corrupted or not:
HASH="$(wget -q -O - https://composer.github.io/installer.sig)" php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
If everything is OK, you should get the following output:
Installer Verified
Next, run the following command to install Composer in the /usr/local/bin directory.
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
After the installation, you should get the following output:
All settings correct for using Composer Downloading... Composer (version 1.10.0) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer
Download LibreNMS
First, create a new user with the following command to run LibreNMS:
useradd librenms -d /var/www/html/librenms -M -r
Next, add the librenms user to the apache group using the following command:
usermod -a -G librenms apache
Next, change the directory to the Apache web root directory and download the latest version of LibreNMS with the following command.
cd /var/www/html git clone https://github.com/librenms/librenms.git
Next, use the following command to change the owner of the librenms directory to the librenms user:
chown -R librenms:librenms /var/www/html/librenms
Next, change the directory to librenms and install the PHP dependencies with the following command:
./scripts/composer_wrapper.php install --no-dev
Once all dependencies are installed, you should get the following output:
Discovered Package: darkghosthunter/larapoke Discovered Package: fideloper/proxy Discovered Package: laravel/laravel Discovered Package: laravel/tinker Discovered Package: martinlindhe/laravel-vue-i18n-generator Discovered Package: nesbot/carbon Discovered Package: oriceon/toastr-5-laravel Discovered Package: spatie/laravel-cors Discovered Package: tightenco/ziggy Package manifest generated successfully. > LibreNMSComposerHelper::postInstall setfacl -R -m g::rwx rrd/ logs/ storage/ bootstrap/cache/ setfacl -d -m g::rwx rrd/ logs/ storage/ bootstrap/cache/ php artisan key:generate Application key set successfully. > IlluminateFoundationComposerScripts::postInstall > @php artisan vue-i18n:generate --multi-locales --format=umd
Configure SNMP
Next, you need to copy the SNMP sample configuration file to the /etc/snmp directory. You can copy it with the following command:
cp /var/www/html/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
Next, open the /etc/snmp/snmpd.conf file as shown below:
nano /etc/snmp/snmpd.conf
Change your community string as shown below:
Save and close the file. Then download the script to identify the distribution version with the following command:
curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro chmod x /usr/bin/distro
Next, start the SNMP service and enable it with the following command so that it will start after the system reboots:
systemctl start snmpd systemctl enable snmpd
You can check the status of the SNMP service with the following command:
systemctl status snmpd
Output:
? snmpd.service - Simple Network Management Protocol (SNMP) Daemon. Loaded: loaded (/usr/lib/systemd/system/snmpd.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2020-03-13 08:37:40 EDT; 7s ago Main PID: 6562 (snmpd) Tasks: 1 (limit: 25028) Memory: 4.7M CGroup: /system.slice/snmpd.service ??6562 /usr/sbin/snmpd -LS0-6d -f Mar 13 08:37:40 centos8 systemd[1]: Stopped Simple Network Management Protocol (SNMP) Daemon.. Mar 13 08:37:40 centos8 systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon.... Mar 13 08:37:40 centos8 snmpd[6562]: NET-SNMP version 5.8 Mar 13 08:37:40 centos8 systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon..
Configure Apache for LibreNMS
Next, create a new configuration file for the LibreNMS virtual host with the following command:
nano /etc/httpd/conf.d/librenms.conf
Add the following lines:
DocumentRoot /var/www/html/librenms/html/ ServerName your-server-ip AllowEncodedSlashes NoDecode Require all granted AllowOverride All Options FollowSymLinks MultiViews
Save and close the file when you’re done. Then restart the Apache service to apply the changes:
systemctl restart httpd
Miscellaneous settings
Next, create a new file http_fping.tt to allow ping.
nano http_fping.tt
Add the following lines:
module http_fping 1.0; require { type httpd_t; class capability net_raw; class rawip_socket { getopt create setopt write read }; } #============= httpd_t ============== allow httpd_t self:capability net_raw; allow httpd_t self:rawip_socket { getopt create setopt write read };
Save and close the file and then execute the following command:
checkmodule -M -m -o http_fping.mod http_fping.tt semodule_package -o http_fping.pp -m http_fping.mod semodule -i http_fping.pp
Next, restart the Apache service to apply the changes:
systemctl restart httpd
Next, copy the LibreNMS cron and logrotate file with the following command:
cp /var/www/html/librenms/librenms.nonroot.cron /etc/cron.d/librenms cp /var/www/html/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
Next, create a new log file for LibreNMS with the following command:
touch /var/www/html/librenms/logs/librenms.log
Finally, set the correct permissions for LibreNMS with the following command:
chown librenms:librenms /var/www/html/librenms/logs/librenms.log chown -R librenms:librenms /var/www/html/librenms setfacl -d -m g::rwx /var/www/html/librenms/rrd /var/www/html/librenms/logs /var/www/html/librenms/bootstrap/cache/ /var/www/html/librenms/storage/ chmod -R ug=rwX /var/www/html/librenms/rrd /var/www/html/librenms/logs /var/www/html/librenms/bootstrap/cache/ /var/www/html/librenms/storage/ chmod -R 777 /var/www/html/librenms
Configure SELinux and firewall
SELinux is activated by default in CentOS 8. You must therefore set up the correct SELinux context for LibreNMS. You can do this with the following command:
semanage fcontext -a -t httpd_sys_content_t '/var/www/html/librenms/logs(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/librenms/logs(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/librenms/logs/librenms.log(/.*)?' restorecon -RFv /var/www/html/librenms/logs/librenms.log restorecon -RFvv /var/www/html/librenms/logs/ semanage fcontext -a -t httpd_sys_content_t '/var/www/html/librenms/rrd(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/librenms/rrd(/.*)?' restorecon -RFvv /var/www/html/librenms/rrd/ semanage fcontext -a -t httpd_sys_content_t '/var/www/html/librenms/storage(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/librenms/storage(/.*)?' restorecon -RFvv /var/www/html/librenms/storage/ semanage fcontext -a -t httpd_sys_content_t '/var/www/html/librenms/bootstrap/cache(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/librenms/bootstrap/cache(/.*)?' restorecon -RFvv /var/www/html/librenms/bootstrap/cache/ setsebool -P httpd_can_sendmail=1 restorecon -RFv /var/www/html/librenms setsebool httpd_can_network_connect on -P
Next, you need to allow ports 80 and 443 via firewalld. You can unblock them with the following command:
firewall-cmd --add-service=http --permanent firewall-cmd --add-service=https --permanent firewall-cmd --reload
When you are done with this, you can proceed to the next step.
Accessing the LibreNMS installation wizard
Now open your web browser and enter the URL http://your-server-ip. On the following screen you should see the LibreNMS pre-check wizard:
Confirm all checks and click the Next Step button. You should see the following screen:
Enter your database details and click the Next Stage button. You should see the following screen:
Click on the Go to Add user button. You should see the following screen:
Enter your desired admin username, email address and password and click the Add User button. Once the user has been successfully added. You should see the following screen:
Click on the Generate Config button to create a new configuration file for LibreNMS. Once the file has been created, you should see the following screen:
Copy the contents of the generated file from the above screen, open your terminal and paste it into the following file:
nano /var/www/html/librenms/config.php
Add the following lines that you copied from the installation wizard:
<?php ## Have a look in defaults.inc.php for examples of settings you can set here. DO NOT EDIT defaults.inc.php! ### Database config $config['db_host'] = 'localhost'; $config['db_port'] = '3306'; $config['db_user'] = 'libreuser'; $config['db_pass'] = 'password'; $config['db_name'] = 'libredb'; $config['db_socket'] = ''; // This is the user LibreNMS will run as //Please ensure this user is created and has the correct permissions to your install $config['user'] = 'librenms'; ### Locations - it is recommended to keep the default #$config['install_dir'] = "https://vitux.com/var/www/html/librenms"; ### This should *only* be set if you want to *force* a particular hostname/port ### It will prevent the web interface being usable form any other hostname #$config['base_url'] = "http://librenms.company.com"; ### Enable this to use rrdcached. Be sure rrd_dir is within the rrdcached dir ### and that your web server has permission to talk to rrdcached. #$config['rrdcached'] = "unix:/var/run/rrdcached.sock"; ### Default community $config['snmp']['community'] = array("public"); ### Authentication Model $config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth #$config['http_auth_guest'] = "guest"; # remember to configure this user if you use http-auth ### List of RFC1918 networks to allow scanning-based discovery #$config['nets'][] = "10.0.0.0/8"; #$config['nets'][] = "172.16.0.0/12"; #$config['nets'][] = "192.168.0.0/16"; # Update configuration #$config['update_channel'] = 'release'; # uncomment to follow the monthly release channel #$config['update'] = 0; # uncomment to completely disable updates
Save and close the file and change the owner of the file:
chown librenms:librenms /var/www/html/librenms/config.php
Now click on the ” Finishinstallation ” button to complete the installation of LibreNMS. You should see the following page:
Click on“Check your installation and fix any problems“. You will be redirected to the LibreNMS login screen:
Enter your LibreNMS admin username and password and click on the ” Login” button. On the following screen you will see the LibreNMS default dashboard:
Conclusion
Congratulations! You have successfully installed and configured LibreNMS on CentOS 8. Further information can be found in the LibreNMS documentation under LibreNMS.