Introduction

Nagios is one of the most widely used open-source monitoring solutions for IT infrastructure. It helps system administrators monitor servers, network devices, applications, and services, providing real-time visibility into system health and performance. With Nagios, organizations can proactively detect issues, reduce downtime, and ensure the availability of critical services.

In this guide, we will walk through the installation and configuration of Nagios Core 4.3.2 on a CentOS 7 server. We will also install the required Nagios plugins, configure the web interface, and prepare the server for monitoring remote hosts using NRPE.

Prerequisites

  1. CentOS 7.0 Server (Fresh Installation)
  2. Root or sudo privileges
  3. Internet connectivity to download required packages and source files
  4. Basic knowledge of Linux command-line operations

Implementation

We assume that this is a fresh CentOS 7 server installation.

Disable SELinux

Temporarily disable SELinux:

setenforce 0

Disable SELinux permanently:

vi /etc/selinux/config
SELINUX=disabled

Install Required Dependencies

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

Create Nagios User and Group

useradd nagios
groupadd nagcmd

Add Nagios and Apache users to the nagcmd group:

usermod -G nagcmd nagios
usermod -G nagcmd apache

Download Nagios Core and Plugins

cd /usr/local/src/
wget https://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.3.2/nagios-4.3.2.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

Extract Source Files

tar -xzf nagios-4.3.2.tar.gz
tar -xzf nagios-plugins-2.2.1.tar.gz

Install Nagios Core

cd nagios-4.3.2
./configure --with-command-group=nagcmd

Compile and install:

make all
make install

Install initialization scripts and command mode:

make install-init
make install-commandmode

Install sample configuration files:

make install-config

Configuring Nagios

Configure Email Notifications

Edit the contacts configuration file:

vi /usr/local/nagios/etc/objects/contacts.cfg

Update the email address:

email                           nagios@domain.tld

Install Web Configuration

make install-webconf

Create Web Authentication User

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

Enter and confirm the password when prompted.

Start Apache Service

service httpd start

Install Nagios Plugins

cd /usr/local/src/nagios-plugins-2.2.1

Configure the plugins:

./configure --with-nagios-user=nagios --with-nagios-group=nagios

Compile and install:

make && make install

Enable Services on Boot

systemctl enable nagios
systemctl enable httpd

Start Nagios Service

service nagios start

Additional Configuration

Create a Directory for Host Configurations

mkdir /usr/local/nagios/etc/servers

Enable the Configuration Directory

Edit the Nagios configuration file:

vi /usr/local/nagios/etc/nagios.cfg

Uncomment the following line:

cfg_dir=/usr/local/nagios/etc/servers

Configure NRPE Command

Edit the commands configuration file:

vi /usr/local/nagios/etc/objects/commands.cfg

Add the following command definition:

###############################################################################
# NRPE CHECK COMMAND
#
# Command to use NRPE to check remote host systems
###############################################################################
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Verify Nagios Configuration

Run the configuration validation command:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If no errors are reported, restart Nagios:

/etc/init.d/nagios restart

Access the Nagios Web Interface

Open the following URL in your browser:

http://IPADDRESS/nagios

Log in using the nagiosadmin username and the password created earlier with the htpasswd command.

Conclusion

Nagios provides a powerful and flexible monitoring platform that enables administrators to monitor servers, services, applications, and network devices from a centralized dashboard. By following the steps outlined in this guide, you have successfully installed and configured Nagios Core on a CentOS 7 server, enabled the web interface, and prepared the environment for monitoring remote hosts using NRPE.

As a next step, consider adding monitored hosts, configuring service checks, setting up email alerts, and integrating performance monitoring plugins to maximize the effectiveness of your monitoring infrastructure. A well-configured Nagios deployment helps improve system reliability, reduces downtime, and ensures proactive issue detection across your environment.

Leave a Reply