Install and Setup Nagios on Ubuntu 22.04

Last Updated:

In this guide, we will provide a step-by-step tutorial on how to install and setup Nagios on Ubuntu 22.04. Nagios, now known as, Nagios Core, is an enterprise-class Open Source IT monitoring, network monitoring, server and applications monitoring solution.

Install and Setup Nagios on Ubuntu 22.04

There are two ways in which you can install Nagios on Ubuntu 22.04.

Install Nagios from APT on Ubuntu

As much it is easier to install Nagios from Ubuntu repos, sometimes the repos do not provide the latest stable release versions of Nagios. Take for example, Nagios 4.x is the current versions of Nagios with Nagios 4.4.7 release being the latest stable version as per the releases page.

If you check the available versions on Ubuntu 22.04 repos, Nagios 4.4.6 is the latest stable release.

apt-cache policy nagios4
  Installed: (none)
  Candidate: 4.4.6-4
  Version table:
     4.4.6-4 500
        500 jammy/universe amd64 Packages

You can check similar installation here;

Install Nagios on Debian 11

Install Nagios from Source on Ubuntu 22.04

This is the only way to ensure that you install the current and latest stable release version of Nagios.

Run System Update

Ensure that your system packages are up-to-date.

apt update

Install Required Nagios build tools and Development Libraries

Run the command below to install the required built tools and development libraries.

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

Download Nagios Source Code

Navigate to Nagios download’s page and grab the latest and stable release Nagios source tarball. Simply grab the link and optionally pull it using wget command;


Extract Nagios Source Code

Once the download completes, extract the source archive;

tar xzf nagios-4.4.7.tar.gz

You should now have Nagios source directory in the current working directory;

nagios-4.4.7 nagios-4.4.7.tar.gz

Compile and Install Nagios on Ubuntu 22.04

Navigate to Nagios source directory and run the configure script to adapt Nagios to your system while checking for any missing required dependency before the installation;

cd nagios-4.4.7

Configure Nagios to use Apache as the web server. Use the --with-httpd-conf to specify where to install Nagios Apache site configs. Be sure to use ./configure --help for more options.

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

Pay attention to the output of this command just in case there is any error that needs to be fixed before you can proceed.

If all is well, you should an output similar to;

*** Configuration summary for nagios 4.4.7 2022-04-14 ***:

 General Options:
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  /run/nagios.lock
   Check result directory:  /usr/local/nagios/var/spool/checkresults
           Init directory:  /lib/systemd/system
  Apache conf.d directory:  /etc/apache2/sites-enabled
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  

Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

Next, compile the main Nagios program and CGIs.

make all

Create Nagios user and group. Add the user to the Apache web server group.

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

Install Nagios main program, CGIs, and HTML files.

make install

Install Nagios startup scripts;

make install-init

Initialize the init scripts;

make install-daemoninit

Install and configure permissions on the directory for holding the Nagios external command file.

make install-commandmode

Install Nagios sample configuration files in /usr/local/nagios/etc.

make install-config

Install Apache configuration file for the Nagios web interface

make install-webconf

Enable Apache rewrite and CGI modules;

a2enmod rewrite cgi

Configure Nagios Web Interface basic authentication.

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

Where nagiosadmin is the default admin user for accessing Nagios web interface (as specified in the cgi.cfg). You can create or use any other user name and be sure to specify it in the /usr/local/nagios/etc/cgi.cfg configuration file.

If you need to add more users, omit option -c in the command above.

We are almost done setting up Nagios on Ubuntu 22.04.

Running Nagios Service

The make install-init command, install systemd service units for Nagios Core. You can start and enable Nagios to run on system boot by running the command;

systemctl enable --now nagios

If it was already running, then restart it;

systemctl restart nagios

To check the status;

systemctl status nagios
● nagios.service - Nagios Core 4.4.7
     Loaded: loaded (/lib/systemd/system/nagios.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-05-04 17:18:52 UTC; 1s ago
    Process: 15854 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
    Process: 15855 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
   Main PID: 15856 (nagios)
      Tasks: 6 (limit: 2241)
     Memory: 5.2M
        CPU: 355ms
     CGroup: /system.slice/nagios.service
             ├─15856 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
             ├─15857 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─15858 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─15859 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─15860 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             └─15861 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

May 04 17:18:52 jellyfish nagios[15856]: qh: core query handler registered
May 04 17:18:52 jellyfish nagios[15856]: qh: echo service query handler registered
May 04 17:18:52 jellyfish nagios[15856]: qh: help for the query handler registered
May 04 17:18:52 jellyfish nagios[15856]: wproc: Successfully registered manager as @wproc with query handler
May 04 17:18:52 jellyfish nagios[15856]: wproc: Registry request: name=Core Worker 15858;pid=15858
May 04 17:18:52 jellyfish nagios[15856]: wproc: Registry request: name=Core Worker 15857;pid=15857
May 04 17:18:52 jellyfish nagios[15856]: wproc: Registry request: name=Core Worker 15860;pid=15860
May 04 17:18:52 jellyfish nagios[15856]: wproc: Registry request: name=Core Worker 15859;pid=15859
May 04 17:18:53 jellyfish nagios[15856]: Successfully launched command file worker with pid 15861
May 04 17:18:53 jellyfish nagios[15856]: HOST ALERT: localhost;DOWN;SOFT;1;(No output on stdout)

Accessing Nagios Web Interface

Restart and enable Apache to run on system reboot;

systemctl restart apache2
systemctl enable --now apache2

If firewall is running, allow Apache through.

ufw allow Apache

You can access Nagios from web interface via, http://Nagios-Server-IP-OR-Hostname/nagios.

Enter your basic authentication credentials;

Install and Setup Nagios on Ubuntu 22.04

Nagios default web interface

Install and Setup Nagios on Ubuntu 22.04

Nagios server is now running on Ubuntu 22.04

Install Nagios Plugins on Ubuntu 22.04

In order for Nagios to start monitoring hosts, you need to install Nagios plugins and NRPE agents. You can simply install plugins as follows;

apt install monitoring-plugins

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

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

So for Nagios use the current plugins directory, simply edit the Nagios resource config file and update as follows;

vim /usr/local/nagios/etc/resource.cfg
# Sets $USER1$ to be the path to the plugins

You can as well create a symbolic link instead of making the above changes as follows;

ln -s /usr/lib/nagios/plugins/* /usr/local/nagios/libexec

By this, you should have the plugins under the /usr/local/nagios/libexec directory.

Follow the links below to learn how to add hosts for monitoring as well as installing plugins and NRPE agents on other systems.

Add Hosts to Nagios Server For Monitoring

Install Nagios NRPE Agents on Debian 11/Debian 10


We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Jay Decrame
Linux Certified Engineer, Technology and Linux/Unix enthusiast.

3 thoughts on “Install and Setup Nagios on Ubuntu 22.04”

  1. Found two Problems one is solved :
    cat /etc/apache2/mods-enabled/php8.0.load
    # Conflicts: php5
    # Depends: mpm_prefork
    LoadModule php_module /usr/lib/apache2/modules/
    Changing it to leads to apache2 service restarts correctly.


    for the other one I have no solution right now
    May 11 07:34:21 nagios1 kernel: [ 5155.541493] traps: nagios[26689] general protection fault ip:7fb8659be7fd sp:7ffe098665b0 error:0 in[7fb8659a3000+5b000]


Leave a Comment