How to Install and Configure Nagios on CentOS 7 for Monitoring
Nagios is a widely-used monitoring system for IT infrastructure. It allows you to monitor server resources, network services, and applications. In this guide, we’ll walk you through the process of installing and configuring Nagios on CentOS 7. The tutorial covers everything from the installation of Nagios Core and Plugins to setting up NRPE for remote monitoring and creating custom monitoring scripts.

Prerequisites for Installing Nagios on CentOS 7
Before you begin, ensure that you have the following prerequisites:
- A CentOS 7 server.
- LAMP stack (Linux, Apache, MySQL, PHP).
- Nagios 4.x installation package.
Additionally, if you’re looking for expert assistance in setting up and optimizing your DevOps, DevSecOps, or AIOps pipelines, ZippyOPS offers consulting and managed services. Visit ZippyOPS Services to learn more.
Step 1: Install Required Build Dependencies
First, install the necessary packages for building Nagios and its plugins:
sudo yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd unzip -y
This command will install essential development tools and libraries that Nagios needs.
Step 2: Create Nagios User and Group
Nagios requires specific user and group settings for proper operation:
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
These commands create the necessary nagios user and nagcmd group.
Step 3: Install Nagios Core
Next, download and install Nagios Core:
cd /opt
curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz
tar xvf nagios-*.tar.gz
cd nagios-*
./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
This step downloads, extracts, configures, and installs Nagios Core on your CentOS 7 server.
Step 4: Configure Apache Web Interface for Nagios
To access Nagios through a web browser, you’ll need to configure Apache:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
This creates the nagiosadmin user for accessing the Nagios web interface. If you choose a different username, make sure to update /usr/local/nagios/etc/cgi.cfg.
Step 5: Install Nagios Plugins
Nagios Plugins extend Nagios’ monitoring capabilities. To install them:
cd /opt
curl -L -O http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
tar xvf nagios-plugins-*.tar.gz
cd nagios-plugins-*
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make; sudo make install
This will install the plugins necessary for monitoring services.
Step 6: Install and Configure NRPE for Remote Monitoring
NRPE (Nagios Remote Plugin Executor) is essential for monitoring remote servers. Here’s how you can install it:
cd /opt
curl -L -O http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
tar xvf nrpe-*.tar.gz
cd nrpe-*
./configure --enable-command-args --with-nagios-user=nagios --with-nagios-group=nagios --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu
make all
sudo make install
sudo make install-xinetd
sudo make install-daemon-config
After installation, update the xinetd configuration to restrict access to only certain IP addresses:
sudo vi /etc/xinetd.d/nrpe
only_from = 127.0.0.1, 192.168.1.20
sudo service xinetd restart
Step 7: Configure Nagios Services and Commands
Now, you need to set up Nagios services and define monitoring commands. For example, to monitor the remote system using NRPE, you can modify the Nagios configuration files as follows:
sudo vi /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
Step 8: Configure Host and Service Definitions
To start monitoring hosts, you need to define them in Nagios configuration files:
sudo vi /usr/local/nagios/etc/servers/jiraExampleCom.cfg
# Host Definition
define host {
use linux-server
host_name jira.example.com
address 192.168.1.20
}
# Service Definition for Ping
define service {
use generic-service
host_name jira.example.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
Step 9: Start Nagios on CentOS 7 and Apache
Once everything is configured, start Nagios and Apache services:
sudo systemctl daemon-reload
sudo systemctl start nagios.service
sudo systemctl restart httpd.service
sudo chkconfig nagios on
Nagios should now be running, and you can access it via http://<your-server-ip>/nagios.
Step 10: Optional – Restrict Access by IP Address
For enhanced security, you can restrict access to the Nagios web interface to specific IP addresses:
sudo vi /etc/httpd/conf.d/nagios.conf
# Restrict access by IP
Order deny,allow
Deny from all
Allow from 192.168.1.20
Then restart Apache:
sudo systemctl restart httpd.service
Conclusion for Installing Nagios on CentOS 7
Installing Nagios on CentOS 7 allows you to monitor your infrastructure with ease. By following these steps, you can configure Nagios Core, Nagios Plugins, and NRPE for remote monitoring, ensuring that your systems stay under constant observation. If you need professional help with setting up complex environments like DevOps or Cloud Infrastructure, consider ZippyOPS. Our team provides expert consulting, implementation, and managed services across DevOps, DevSecOps, and AIOps. For more details, visit ZippyOPS Solutions.
For further assistance, reach out to us at sales@zippyops.com.



