
Nagios is a monitoring system that tracks the availability and performance of network services, servers, and applications. Installing Nagios on Rocky Linux 9 enables users to run scheduled service checks for HTTP, SSH, disk usage, and system processes using plugins. Nagios Core is the central component of the Nagios system, responsible for executing monitoring checks, managing configurations, and handling notifications. Nagios Core triggers alerts if a service or host experiences an issue, such as downtime or a performance threshold breach.
This article explains how to install Nagios on Rocky Linux. You'll also configure Nagios to monitor services on a remote host.
Before you begin, you need to:
Nagios is not available in the default package repositories on Rocky Linux 9. Follow the steps below to compile and install the Nagios Core and its plugins.
Update the existing server packages.
On your Nagios server, install all required dependency packages.
This command installs compilers, libraries, and tools needed to compile Nagios Core and its plugins.
Navigate to the user's home directory.
Create a new nagios project directory to store Nagios Core files.
Navigate to the directory.
Visit the Nagios Core page and download the latest Nagios Core source code.
Install tar to extract the Nagios core.
Extract files from the downloaded archive.
Navigate to the extracted plugins directory.
Run the Nagios Core configuration script.
Compile Nagios Core.
Compile and create a Nagios system user and group.
Your output should be similar to the one below:
Add the apache user to the Nagios group to allow the Apache web server to interact with Nagios files and directories.
Nagios Core consists of essential binaries, configuration files, and system services that enable monitoring capabilities. Follow these steps to install Nagios on Rocky Linux 9.
Install the core Nagios binaries.
Install the init scripts required to start, stop, and manage Nagios as a service on your server.
Install the Nagios command mode package to allow access to external web-based commands.
Install the default Nagios configuration files.
Install the Apache configuration file to enable Nagios's web interface.
Verify the Nagios configuration to ensure there are no errors.
Your output should be similar to the one below:
Create a new vultr-admin user to access the web interface and set a strong password when prompted.
Your output should be similar to the one below:
Grant Apache access to the Nagios authentication file.
This allows the Apache web server to read the authentication credentials for the Nagios web interface.
Start the Nagios service.
Your output should be similar to the one below:
Enable Nagios to start automatically on system boot.
Verify the Nagios service is up and running.
Your output should be similar to the one below:
Allow HTTP traffic on port 80 through the firewall.
Output:
Reload the firewall to apply the new rules.
Enable Apache to start automatically when the system boots.
Restart both Nagios and Apache to apply the changes.
Nagios plugins allow Nagios to monitor various services, hosts, and resources. They acts as an executable script or binary that checks the status of a specific service or system component and returns the results to the Nagios core. Follow the steps below to install Nagios plugins.
Navigate to the Nagios directory you created.
Visit the the Nagios plugins page and download the latest Nagios plugins source code.
Extract files from the downloaded archive.
Navigate to the extracted plugins directory.
Run the Nagios plugins configuration script.
Compile the plugins.
Install the compiled plugins.
Restart both Nagios and Apache to apply the changes.
Follow the steps below to access the Nagios web monitoring dashboard using your Nagios server's public IP address.
Open a new tab in web browser and enter the following URL to access the Nagios web interface.
Replace <your-server-ip> with the actual IP address of your Rocky Linux server.
Enter the username vultr-admin and the password you configured. After logging in, the Nagios dashboard appears, as shown in the image below.
On the dashboard, navigate to side menu and click Tactical Overview to view a summary of monitored hosts, services, monitoring performance, and active alerts.
Click Event Log to check logs for events such as alerts, outages, and recovery logs.
Nagios enables you to monitor servers, routers, and other networked devices by defining them as hosts. The Nagios Remote Plugin Executor (NRPE) extends Nagios monitoring capabilities to remote hosts. It allows Nagios to execute plugins on remote machines, providing system metrics and resource monitoring when direct access is restricted.
Before Nagios can monitor a remote host, NRPE must be installed on it. NRPE listens for connection requests from a Nagios server, allowing remote monitoring of system metrics and resources. Follow the steps below to configure NRPE on your remote host.
Update the APT package index.
Install Nagios Remote Plugin Executor (NRPE) and Nagios plugins.
Open the NRPE configuration file using a text editor, such as vi.
Locate the allowed_hosts directive and add your Nagios server’s IP address.
Replace <nagios-server-ip> with the actual IP address of your Nagios server.
Start NRPE server.
Enable NRPE to start at boot.
Check NRPE service status.
Your output should be similar to the one below:
View the UFW status and verify that the firewall is active.
If the status is inactive, allow SSH connections to the server and start UFW.
The NRPE service listens on port 5666. Allow inbound connections on this port.
Output:
Reload UFW to apply the changes.
Output:
Follow the steps below to configure your Nagios server to monitor the remote host.
Install NRPE plugin.
Open the Nagios command configuration file.
Add the following custom command definition to the file.
This command definition allows the Nagios server to connect to the NRPE agent on a remote host, request the execution of specific monitoring plugins, and retrieve the results.
Save and close the file.
In the above configuration:
command_name: The name (check_nrpe) that Nagios uses to reference this command.
command_line: The actual command executed by Nagios, where:
/usr/lib64/nagios/plugins/check_nrpe runs the check_nrpe plugin.
-H $HOSTADDRESS$ specifies the target host's address.
-c $ARG1$ specifies the command for the remote host's NRPE agent to execute.
The NRPE service listens on port 5666. Allow inbound connections on this port.
Output:
Reload the firewall to apply the changes.
Output:
Create a new hosts configuration file for the remote host.
Add the following configuration to define the contact responsible for receiving notifications about host or service issues.
In the above configuration:
use generic-contact: Inherits properties from a pre-defined generic-contact template.contact_name vultr-admin: Assigns the name vultr-admin to the contact.alias Vultr Admin: Provides a descriptive label Vultr Admin, for the contact.email vultradmin@example.com: Specifies the email address for sending notifications. Feel free to replace the contact_name, alias, and email values with your information.
Add the following configuration to create a host block for a specific device to be monitored by Nagios.
In the above configuration:
use linux-server: Applies the default settings from the linux-server template for standard Linux configurations.host_name vultr-example: Sets a unique identifier for the host. Replace vultr-example with your hostname.address <ip-address>: Specifies the IP address of the host to be monitored. Replace <ip-address> with the actual IP.max_check_attempts 5: Retries failed checks up to 5 times before marking the host as down.check_period 24x7: Specifies that checks are performed 24 hours a day, 7 days a week.notification_interval 30: Sends notifications every 30 minutes during a problem state.notification_period 24x7: Defines when Nagios will send notifications, 24 hours a day, 7 days a week.The following configurations define service checks for the vultr-example host to monitor SSH connectivity, system load, and total processes.
Add the following configuration to monitor for SSH connectivity for the vultr-example host.
In the above configuration:
check_ssh plugin.Add the following configuration to define a System Load check for the vultr-example host to monitor its load levels.
In the above configuration:
Add the configuration below to define a Total Processes check for the vultr-example host to monitor the total number of processes running on the system.
In the above configuration:
Save and close the file.
Open Nagios configuration file with a text editor such as vi.
Add the following line to include the hosts.cfg file during startup.
Save and close the file.
Verify the Nagios configuration to ensure there are no errors.
Your output should be similar to the one below:
Restart Nagios to apply the changes.
In the Nagios Dashboard, navigate to the side menu and click Hosts. The newly configured remote host should appear in the list with a status of UP, indicating that the host is operational and accessible by the Nagios server.
Click the vultr-example host to view the Host State Information page.
This section provides detailed status information about the remote host.
Click View Status Detail For This Host in the Host State Information section to see the monitored services for vultr-example. Services with an OK status indicate successful checks.
Initially, statuses may show as PENDING due to a 2-minute check interval. Nagios updates statuses after the next scheduled check.
To view all monitored services, navigate to the Services option in the side menu. The displayed information includes localhost, representing your Rocky Linux server and its monitored services, as well as the remote host vultr-example and its monitored services.
You have successfully installed the Nagios on Rocky Linux, set up Nagios plugins, and configured remote host monitoring. With Nagios running, you can extend its capabilities by adding more hosts and services as needed. For enhanced monitoring, use the Nagios NRPE package on remote hosts and configure settings accordingly. For more information on Nagios, visit the official documentation.
0 Comments
Be the first to comment and share your perspective with the community.