Bobcares

How to Install and Configure Nagios on Ubuntu 24.04

by | Aug 22, 2024

Learn how to install and configure Nagios on Ubuntu 24.04. Our Server Management Support team is here to help you with your questions and concerns.

How to Install and Configure Nagios on Ubuntu 24.04

Nagios is an open-source, powerful monitoring system that acts as the watchdog for our IT infrastructure. It continuously monitors servers, services, and applications, and alerts our technical team to any issues before they escalate.

How to Install and Configure Nagios on Ubuntu 24.04

If we are looking to ensure the health and performance of our systems, installing Nagios on your Ubuntu 24.04 setup is an excellent choice.

An Overview:

  1. Ways to Install Nagios on Ubuntu 24.04
  2. Installing Nagios from the Default Ubuntu Repositories
  3. Building and Installing Nagios from Source on Ubuntu 24.04
  4. Accessing the Nagios Web Interface
  5. Installing Nagios Plugins
Ways to Install Nagios on Ubuntu 24.04

There are two primary methods to install Nagios on Ubuntu 24.04:

  1. Install Nagios from the Default Ubuntu Repositories

    This method is straightforward but might not always offer the latest stable release. For example, the current stable version is Nagios 4.5.2, but the Ubuntu 24.04 repositories may only offer version 4.4.6.

  2. Build Nagios from Source

    This method makes sure we get the latest stable version directly from Nagios. Although it’s more involved than using the default repositories, it gives us the most current features and updates.

Installing Nagios from the Default Ubuntu Repositories

We can install Nagios from the default Ubuntu repositories with these steps:

  1. First, check the Nagios version available in the repositories by running:

    apt-cache policy nagios4

    The output will let us know about the available version, such as 4.4.6.

    For example:

    nagios4:
    Installed: (none)
    Candidate: 4.4.6-4
    Version table:
    4.4.6-4 500
    500 http://de.archive.ubuntu.com/ubuntu noble/universe amd64 Packages

  2. Then, install Nagios by running this command:

    sudo apt install nagios4

Building and Installing Nagios from Source on Ubuntu 24.04

To install the latest version of Nagios, we need to build it from the source:

  1. First, update the system packages:

    sudo apt update

  2. Then, install the necessary tools and libraries:

    sudo apt install autoconf \
    gcc \
    libc6 \
    make \
    wget \
    unzip \
    apache2 \
    apache2-utils \
    php \
    libapache2-mod-php \
    libgd-dev \
    libssl-dev -y

  3. Next, head to the Nagios downloads page and download the latest source tarball. We need to replace `VER` with the latest version number:

    VER=4.5.2
    wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-${VER}.tar.gz

  4. Then, extract the downloaded archive and go to the source directory:

    tar xzf nagios-${VER}.tar.gz

    Now we should have the Nagios source directory in the current working directory:


    ls
    nagios-4.5.2 nagios-4.5.2.tar.gz

  5. Then, go to the Nagios source directory and run the configure script to adapt Nagios to our system while checking for any missing required dependency before the installation:

    cd nagios-${VER}

  6. Now, it is time to configure Nagios to use Apache as the web server:

    ./configure –with-httpd-conf=/etc/apache2/sites-enabled

    We can use ./configure –help for more options.

  7. Then compile and install Nagios:

    make all

  8. After that, create a Nagios user and group. Then, add the user to the Apache web server group.

    sudo make install-groups-users
    sudo usermod -aG nagios www-data

  9. Then, install the Nagios Server main program, CGIs, and HTML files.

    sudo make install

  10. After that, install Nagios Server startup scripts:

    sudo make install-init

    We can install and configure permissions on the directory for holding the external command file:

    sudo make install-commandmode

    Also, initialize the init scripts:

    sudo make install-daemoninit

    We can install Nagios Server sample configuration files in /usr/local/nagios/etc with this command:

    sudo make install-config

  11. Furthermore, we can install the Apache configuration file for the Nagios web interface:

    sudo make install-webconf

  12. Then, enable Apache modules and configure basic authentication:

    sudo a2enmod rewrite cgi

  13. Next, enable Apache rewrite and CGI modules:

    sudo a2dissite 000-default.conf

  14. Similarly, we can disable the default Apache site as seen here:

    sudo a2dissite 000-default.conf

  15. Now, configure Nagios Web Interface basic authentication:

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

    Here, nagiosadmin is the default admin user for accessing Nagios web interface. We can create or use any other user name and be sure to specify it in the /usr/local/nagios/etc/cgi.cfg configuration file.

    Furthermore, we can add more users by omitting option -c in the command above.

  16. Now, we can start and enable the Nagios service:

    sudo systemctl enable --now nagios

    If it was already running, we can restart it:

    sudo systemctl restart nagios

    We can check the status with this command:

    systemctl status nagios

Accessing the Nagios Web Interface

Once Nagios is installed and running, we can access the web interface by navigating to `http://>Nagios-Server-IP</nagios`. So, log in using the credentials set up during installation.

Installing Nagios Plugins

To start monitoring hosts, install the Nagios plugins:

sudo apt install monitoring-plugins

This will install a number of plugins under the directory, /usr/lib/nagios/plugins/.

Furthermore, Nagios installed from the source expects the plugins to reside under, /usr/local/nagios/libexec directory by default.

Hence, update the Nagios configuration to point to the correct plugin directory. So open the file:

sudo vim /usr/local/nagios/etc/resource.cfg

Then make the following changes:

# Sets $USER1$ to be the path to the plugins
# $USER1$=/usr/local/nagios/libexec
$USER1$=/usr/lib/nagios/plugins

 

Finally, reload the Nagios service to apply the changes:

sudo systemctl reload nagios.service

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

After the above steps, we will have a fully functioning Nagios server monitoring our Ubuntu 24.04 system. Whether we choose to install from the Ubuntu repositories or build from the source, Nagios offers robust monitoring to keep the infrastructure running smoothly.

In brief, our Support Experts how to install and configure Nagios on Ubuntu 24.04.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.