Nagios Monitoring on a Dedicated Server: How-To
In this article
To monitor system performance on your dedicated server with Nagios, install the Nagios Core server on the machine (or a separate monitoring host), install the NRPE agent on the server you want to watch, and configure checks for CPU load, memory, disk usage, and running services. Nagios then polls those checks on a schedule, shows the results in its web interface, and alerts you by email or another notification method when something crosses a threshold. This guide walks through a practical setup on a Linux dedicated server, using the official Nagios Core and NRPE packages.
What You'll Need
- A Linux dedicated server with root or sudo access (the steps below use a Debian/Ubuntu-style system; package names differ slightly on RHEL/CentOS).
- The Nagios Core server software and its plugins package.
- The NRPE (Nagios Remote Plugin Executor) agent on each server you want to monitor.
- A web server (Apache or Nginx) for the Nagios web interface.
- A working mail transfer agent or SMTP relay if you want email alerts.
- Basic firewall access: port 80/443 for the web interface, and port 5666 for NRPE between the monitoring host and the monitored server.
Note that menu labels and package names can differ slightly by distribution, version, and region. Where a step depends on your distro, the text says so.
Step-by-Step
- Update the server and install prerequisites. Run your package manager's update command, then install the build tools, compilers, and libraries Nagios needs. On Debian/Ubuntu, install packages such as build-essential, libgd-dev, and openssl. On RHEL/CentOS, use the equivalent development packages. This step prevents compile errors later.
- Create a Nagios user and group. Create a dedicated system user (commonly named nagios) and a group (commonly nagcmd) so the web interface and the monitoring engine can communicate. Add your web server user to the nagcmd group.
- Download and compile Nagios Core. Get the official Nagios Core source tarball from the Nagios website, extract it, and run the configure script with the web interface and command group options. Then run make and make install, followed by the install-webconf and install-init steps. The exact configure flags are listed in the official installation guide and should be followed as written.
- Set up the web interface login. Create an htpasswd user for the Nagios web interface and place the password file where the web server configuration expects it. Restrict access to the Nagios directory in your web server config, then restart the web server.
- Start Nagios and verify the web interface. Start the Nagios service and check that it is running. Open the web interface in a browser and log in. You should see the default localhost checks. If the page does not load, check the web server error log and the Nagios service status.
- Install the Nagios plugins. Nagios Core does not include the check commands by itself; the plugins package provides check_load, check_disk, check_memory, check_http, and many others. Install the official plugins package for your distribution or compile it from source, then confirm the plugin directory path matches the one in your Nagios configuration.
- Install NRPE on the server to be monitored. If you are monitoring the same machine that runs Nagios, you can use local checks. For a separate dedicated server, install the NRPE agent and its plugins on that server. Open port 5666 only to the monitoring host's IP address in the firewall.
- Configure the NRPE checks. Edit the NRPE configuration file on the monitored server to define the commands you want to allow, such as check_load, check_disk, and check_memory, with your thresholds. Set the allowed_hosts entry to the Nagios server's IP. Restart NRPE and test from the Nagios server with the check_nrpe plugin.
- Define the host and services in Nagios. In the Nagios configuration directory, create a host definition for the server (address, hostname, check period) and service definitions for each check, pointing at check_nrpe with the command name and arguments. Keep custom files separate from the sample configuration so upgrades do not overwrite them.
- Set warning and critical thresholds. Choose values that reflect normal load on your hardware. For example, warn on disk usage above 80 percent and go critical above 90 percent; warn on load average above the number of CPU cores and go critical at twice that. These are starting points, not universal rules.
- Configure notifications. Set up a contact and contact group with an email address, assign them to the host and services, and make sure the server can send mail. Test with a forced notification before relying on it.
- Validate and reload the configuration. Run the Nagios configuration check command before every reload. If it reports errors, fix them before restarting, because a bad config can stop monitoring silently.
- Confirm checks are running. In the web interface, open the host and service detail pages and confirm the checks show recent timestamps and sensible output. A check stuck in PENDING or UNKNOWN usually means a command path or permission problem.
Common Mistakes
- Forgetting to open port 5666 only to the monitoring server, or opening it to the whole internet. NRPE should never be exposed publicly.
- Editing sample configuration files directly, so custom checks are lost on the next upgrade. Use separate files and include them from the main config.
- Setting thresholds so tight that normal spikes trigger alerts, which leads to alert fatigue and ignored warnings.
- Not testing email delivery, so notifications never arrive when a real problem occurs.
- Reloading Nagios without running the configuration check, which can leave the service down.
- Monitoring only the Nagios host itself and assuming remote servers are covered; each remote server needs its own host and service definitions.
Tips
- Monitor the basics first: disk space, memory, CPU load, and whether key services are running. Add application checks only after those are stable.
- Use different check intervals for different services; critical services can be checked more often than disk usage.
- Keep a short runbook next to each alert so whoever receives it knows what to check first.
- Review thresholds after a few weeks of data rather than guessing once and leaving them forever.
- Back up your Nagios configuration directory regularly; it is the part that takes longest to rebuild.
Troubleshooting
If the web interface does not load, check that the web server is running and that the Nagios configuration points to the correct CGI and HTML directories. If checks return UNKNOWN or connection refused, verify NRPE is running on the remote server, that the firewall allows the monitoring host, and that allowed_hosts includes the correct IP. If you see permission errors in the Nagios log, confirm the nagios user can read the plugin directory and execute the plugins. If notifications do not arrive, test the mail command from the server manually and check the contact definition is assigned to the service. If a check works from the command line but not in Nagios, compare the exact command and arguments; quoting and path differences are common causes. After any configuration change, run the configuration check and read the output before reloading.
Frequently Asked Questions
Can I run Nagios on the same server I am monitoring?
Yes. For a single dedicated server, Nagios Core and the plugins can run locally. Remote NRPE is mainly useful when one monitoring host watches several servers.
Do I need NRPE if Nagios is on the same machine?
No. Local checks run directly through the plugins. NRPE is for checks executed on a different machine.
What is the difference between Nagios Core and Nagios XI?
Nagios Core is the free, open-source monitoring engine configured through text files. Nagios XI is a separate commercial product with a web-based configuration interface. This guide covers Core.
How do I add a new check?
Define the command in an NRPE config on the monitored server, then add a service definition in Nagios that calls check_nrpe with that command name. Validate and reload the configuration.
Why does a check show PENDING?
The check has not run yet, or Nagios cannot execute it. Wait for the first scheduled interval, then check the Nagios log for command or permission errors.
Can Nagios monitor Windows servers too?
Yes, through a separate agent for Windows, but that is a different setup from the Linux NRPE steps here. Follow the official agent documentation for Windows hosts.