A Guide to Monitoring Servers/Services with Nagios — Part 1

Kelom
7 min readAug 19, 2020

--

(INSTALLATION AND CONFIGURATION)

Imagine being a Sys Admin of mission-critical applications/servers, responsible for about 100 boxes (windows and linux), and you need to ensure system up-time of 99.8% throughout the year.

One afternoon, you leave the office for a meeting, upon your return, you realize a number of your systems were down, just imagine the frustration, the frustration of not knowing that your systems were down when you were away.

This is exactly what led to the building of Nagios Core, a free & open source monitoring tool, for monitoring systems and their services (CPU utilization, Disk utilization, Memory utilization, SMTP, HTTP, POP3, SNMP, ICMP, FTP, SSH etc) remotely and receiving alerts if any of these services went wrong.

Nagios Core

In part 1 of this tutorial, we are going to install & configure Nagios Core on Oracle Linux 7
Then in part 2, we will add a windows box for monitoring (read it here).
In part 3, we will add Linux box with MySQL database and monitor the MySQL database (read it here).
The final part, part 4 will handle notification (email alert) configuration.(read it here)

Let’s begin, prerequisite:

- Oracle Linux 7 environment.

Note: the commands might be different depending on which Linux you are using, e.g: yum install will be apt-get install on Ubuntu, etc

Step 1: login to the oracle Linux 7 environment as the root user, and configure the firewall to make Nagios web interface accessible from external machines by running the following command in the terminal:

sudo firewall-cmd --permanent --add-port=80/tcp
sudo systemctl restart firewalld

Step 2: We need to disable SELINUX by editing the config file located
at : /etc/selinux/ and changing SELINUX from enforcing to disabled:

vi /etc/selinux/config

save the changes and restart the server

Step 3: We need to install nagios’ dependent packages

yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp perl perl-devel openssl openssl-devel

Step 4: Download Nagios Core Source.

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.3.tar.gz

Step 5: Create Nagios and apache Users, Create Group and Add them to that group.

useradd Nagios
groupadd naggrp
usermod -a -G naggrp Nagios
usermod -a -G naggrp apache

Step 6: Unzip the download file from step 4, change directory to the folder containing the downloaded file and run this command:

tar -xvf nagios-4.4.3.tar.gz

Step 7: Compile Nagios from the source code. Change directory to the folder containing the unzipped file from step 6.

cd  nagios-4.4.3
./configure --with-command-group=naggrp
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
make install-exfoliation

Step 8: Still in the unzipped folder (/nagios-4.4.3/), Copy Evenhandler Files to /usr/local/nagios/libexec/

cp -rvf contrib/eventhandlers/ /usr/local/nagios/libexec/

Step 9: Change permissions of eventhandlers.

chown -R nagios:naggrp /usr/local/nagios/libexec/eventhandlers

Step 10: Creating a nagios user (for the web login) and Generating its password.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Enter the password

Step 11: Starting Web Service, enabling it to auto start on server reboot.
Start the webservice:

systemctl start httpd.service

enabling it to auto start on reboot:

systemctl enable httpd.service

check the status of web service, to be sure it is running:

systemctl status httpd.service

Step 12: Starting Nagios Service.
Start nagios servers

systemctl start nagios.service

enabling it to auto start on reboot:

systemctl enable nagios.service

check the status of nagios service to be sure it is running:

systemctl status nagios.service

Step 13: Download Nagios Plugins.

wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

Step 14: Unzip the downloaded Nagios Plugins. change directory to the folder containing the downloaded file. Run this command:

tar -xvf nagios-plugins-2.2.1.tar.gz

Step 15: Install Nagios Plugins. Change directory to the folder containing the unzipped files from step 14

cd nagios-plugins-2.2.1/
./configure — with-nagios-user=nagios — with-nagios-group=naggrp
make
make install

Step 16: Download the NRPE file, i am downloading it to the tmp folder.

wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz -P /tmp/

Step 17: Extract the NRPE Source File downloaded in step 16

tar zxvf nrpe-3.2.1.tar.gz

Step 18: Configure NRPE

./configure --enable-command-args --with-nrpe-user=nagios --with-nrpe-group=naggrp

Step 19: still in the /nrpe-3.2.1/ directory, run the following commands:

make all
make install
make install-config
make install-init

Nagios has been successfully installed and configured.
login to the nagios web interface by using the ip address of the nagios server followed by /nagios, mine is: http://192.168.20.131/nagios/

When asked for login credentials, use the credentials you created in step 10, i.e nagiosadmin and the password generated

Read: Part 2 - adding a windows box for monitoring

--

--