Nagios is a powerful open-source monitoring tool that helps you monitor your servers, network devices, and applications. In this guide, we will walk you through the process of how to install and configure Nagios on Rocky Linux. By the end, you will have a fully functional Nagios setup to monitor your infrastructure.
Table of Contents
- Prerequisites
- Step 1: Install Required Dependencies
- Step 2: Download and Install Nagios
- Step 3: Configure Nagios
- Step 4: Set Up Apache for Nagios
- Step 5: Install Nagios Plugins
- Step 6: Verify and Start Nagios
- Step 7: Access Nagios Web Interface
- Step 8: Configure Email Notifications
- Conclusion
How to Install and Configure Nagios on Rocky Linux
Prerequisites
Before proceeding, make sure you have the following:
- A fresh installation of Rocky Linux
- A user with sudo privileges
- Access to a terminal or command-line interface
Install Required Dependencies on Rocky Linux
First, update your system and install the required dependencies:
sudo dnf update -y
sudo dnf install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release unzip httpd php
Download and Install Nagios on Rocky Linux
Download the latest version of Nagios Core from the official website:
cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.6.tar.gz
tar xzf nagioscore.tar.gz
Replace 4.x
with the actual version number of the latest Nagios Core release.
Next, compile and install Nagios:
cd /tmp/nagioscore-nagios-4.x
./configure --with-httpd-conf=/etc/httpd/conf.d
make all
sudo make install
Create a Nagios user and group:
sudo make install-groups-users
sudo usermod -a -G nagios apache
Set up the Nagios command configuration:
sudo make install-commandmode
Configure Nagios on Rocky Linux
Copy the Nagios sample configuration files:
sudo make install-config
Open the main Nagios configuration file:
sudo nano /usr/local/nagios/etc/nagios.cfg
Find the following line:
#cfg_dir=/usr/local/nagios/etc/servers
Uncomment it by removing the #
at the beginning of the line:
cfg_dir=/usr/local/nagios/etc/servers
Save and exit the file.
Create the servers
directory:
sudo mkdir /usr/local/nagios/etc/servers
Set Up Apache for Nagios on Rocky Linux
Install the Nagios web configuration:
sudo make install-webconf
Create a Nagios user for accessing the web interface:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
You will be prompted to enter a password for the nagiosadmin
user. Make sure to choose a strong and secure password.
Configure Nagios Core on Rocky Linux
Now that the Nagios Core has been installed, it is time to configure it. Start by editing the nagios.cfg
configuration file.
sudo nano /usr/local/nagios/etc/nagios.cfg
Find the line containing cfg_dir=/usr/local/nagios/etc/servers
and uncomment it by removing the #
at the beginning of the line. This will enable Nagios to monitor the servers defined in the servers
directory.
Next, create the servers
directory:
sudo mkdir /usr/local/nagios/etc/servers
Configure Nagios Plugins on Rocky Linux
With the Nagios Core configured, let’s proceed with configuring the Nagios Plugins. These plugins will help Nagios Core monitor various services and system metrics.
Edit the commands.cfg
file:
sudo nano /usr/local/nagios/etc/objects/commands.cfg
Add the following lines to the file to define the check_nrpe
command:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
Save the file and exit the editor.
Configure Apache for Nagios on Rocky Linux
To access the Nagios web interface, we need to configure Apache. First, create a new Apache configuration file:
sudo nano /etc/httpd/conf.d/nagios.conf
Add the following content to the file:
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Require all granted
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Require all granted
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Save the file and exit the editor. Then, restart the Apache service to apply the changes:
sudo systemctl restart httpd
Enable and start the Nagios service:
sudo systemctl enable --now nagios
Access Nagios Web Interface
Open your favorite web browser and navigate to the following URL:
http://your_server_ip/nagios
Replace your_server_ip
with the IP address of your Rocky Linux server. You will be prompted to enter the nagiosadmin
username and the password you set earlier. After successfully logging in, you should see the Nagios web interface.
Install NRPE and Configure Remote Hosts
To monitor remote hosts, you will need to install and configure the Nagios Remote Plugin Executor (NRPE) on each remote host. The installation process may vary depending on the remote host’s operating system. For detailed instructions on how to install NRPE on different systems, check out these guides: How to Install and configure ProFTPD on Rocky Linux, How to Install MongoDB on Rocky Linux and How to Install and Configure Lighttpd on Rocky Linux