How To - Install Libre NMS 2021-02 v22
How To - Install Libre NMS 2021-02 v22
How To - Install Libre NMS 2021-02 v22
Contents
Newer version CentOS 8 – in progress..................................................................................................2
How to Install LibreNMS on CentOS 8...................................................................................................2
Installation....................................................................................................................................2
Step 1: Pre-Requisites...............................................................................................................3
Step 2: SELinux..........................................................................................................................3
Step 3: Dependencies................................................................................................................4
Step 4: Setting up Database......................................................................................................5
Step 5: PHP-FPM and Nginx set up.........................................................................................7
Step 6: Miscellaneous:...............................................................................................................9
Step 7: Web Installer................................................................................................................11
Step 8: Adding a New Device..................................................................................................17
Minimal Install – CentOS 7 x6 [DualCore minimum), 4GB RAM , 16GB storage].................................20
Install Webtatic................................................................................................................................20
Install PHP – latest version..............................................................................................................20
Install initial packages......................................................................................................................20
Check the network is functioning as expected................................................................................20
Temporarily Disable Servers ‘Internal’ Firewall...............................................................................21
Download & Configure LibreNMS........................................................................................................22
Add LibreNMS User.........................................................................................................................22
Download LibreNMS........................................................................................................................22
Create a new directory for the LibreNMS logs and the rrd files:.....................................................22
Configure PHP-FPM for the installation of LibreNMS..........................................................................23
Open the PHP-FPM configuration file..............................................................................................24
Install WEBMIN....................................................................................................................................25
Check that WEBMIN is running ok...................................................................................................25
Install MariaDB server.........................................................................................................................25
Securing MariaDB server.................................................................................................................25
Define MariaDB SQL root password................................................................................................26
How To Configure MySQL................................................................................................................26
Configure NGINX..................................................................................................................................26
How to Configure the LibreNMS Virtual Host..................................................................................26
Install Fping.........................................................................................................................................28
Configure SNMPd................................................................................................................................28
Configure Cron job(s).......................................................................................................................28
Copy logrotate config......................................................................................................................28
Set permissions................................................................................................................................28
https://www.devopstutorials.io/how-to-install-librenms-on-centos-8/
It’s feature set includes automatic discovery, customizable alerts, API access, billing
system for ports on the network, automatic updates and many more. It also has
multiple authentication methods like MySQL, HTTP, LDAP, Radius, Active Directory.
We can also get the LibreNMS native Android and iOS app so that we can monitor
our devices while roaming everywhere.
Installation
For this tutorial, we will be using CentOS 8 as the host operating system. Here is a
brief overview of the steps we will be following in the tutorial.
Step 1: Pre-Requisites
Before we begin with the installation let us make sure that our system is up to date.
dnf -y update
Now let’s install all repos which are required to install LibreNMS on Centos 8. All
dependencies are found in both Epel and Remi repository. Remi repo to get the
latest PHP package and EPEL repo to satisfy the dependencies.
dnf update
Step 2: SELinux
Before we can start with our installation it is advised that we disable SELinux or set it
to permissive mode so that it will not hinder the installation process. To do this, we
will edit the SELinux config file.
nano /etc/selinux/config
Make sure to reboot your server after changing the SELinux config.
Step 3: Dependencies
Let’s install the packages required for LibreNMS to run on Ubuntu 20.
dnf install bash-completion cronie fping git ImageMagick mariadb-server mtr net-
snmp net-snmp-utils nginx nmap php-fpm php-cli php-common php-curl php-gd php-json
php-mbstring php-process php-snmp php-xml php-zip php-mysqlnd python3 python3-
PyMySQL python3-redis python3-memcached python3-pip rrdtool unzip
Finally, it’s time to clone the latest LibreNMS repo under /opt
Since we have a new user to manage LibreNMS, we are required to provide the user
with the privileges and set permissions for directories.
su - librenms
exit
mysql_secure_installation
Here we will:
We will now create our database which will be used by LibreNMS. First login as the
root user with the password you set.
mysql -u root -p
Next we are required to create a database and a user, Do not forget to change the
‘password’ below to something secure
FLUSH PRIVILEGES;
exit
nano /etc/my.cnf.d/mariadb-server.cnf
lower_case_table_names=0
For PHP-FPM to work with Nginx, we are required to make changes to the config file
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/librenms.conf
nano /etc/php-fpm.d/librenms.conf
[librenms]
user = librenms
group = librenms
listen = /run/php-fpm-librenms.sock
Now add the following lines in the librenms.conf file and replace server_name with
your IP Address or FQDN.
server {
listen 80;
server_name librenms.example.com;
root /opt/librenms/html;
index index.php;
charset utf-8;
gzip on;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi.conf;
location ~ /\.(?!well-known).* {
deny all;
Also, we should not forget to remove the default server section from the nginx.conf
file.
Here we
removed the contents of server section
Now start and enable the Nginx so that it will start with system restart
Step 6: Miscellaneous:
FIREWALLD ACCESS
We can either disable the firewalld
Or we can allow access through the firewalld by using the following commands.
SNMPD CONFIG
Copy the sample config file to its required destination
cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
nano /etc/snmp/snmpd.conf
Now we will run the following commands to get it set up and started
chmod +x /usr/bin/distro
CRON JOB
LibreNMS has it’s own cron jobs that are used to poll and discover the devices in
your network, copy it’s cron file and paste it inside /etc/cron.d directory.
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
LOGROTATE
LibreNMS logs can be found in /opt/librenms/logs directory which can grow up to be
quite large at some time in future. We can use the logrotate config provided to
counter this problem.
cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
TIMEZONES
It is important for each component that we have installed to work on the same
timezone as our server.
On CentOS
timedatectl
PHP-FPM
Time zone can be set in the php.ini file found in /etc
nano /etc/php.ini
Edit the date_timezone under the [Module Setting] section. Use the same timezone
as used above.
Now on your browser, open the address of your server, In our case, it was
192.168.122.86. Yours might be different. It will take you to the web interface for the
next steps in the setup process.
Next, it will build the Database. If you do not see any errors then we are good to go.
Now click on ‘validate your install and fix any issues’ To validate our install.
We will be using the same user we created in the web interface to login
We will be adding a Linux device running Debian 10. We will be using SNMP to
collect and organize information from our device
Now replace the snmpd.conf file with the example below. And also change the
community string appropriately.
#Distro Detection
Now we will head to the add device section in the Web Interface
Add your hostname or IP in its respective section. The default SNMP port is 161 so
we will enter the port as 161. At last enter the community string in the Community
section
After a few minutes, you will be able to see your device in the devices section.
You have successfully installed your LibreNMS server on Centos 8.Thank you for
reading this blog, if you guys have any questions or you got stuck anywhere please
feel free to mention in the comment section below
Install Webtatic
# yum -y update
# systemctl stop firewalld (temporarily stop the firewall {gets in the way early on!})
Once the user has been created and added to the respective group, we will go to the /opt/ directory and
download the LibreNMS source code using the git clone command as follows:
Download LibreNMS
# cd /opt
# composer create-project --no-dev --keep-vcs librenms/librenms librenms dev-master
Create a new directory for the LibreNMS logs and the rrd files:
Create a new directory for the LibreNMS logs and the rrd files:
# mkdir -p /opt/librenms/logs/
# mkdir -p /opt/librenms/rrd/
# chmod 775 /opt/librenms/rrd/
Change the ownership of all files and directories in the / opt / librenms directory to the librenms user and group
by executing the following:
May 02 23:05:07 nms.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy
server...
May 02 23:05:07 nms.localdomain nginx[25890]: nginx: the configuration file
/etc/nginx/nginx.conf syntax is ok
May 02 23:05:07 nms.localdomain nginx[25890]: nginx: configuration file /etc/nginx/nginx.conf
test is s...sful
May 02 23:05:07 nms.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.
Hint: Some lines were ellipsized, use -l to show in full.
# timedatectl
Open the loaded configuration file by PHP in an editor and replace *date.timezone with value from
‘timedatectl’ above.
# vi /etc/php.ini
Find the following lines, uncomment and change their values as shown.
cgi.fix_pathinfo= 0
memory_limit = -1
date.timezone = Europe/London
listen = 127.0.0.1:9000
Replace it with the following line.
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php7.2-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
Save the file and exit from the editor. Restart PHP-FPM and enable it to start at boot time.
Install WEBMIN
# vi /etc/yum.repos.d/webmin.repo
[Webmin]
name=Webmin Distribution Neutral
#baseurl=https://download.webmin.com/download/yum
mirrorlist=https://download.webmin.com/download/yum/mirrorlist
enabled=1
# wget http://www.webmin.com/jcameron-key.asc
# rpm --import jcameron-key.asc
# yum -y install webmin
# /etc/init.d/webmin stop
# /etc/init.d/webmin restart
May 03 04:07:54 nms.localdomain mysqld[4142]: 2018-05-03 4:07:54 140190332725376 [Note] InnoDB: 5.7.21...9987
May 03 04:07:54 nms.localdomain mysqld[4142]: 2018-05-03 4:07:54 140189125039872 [Note] InnoDB: Loadin...pool
May 03 04:07:54 nms.localdomain mysqld[4142]: 2018-05-03 4:07:54 140190332725376 [Note] Plugin 'FEEDBA...led.
May 03 04:07:54 nms.localdomain mysqld[4142]: 2018-05-03 4:07:54 140189125039872 [Note] InnoDB: Buffer...7:54
May 03 04:07:54 nms.localdomain mysqld[4142]: 2018-05-03 4:07:54 140190332725376 [Note] Server socket ...::'.
May 03 04:07:54 nms.localdomain mysqld[4142]: 2018-05-03 4:07:54 140190332725376 [Note] Reading of all...eded
May 03 04:07:54 nms.localdomain mysqld[4142]: 2018-05-03 4:07:54 140190332725376 [Note] Added new Mast...able
May 03 04:07:54 nms.localdomain mysqld[4142]: 2018-05-03 4:07:54 140190332725376 [Note] /usr/sbin/mysq...ons.
May 03 04:07:54 nms.localdomain mysqld[4142]: Version: '10.2.14-MariaDB' socket: '/var/lib/mysql/mysql...rver
May 03 04:07:54 nms.localdomain systemd[1]: Started MariaDB 10.2.14 database server.
Hint: Some lines were ellipsized, use -l to show in full.
Now, open the MySQL configuration file.
# mysql_secure_installation
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Create a new database called ‘librenms’, a new user ‘libreanms’ with password ‘password123’
MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]> exit <enter>
Bye
[mysqld]
innodb_file_per_table=1
sql-mode=""
lower_case_table_names=0
Configure NGINX
How to Configure the LibreNMS Virtual Host
LibreNMS is a Web-based application, and up to this point, we are using a Nginx web server to host it.
We will create a new virtual host file librenms.conf in the nginx conf.d directory by executing the following:
# vi /etc/nginx/conf.d/librenms.conf
In this new file we will paste the following:
server {
# LibreNMS logs
access_log /opt/librenms/logs/access_log;
error_log /opt/librenms/logs/error_log;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /api/v0 {
try_files $uri $uri/ /api_v0.php?$query_string;
}
location ~ /\.ht {
deny all;
}
}
Now you should delete the [server] section from the [/etc/nginx/nginx.conf] file
Remark out (#) each of the lines, as shown below…. then save the file
# vi /etc/nginx/nginx.conf
# server {
# listen 80 default_server;
# listen [::]:80 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
Install Fping
# vi /opt/librenms/http_fping.tt
require {
type httpd_t;
class capability net_raw;
class rawip_socket { getopt create setopt write read };
}
Configure SNMPd
# cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
# vi /etc/snmp/snmpd.conf
# cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
Set permissions
# chown -R librenms:librenms /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/
# cd /opt/librenms
# systemctl stop firewalld (temporarily stop the firewall {gets in the way early on!})
FIREWALL - ‘firewalld’
Configure Firewall in CentOS 7
# yum -y install firewalld
Once installed, we will start firewalld and enable it to run at boot with the following systemctl commands:
Once enabled, we will add the following lines to enable the respective services:
# firewall-cmd --reload
We can list the rules to confirm that the services have been added correctly:
# firewall-cmd --list-all
We will configure Nginx to use SSL generated with Let's Encrypt free SSL.
Before you can request the certificates, you will need to allow port 80 and 443, or
standard HTTP and HTTPS services through the firewall.
Installing ClamAV
# yum -y install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-
scanner-systemd clamav-devel clamav-lib clamav-server-systemd
# setsebool -P antivirus_can_scan_system 1
# setsebool -P clamd_use_jit 1
antivirus_can_scan_system --> on
antivirus_use_jit --> on
Before Clam configuration can be enabled, you need to remove Example string from the configuration file:
Next, you will have to specify the server type. Open configuration file with your favorite text editor, in this example
we will use nano. If it’s not already installed, install it using yum:
# vi /etc/clamd.d/scan.conf
#LocalSocket /var/run/clamd.scan/clamd.sock
LocalSocket /var/run/clamd.scan/clamd.sock
Save the changes by hitting CTRL + X shortcut (or COMMAND+X if you are on MAC).
Almost done, now remove Example string from ClamAV’s freshclam update engine configuration file:
# freshclam
Install Certbot, which is the client application for Let's Encrypt CA.
The SSL certificate will be stored as fullchain.pem and private key will be stored as privkey.pem.
# vi /etc/nginx/conf.d/nms.example.com.conf <enter>
server {
listen 80;
# server_name nms.localdomain; *remove the < > from below, replacing with registered domain
server_name <nms.domain.org>;
return 301 https://$host$request_uri;
}
server {
listen 443;
# server_name nms.localdomain;
server_name nms.welovebees.cloudns.org;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
access_log /opt/librenms/logs/librenms.nginx.access.log;
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 /api/v0 {
try_files $uri $uri/ /api_v0.php?$query_string;
}
location ~ \.php {
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}