Step-by-Step Guide to Installing and Configuring Nagios on CentOS
This comprehensive tutorial walks you through installing and configuring Nagios on CentOS 6.8, covering system prerequisites, daemon, plugins, NRPE, web interface setup, client-side installations, configuration file management, and troubleshooting tips to achieve effective host and service monitoring.
Nagios System Overview
Nagios is an open‑source monitoring solution that can watch network devices (routers, switches, firewalls, printers, etc.) and servers (UNIX, Linux, Windows). It primarily uses the NRPE component for host and service checks, while also supporting SNMP.
Host or service status monitoring – monitors resources and services on devices that support SNMP or NRPE.
Alert notification – generates alerts and sends them via email, SMS, WeChat, or custom API scripts.
Visualization – combines with a web server to display monitoring data on web pages; PNP4Nagios can render graphs.
Data storage – stores results in flat files or MySQL‑compatible databases via NDOUtils.
Nagios Components
Nagios Daemon – core engine that coordinates all components.
Nagios Plugins – built‑in and custom scripts that collect data.
NRPE – remote agent that runs checks on monitored Linux hosts (listens on port 5666).
Web interface – provides a UI for viewing status and graphs.
Additional components – NDOUtils, NSCA, NSClient++ for distributed monitoring.
Installation Environment
Operating system: CentOS 6.8 (2.6.32‑642.el6.x86_64). Internet access is required for yum, Baidu, Google, etc. The following software groups and packages are needed (web server, PHP, GD, rrdtool, etc.).
Server‑Side Software Installation
Prerequisite : ensure the system can compile source packages and resolve dependencies. Install the following group packages:
Install Nagios dependencies (web server, PHP, GD, rrdtool, etc.).
Create the nagios user and group.
useradd nagios
groupadd nagiosAdd nagios and apache to a group that can receive web commands.
Compile and install Nagios Core (the daemon):
./configure
make
make installIf make all is prompted, run it to finish compilation.
Create the web UI account (default nagiosadmin) and set its password (stored in /usr/local/nagios/etc/htpasswd.users).
Restart the web service and enable it at boot.
Install plugins and the NRPE component on the server so it can monitor itself.
make install-plugin
make install-nrpeEnable Nagios and web services to start on boot.
Client‑Side Software Installation
On each monitored Linux host, install the Nagios plugins and NRPE, and configure xinetd to manage the NRPE daemon.
Create a nagios user on the client.
Extract the plugin tarball and place the binaries under /usr/local/nagios/libexec.
Install NRPE and configure /etc/xinetd.d/nrpe to allow connections from the Nagios server. only_from = 192.168.1.0/24 Add the NRPE service port (5666) to /etc/services. nrpe 5666/tcp #Nagios-Client Start xinetd and enable it at boot.
Verify the daemon is listening with ss -tnl and test from the server using the check_nrpe plugin.
Configuration Files
Nagios uses .cfg files located in /usr/local/nagios/etc and /usr/local/nagios/etc/objects to define hosts, services, commands, contacts, and time periods.
nagios.cfg – main daemon configuration (log settings, performance data, user/group, etc.).
templates.cfg – reusable templates for hosts, services, contacts.
commands.cfg – definitions of check commands (e.g., check_nrpe).
contacts.cfg – contact groups for alert notifications.
timeperiods.cfg – defines monitoring and notification windows.
localhost.cfg – monitors the Nagios server itself.
hosts.cfg – lists all remote hosts to be monitored.
services.cfg – lists services to be checked on each host.
After creating hosts.cfg and services.cfg, add their paths to nagios.cfg using the cfg_file directive.
Checking Configuration
Run Nagios' built‑in verification tool to validate syntax and logic, then reload the daemon:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios reloadClient‑Side NRPE Command Definition
Edit /etc/nagios/nrpe.cfg on each client to define the commands that the server may invoke via check_nrpe. After editing, restart the NRPE service.
service nrpe restartViewing Monitoring Data
Access the web UI at http://<em>nagios‑server‑ip</em>/nagios using the nagiosadmin credentials. The interface shows host status, service status, and graphs (if PNP4Nagios is installed). Adjust date_format in nagios.cfg to change timestamp display.
For troubleshooting, consult /var/log/messages or /usr/local/nagios/var/nagios.log. Common issues include missing SSL libraries for NRPE, missing SNMP packages, firewall or SELinux restrictions, and dependency problems during compilation.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
