CentOSRHEL Based

How To Install Nagios on CentOS Stream 10

Install Nagios on CentOS Stream 10

In today’s complex IT environments, robust network monitoring is essential for maintaining uptime and ensuring optimal performance. Nagios Core, a powerful and versatile open-source monitoring solution, provides real-time insights into your infrastructure. This guide offers a detailed, step-by-step walkthrough on how to install Nagios Core on CentOS Stream 10. Setting up Nagios on CentOS Stream 10 from source provides greater customization and control over your monitoring environment. Let’s dive in!

Introduction

Nagios is more than just a monitoring tool; it’s a proactive solution that alerts you to potential issues before they impact your users. Network administrators rely on Nagios to monitor network services, applications, operating systems, and system metrics. Nagios Core, the open-source foundation of the Nagios ecosystem, offers a flexible and scalable platform for comprehensive IT infrastructure monitoring. This article will guide you through the installation process on CentOS Stream 10, ensuring you have a solid foundation for your monitoring needs.

Installing from source provides the latest features, security patches, and customization options that pre-packaged installations might lack. You gain complete control over the configuration and integration of Nagios with your existing systems. You’ll learn how to compile, install, and configure Nagios Core and its plugins, providing you with the skills to adapt the monitoring solution to your specific requirements.

Prerequisites

Before starting the installation process, ensure that you have the following prerequisites in place. These are crucial for a successful Nagios Core installation on CentOS Stream 10.

  • CentOS Stream 10 Installed and Running: Begin with a clean and updated installation of CentOS Stream 10.
  • Root Access: You will need root or sudo privileges to install software and modify system configurations.
  • Basic Linux Command-Line Knowledge: Familiarity with basic Linux commands such as cd, ls, mkdir, and vi is essential.
  • A Running LAMP Stack: Nagios Core uses a LAMP (Linux, Apache, MariaDB/MySQL, PHP) stack to serve its web interface. Ensure that Apache, MariaDB/MySQL, and PHP are installed and configured correctly.

Each prerequisite plays a vital role. CentOS Stream 10 provides a stable and modern operating system environment. Root access allows you to perform administrative tasks necessary for installation. Command-line knowledge enables you to navigate the system effectively. The LAMP stack provides the necessary web server and scripting environment for Nagios Core to function correctly. If you don’t have a LAMP stack set up, install it before proceeding.

Preparing the System

Before installing Nagios Core, prepare your CentOS Stream 10 system with the necessary updates, packages, and configurations. This ensures a smooth and trouble-free installation process.

  1. Update the System:Update the package repositories and installed packages to the latest versions. This ensures you have the latest security patches and software updates.
    sudo dnf update -y
  2. Install Required Packages:Install the essential packages required for compiling and running Nagios Core and its plugins. These packages include compilers, libraries, and utilities necessary for the installation.
    sudo dnf install gcc glibc glibc-common make gettext automake autoconf gd gd-devel perl net-snmp net-snmp-utils openssl-devel epel-release wget tar

    Here’s a breakdown of the packages:

    • gcc: GNU Compiler Collection, essential for compiling source code.
    • glibc and glibc-common: GNU C Library, provides standard functions.
    • make: A build automation tool.
    • gettext: For localization and internationalization.
    • automake and autoconf: Tools for automatically generating makefiles.
    • gd and gd-devel: Graphics library for creating images.
    • perl: A scripting language used by some Nagios plugins.
    • net-snmp and net-snmp-utils: Simple Network Management Protocol tools.
    • openssl-devel: Secure Sockets Layer development libraries.
    • epel-release: Extra Packages for Enterprise Linux repository.
    • wget: A command-line tool for downloading files.
    • tar: A tool for archiving and extracting files.
  3. Enable Necessary Repositories:Enable the EPEL (Extra Packages for Enterprise Linux) and PowerTools repositories to access additional packages required for Nagios. Then install the perl-Net-SNMP package.
    sudo dnf --enablerepo=powertools,epel install perl-Net-SNMP
  4. Disable SELinux:SELinux (Security-Enhanced Linux) can interfere with Nagios Core’s operation. Disable it or set it to permissive mode. However, understand the security implications of doing so.
    sudo sed -i 's/SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
    sudo setenforce 0

    Setting SELinux to permissive mode allows the system to log violations without enforcing them. For production environments, consider configuring SELinux policies to allow Nagios Core to run without disabling it completely.

  5. Configure the Firewall:Configure the firewall to allow access to the Nagios Core web interface. This ensures that you can access the Nagios web interface from other machines on your network.
    sudo firewall-cmd --zone=public --add-service=http --permanent
    sudo firewall-cmd --zone=public --add-service=https --permanent
    sudo firewall-cmd --reload

    These commands open ports 80 (HTTP) and 443 (HTTPS) in the firewall, allowing web traffic to reach the Nagios Core web interface.

Setting Up the LAMP Stack

Nagios Core relies on a LAMP stack to serve its web interface and handle dynamic content. Ensure that Apache, PHP, and MariaDB/MySQL are properly installed and configured.

  1. Install Apache Web Server:Install the Apache web server, which will serve the Nagios Core web interface.
    sudo dnf install httpd

    Start and enable the Apache web server to ensure it starts automatically on boot.

    sudo systemctl start httpd
    sudo systemctl enable httpd
  2. Install PHP:Install PHP, a scripting language that Nagios Core uses for dynamic content generation.
    sudo dnf install php php-cli

    Nagios Core requires PHP to run its web interface and handle dynamic content. Ensure that PHP is installed and configured correctly.

  3. Secure Apache:Implement basic security measures to protect your Apache web server. These steps can help prevent common security vulnerabilities.
    • Disable Directory Listing: Prevent Apache from displaying directory contents.
    • Limit Access to Sensitive Files: Restrict access to sensitive files and directories.
    • Enable mod_security: Install and configure mod_security, a web application firewall.

Downloading Nagios Core and Nagios Plugins

Download the latest versions of Nagios Core and Nagios Plugins from the Nagios website or GitHub. These packages contain the source code and necessary files for installation.

  1. Create a Directory for Nagios Installation:Create a temporary directory to store the downloaded files.
    mkdir /tmp/nagios
    cd /tmp/nagios
  2. Download Nagios Core:Use wget to download the latest version of Nagios Core. Obtain the download URL from the Nagios website or GitHub releases page.
    wget -O nagioscore.tar.gz $(wget -q -O - https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest | grep '"browser_download_url":' | grep -o 'https://[^"]*')
  3. Download Nagios Plugins:Download the latest version of Nagios Plugins. Obtain the download URL from the Nagios website or GitHub releases page.
    wget --output-document="nagios-plugins.tar.gz" $(wget -q -O - https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest | grep '"browser_download_url":' | grep -o 'https://[^"]*')

Extracting the Source Code

Extract the downloaded source code archives to prepare for compilation and installation. This step unpacks the source code into directories that you can then configure and build.

  1. Extract Nagios Core:
    tar xzf nagioscore.tar.gz
  2. Extract Nagios Plugins:
    tar zxf nagios-plugins.tar.gz

Compiling and Installing Nagios Core

Compile and install Nagios Core from the extracted source code. This process involves configuring the build environment, compiling the source code, and installing the binaries and configuration files.

  1. Change Directory to the Nagios Core Source Directory:
    cd /tmp/nagios/nagioscore*
  2. Configure Nagios Core:Run the configure script to prepare the build environment. Use the --with-httpd-conf option to specify the Apache configuration directory.
    ./configure --with-httpd-conf=/etc/httpd/conf.d

    The --with-httpd-conf option tells the configure script where to install the Apache configuration file for Nagios Core.

  3. Compile the Source Code:
    make all
  4. Create Nagios User and Group:Create the nagios user and group, and add the Apache user to the nagios group.
    make install-groups-users
    usermod -a -G nagios apache

    These commands create the necessary user and group for Nagios Core to run securely. Adding the Apache user to the Nagios group allows Apache to execute Nagios commands.

  5. Install Nagios Binaries:
    make install
  6. Install Nagios Daemon:
    make install-daemoninit
  7. Install Command Mode:
    make install-commandmode
  8. Install Configuration Files:
    make install-config
  9. Install Web Configuration:
    make install-webconf

Compiling and Installing Nagios Plugins

Compile and install Nagios Plugins from the extracted source code. Nagios plugins are essential for monitoring various services and metrics on your network.

  1. Change Directory to the Nagios Plugins Source Directory:
    cd /tmp/nagios/nagios-plugins*
  2. Configure Nagios Plugins:Run the configure script to prepare the build environment. Specify the Nagios user and group.
    ./configure --with-nagios-user=nagios --with-nagios-group=nagios

    The --with-nagios-user and --with-nagios-group options ensure that the plugins have the correct permissions to run under the Nagios user.

  3. Compile the Source Code:
    make
  4. Install the Plugins:
    make install

Configuring Nagios

Configure Nagios Core to define monitored hosts, services, and notification settings. Proper configuration is crucial for effective monitoring.

  1. Create an Administrator User for the Nagios Web Interface:Create a user account to access the Nagios web interface. Use the htpasswd command to create a password file.
    sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

    This command creates a user named nagiosadmin and prompts you to enter a password. The -c option creates the password file if it doesn’t exist. Omit the -c option when adding additional users.

  2. Modify the Apache Configuration File:Modify the Apache configuration file to allow access to the Nagios web interface. Edit the /etc/httpd/conf.d/nagios.conf file and adjust the Require directives to grant access to the nagiosadmin user and your network.Example:
    <Directory "/usr/local/nagios/sbin">
       Options ExecCGI
       AllowOverride None
       Require all granted
    </Directory>
    
    <Directory "/usr/local/nagios/share">
       Options FollowSymLinks
       AllowOverride None
       Require all granted
    </Directory>

    These directives ensure that only authenticated users can access the Nagios web interface.

  3. Verify Nagios Configuration Files:Verify the Nagios configuration files for any errors before starting the Nagios service.
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    This command checks the Nagios configuration file for syntax errors and other issues. Address any errors before proceeding.

  4. Restart Apache:Restart the Apache web server to apply the changes to the configuration file.
    sudo systemctl restart httpd

Starting Nagios

Start the Nagios service and ensure it is running correctly. Enabling the service ensures that Nagios starts automatically on boot.

  1. Enable Nagios Service:
    sudo systemctl enable nagios
  2. Start Nagios Service:
    sudo systemctl start nagios
  3. Check Nagios Status:
    sudo systemctl status nagios

    This command displays the status of the Nagios service, including whether it is running, its process ID, and recent log messages. Look for any errors or warnings that might indicate a problem.

Accessing the Nagios Web Interface

Access the Nagios web interface through your web browser. Log in with the nagiosadmin user and the password you created earlier.

  1. Open a Web Browser:Navigate to the Nagios web interface using your server’s IP address or fully qualified domain name (FQDN).
    http://Your-server-IP-address/nagios
    http://FQDN/nagios
  2. Log In:Enter the username nagiosadmin and the password you created earlier. The Nagios web interface should now be accessible.

Install Nagios on CentOS Stream 10

Basic Nagios Usage

Explore the Nagios web interface and familiarize yourself with its main sections. This will help you understand how to monitor your hosts and services effectively.

  • Hosts: View the status of monitored hosts.
  • Services: View the status of monitored services.
  • Problems: View current problems and alerts.
  • Reports: Generate reports on Nagios performance.
  • Configuration: Configure Nagios settings.

To add a new host to monitor, define it in the /usr/local/nagios/etc/objects/hosts.cfg file. To configure a service to monitor, define it in the /usr/local/nagios/etc/objects/services.cfg file. Remember to verify the Nagios configuration and restart the Nagios service after making any changes.

Troubleshooting

Address common issues that may arise during or after the Nagios Core installation. Troubleshooting is a crucial skill for maintaining a healthy monitoring environment.

  • Nagios Not Starting:Check the Nagios log file (/usr/local/nagios/var/nagios.log) for errors. Verify that the Nagios configuration files are valid and that all necessary dependencies are installed.
  • Web Interface Not Accessible:Ensure that the Apache web server is running and that the firewall is configured to allow access to ports 80 and 443. Check the Apache error logs for any issues.
  • Incorrect Permissions:Verify that the Nagios user and group have the correct permissions on the Nagios directories and files. Use the chown and chmod commands to adjust permissions as needed.
  • Plugin Errors:Check the Nagios Plugins directory (/usr/local/nagios/libexec) to ensure that the necessary plugins are installed. Verify that the plugins have execute permissions and that they are configured correctly.

When troubleshooting, start by checking the Nagios logs for error messages. These logs often provide valuable clues about the cause of the problem. Use the testnag alias to quickly verify the Nagios configuration files for errors.

Congratulations! You have successfully installed Nagios. Thanks for using this tutorial to install Nagios Core on CentOS Stream 10. For additional help or useful information, we recommend you check the official Nagios website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button