How to Install and Configure Nagios Core on RHEL 7

Nagios Core is one of the most widely deployed open-source infrastructure monitoring systems in the world. It provides comprehensive monitoring of hosts, services, and network devices, alerting administrators when things go wrong and when they recover. On RHEL 7, setting up Nagios Core from source gives you full control over the version and build options. This tutorial walks through every step from installing build dependencies to verifying your first monitored host through the Nagios web interface.

Prerequisites

  • RHEL 7 server with a static IP address and root or sudo access
  • Active internet connection or access to a local mirror
  • EPEL repository enabled (yum install epel-release)
  • Apache (httpd), PHP, GCC, OpenSSL, and development libraries
  • A registered hostname or IP for the web interface

Step 1: Install Required Dependencies

Nagios Core must be compiled from source, so you need a full build toolchain along with Apache and PHP for the web interface. Install all required packages with a single yum command.

sudo yum install -y gcc glibc glibc-common wget unzip httpd php gd 
  gd-devel perl postfix openssl openssl-devel make gettext autoconf 
  net-snmp net-snmp-utils epel-release

Start and enable Apache so it launches automatically at boot:

sudo systemctl start httpd
sudo systemctl enable httpd

Step 2: Create the Nagios User and Group

Nagios runs as a dedicated system user for security isolation. Create the nagios user and group, then add the Apache user (apache) to the nagcmd group so the web interface can submit external commands.

sudo useradd -m -s /bin/bash nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd apache

Step 3: Download and Compile Nagios Core

Download the Nagios Core source tarball. At the time of writing, version 4.4.x is the current stable release. Check the official Nagios GitHub releases page for the latest version number and substitute it below.

cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.14.tar.gz
tar -xzf nagios-4.4.14.tar.gz
cd nagios-4.4.14

Configure the build with the Nagios user, group, and command group, then compile and install:

./configure --with-command-group=nagcmd
make all
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
sudo make install-webconf

The make install-webconf step drops a Nagios Apache configuration file into /etc/httpd/conf.d/nagios.conf and links the CGI scripts into the Apache document root.

Step 4: Create the Nagios Web Admin Account

The web interface is protected by HTTP Basic Authentication. Use htpasswd to create an admin credential file. The -c flag creates the file; omit it for additional users.

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

Enter a strong password when prompted. This user maps to the authorized_for_all_* directives in nagios.cfg.

Step 5: Download and Install Nagios Plugins

Without plugins, Nagios cannot actually check anything. The official Nagios Plugins package provides over 50 standard checks covering ping, HTTP, disk, CPU, MySQL, and more.

cd /tmp
wget https://nagios-plugins.org/download/nagios-plugins-2.4.6.tar.gz
tar -xzf nagios-plugins-2.4.6.tar.gz
cd nagios-plugins-2.4.6
./configure --with-nagios-user=nagios --with-nagios-group=nagios 
            --with-openssl
make
sudo make install

Plugins are installed to /usr/local/nagios/libexec/. Verify a plugin works:

/usr/local/nagios/libexec/check_ping -H 127.0.0.1 -w 100,20% -c 500,60%

Step 6: Configure nagios.cfg and Object Files

The main configuration file is /usr/local/nagios/etc/nagios.cfg. It includes references to object configuration directories. Open it and verify the cfg_dir directive points to your objects folder:

grep cfg_dir /usr/local/nagios/etc/nagios.cfg

You should see at minimum:

cfg_dir=/usr/local/nagios/etc/objects

The sample objects directory already contains localhost.cfg, commands.cfg, contacts.cfg, templates.cfg, and timeperiods.cfg. Edit contacts.cfg to set your alert email address:

define contact {
    contact_name                    nagiosadmin
    use                             generic-contact
    alias                           Nagios Admin
    email                           [email protected]
}

Step 7: Add a Custom Host and Services

Create a new object file for your monitored server. It is best practice to keep each host in its own file inside the objects/ directory.

sudo tee /usr/local/nagios/etc/objects/webserver01.cfg <<'EOF'
define host {
    use                     linux-server
    host_name               webserver01
    alias                   Web Server 01
    address                 192.168.1.50
    max_check_attempts      5
    check_period            24x7
    notification_interval   30
    notification_period     24x7
}

define service {
    use                     generic-service
    host_name               webserver01
    service_description     HTTP
    check_command           check_http
    check_interval          5
    retry_interval          1
}

define service {
    use                     generic-service
    host_name               webserver01
    service_description     SSH
    check_command           check_ssh
    check_interval          5
    retry_interval          1
}
EOF

Register this file in nagios.cfg by adding:

echo "cfg_file=/usr/local/nagios/etc/objects/webserver01.cfg" | 
  sudo tee -a /usr/local/nagios/etc/nagios.cfg

Step 8: Validate the Configuration

Before starting the Nagios service, always validate the configuration to catch syntax errors. The -v flag runs a verification pass against every object file referenced in nagios.cfg.

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

A successful check ends with:

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

Fix any reported errors before proceeding. Common issues include undefined command references or incorrect file paths.

Step 9: Start Nagios and Configure Firewall

Enable and start the Nagios service, then open the firewall for HTTP access:

sudo systemctl enable nagios
sudo systemctl start nagios
sudo systemctl status nagios

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

If SELinux is enforcing, grant the web interface permission to execute the CGI scripts:

sudo setsebool -P httpd_enable_cgi 1
sudo chcon -R -t httpd_sys_script_exec_t /usr/local/nagios/sbin/
sudo chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

Step 10: Access the Web Interface

Open a browser and navigate to http://<your-server-ip>/nagios. Enter the username nagiosadmin and the password you set with htpasswd. The Nagios dashboard will display your monitored hosts and services. Click Hosts in the left sidebar to see the status of localhost and webserver01. Green indicates an OK state. If a service is shown as PENDING, Nagios is still running its initial check; wait a few minutes for results to populate.

Nagios Core on RHEL 7 gives you a robust, extensible monitoring platform built entirely from open-source components. From here you can expand coverage with NRPE (Nagios Remote Plugin Executor) for agent-based local checks on remote hosts, configure escalation policies in escalations.cfg, and add notification channels beyond email using event broker modules. The configuration-file-driven approach means your entire monitoring setup can be version-controlled and reproduced consistently across environments.