Install and Configure Nagios Server
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
- CentOS 7.0 Server (Fresh Installation)
- Root or sudo privileges
- Internet connectivity to download required packages and source files
- 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 0Disable SELinux permanently:
vi /etc/selinux/configSELINUX=disabledInstall Required Dependencies
yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmpCreate Nagios User and Group
useradd nagios
groupadd nagcmdAdd Nagios and Apache users to the nagcmd group:
usermod -G nagcmd nagios
usermod -G nagcmd apacheDownload 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.gzExtract Source Files
tar -xzf nagios-4.3.2.tar.gz
tar -xzf nagios-plugins-2.2.1.tar.gzInstall Nagios Core
cd nagios-4.3.2
./configure --with-command-group=nagcmdCompile and install:
make all
make installInstall initialization scripts and command mode:
make install-init
make install-commandmodeInstall sample configuration files:
make install-configConfiguring Nagios
Configure Email Notifications
Edit the contacts configuration file:
vi /usr/local/nagios/etc/objects/contacts.cfgUpdate the email address:
email nagios@domain.tldInstall Web Configuration
make install-webconfCreate Web Authentication User
htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadminEnter and confirm the password when prompted.
Start Apache Service
service httpd startInstall Nagios Plugins
cd /usr/local/src/nagios-plugins-2.2.1Configure the plugins:
./configure --with-nagios-user=nagios --with-nagios-group=nagiosCompile and install:
make && make installEnable Services on Boot
systemctl enable nagios
systemctl enable httpdStart Nagios Service
service nagios startAdditional Configuration
Create a Directory for Host Configurations
mkdir /usr/local/nagios/etc/serversEnable the Configuration Directory
Edit the Nagios configuration file:
vi /usr/local/nagios/etc/nagios.cfgUncomment the following line:
cfg_dir=/usr/local/nagios/etc/serversConfigure NRPE Command
Edit the commands configuration file:
vi /usr/local/nagios/etc/objects/commands.cfgAdd 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.cfgIf no errors are reported, restart Nagios:
/etc/init.d/nagios restartAccess the Nagios Web Interface
Open the following URL in your browser:
http://IPADDRESS/nagiosLog 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.
