Nagios

How To Install Nagios On CentOS 9: A Step-by-Step Guide

Monitoring your network and systems is crucial for maintaining the health and performance of your IT environment. One of the most popular open-source tools for this purpose is Nagios. In this blog post, we’ll guide you through the process of installing Nagios on CentOS 9, ensuring that you can effectively monitor your systems with minimal hassle.

What is Nagios?

Nagios is a powerful monitoring system that enables you to keep track of your servers, network devices, and services. It provides alerting capabilities, allowing you to identify issues before they become critical, making it indispensable for systems administrators.

Prerequisites

Before we begin the installation, you need to ensure that you have the following prerequisites:

  • A server running CentOS 9 with a non-root user that has sudo privileges.
  • Basic knowledge of using the command line.
  • An up-to-date system: it’s essential to update your packages after installation.

Here’s how to get started with installing Nagios on CentOS 9.

Step 1: Update Your System

Start by updating your system packages. Open a terminal and execute:

sudo dnf update -y

Step 2: Install Required Packages

Nagios requires several additional packages for installation. Use the following command to install the necessary dependencies:

sudo dnf install -y gcc glibc glibc-common perl fromutils httpd php php-gd php-xml php-mbstring php-mysqlnd mariadb-server httpd-devel php-devel

Step 3: Create a Nagios User and Group

Next, you’ll need to create a user and group for Nagios. Run the following commands:

sudo useradd nagios
sudo useradd nagcmd -G nagios

This creates a user for Nagios and another user for command execution.

Step 4: Download and Install Nagios Core

Now let’s download the latest version of Nagios Core. Navigate to the Nagios downloads page and get the latest version link. Replace the version number in the command below as necessary:

cd /tmp
curl -O https://github.com/NagiosEnterprises/nagioscore/archive/refs/tags/nagios-4.4.6.tar.gz

Extract the downloaded file using:

tar zxvf nagios-4.4.6.tar.gz
cd nagioscore-nagios-4.4.6

Compile and install Nagios Core with the following commands:

./configure --with-command-group=nagcmd
make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode

Step 5: Configure Nagios

Edit the main Nagios configuration file. You can customize settings such as the hostname and email address for notifications.

sudo nano /usr/local/nagios/etc/nagios.cfg

Find and edit these lines, replacing with your details:

# Nagios Administrator Email
[email protected]

Step 6: Install the Nagios Web Interface

Next, you’ll need to install the web interface. Run:

sudo make install-webconf
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

You will be prompted to enter a password. This will create the user nagiosadmin for accessing the web interface.

Step 7: Configure SELinux (if enabled)

If SELinux is enabled, you must configure it to allow Nagios to run correctly. You can temporarily disable SELinux for checking:

sudo setenforce 0

To permanently configure it, edit /etc/selinux/config and change the line:

SELINUX=enforcing

to

SELINUX=permissive

Note: Be cautious while modifying SELinux settings. It’s recommended to consult your security policies.

Step 8: Start Nagios and Set it to Launch on Boot

Start the Nagios service and set it to start automatically on boot:

sudo systemctl start nagios
sudo systemctl enable nagios

Step 9: Start Apache Web Server

To access the Nagios web interface, you need to start the Apache web server:

sudo systemctl start httpd
sudo systemctl enable httpd

Step 10: Access the Nagios Web Interface

Open a web browser and navigate to:

http://your-server-ip/nagios

Log in using the username nagiosadmin and the password you set earlier.

Conclusion

Congratulations! You have successfully installed Nagios on CentOS 9. With Nagios up and running, you can begin monitoring your server’s health, services, and network. Regularly check for updates and consult the official Nagios documentation for advanced configurations and features.


At Greenhost.cloud, we strive to provide you with the best cloud-based solutions for your business needs. Stay tuned for more how-to guides and tips on optimizing your IT infrastructure!