How to Install Nagios Server on Ubuntu 24.04

|
Published:
|
|
Install and Setup Nagios

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

Install Nagios Server on Ubuntu 24.04

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

Install Nagios Server from Default Ubuntu Repos

While it is easier to install Nagios Server 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.5.2 release being the latest stable version as per the releases page.

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

apt-cache policy nagios4
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

You can check similar installation here;

Install Nagios Server on Debian 11

Install Nagios Server from Source Code on Ubuntu 24.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.

sudo apt update

Install Required Nagios build tools and Development Libraries

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

sudo apt install autoconf \
    gcc \
    libc6 \
    make \
    wget \
    unzip \
    apache2 \
    apache2-utils \
    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;

Replace the value of the VER variable below with the current release version of Nagios.

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

Extract Nagios Source Code

Once the download completes, extract the source archive;

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

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

ls
nagios-4.5.2 nagios-4.5.2.tar.gz

Compile and Install Nagios Server on Ubuntu 24.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-${VER}

Configure Nagios to use Apache as the web server. Use the --with-httpd-conf to specify where to install Nagios Server Apache site configs.

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

Be sure to use ./configure --help for more options.

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;

...
Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 4.5.2 2024-04-30 ***:

 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.

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

Install Nagios Server main program, CGIs, and HTML files.

sudo make install

Install Nagios Server startup scripts;

sudo make install-init

Installs and configures permissions on the directory for holding the external command file;

sudo make install-commandmode

Initialize the init scripts;

sudo make install-daemoninit

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

sudo make install-config

Sample output;

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

Install Apache configuration file for the Nagios web interface

sudo make install-webconf

Enable Apache rewrite and CGI modules;

sudo a2enmod rewrite cgi

Similarly, disable the default Apache site;

sudo a2dissite 000-default.conf

Configure Nagios Web Interface basic authentication.

sudo 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 24.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;

sudo systemctl enable --now nagios

If it was already running, then restart it;

sudo systemctl restart nagios

To check the status;

systemctl status nagios
● nagios.service - Nagios Core 4.5.2
     Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; preset: enabled)
     Active: active (running) since Wed 2024-05-08 19:49:13 UTC; 21s ago
       Docs: https://www.nagios.org/documentation
    Process: 21969 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
    Process: 21970 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
   Main PID: 21972 (nagios)
      Tasks: 6 (limit: 4614)
     Memory: 5.7M (peak: 6.2M)
        CPU: 196ms
     CGroup: /system.slice/nagios.service
             ├─21972 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
             ├─21973 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─21974 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─21976 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─21977 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             └─21978 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

May 08 19:49:13 monitor01 nagios[21972]: qh: core query handler registered
May 08 19:49:13 monitor01 nagios[21972]: qh: echo service query handler registered
May 08 19:49:13 monitor01 nagios[21972]: qh: help for the query handler registered
May 08 19:49:13 monitor01 nagios[21972]: wproc: Successfully registered manager as @wproc with query handler
May 08 19:49:13 monitor01 nagios[21972]: wproc: Registry request: name=Core Worker 21974;pid=21974
May 08 19:49:13 monitor01 nagios[21972]: wproc: Registry request: name=Core Worker 21973;pid=21973
May 08 19:49:13 monitor01 nagios[21972]: wproc: Registry request: name=Core Worker 21977;pid=21977
May 08 19:49:13 monitor01 nagios[21972]: wproc: Registry request: name=Core Worker 21976;pid=21976
May 08 19:49:14 monitor01 nagios[21972]: Successfully launched command file worker with pid 21978
May 08 19:49:14 monitor01 nagios[21972]: HOST ALERT: localhost;DOWN;SOFT;1;(No output on stdout) stderr: execvp(/usr/local/nagios/libexec/check_ping, ...) failed. errno is 2: No such file or directory

The error you see on status;

May 08 19:49:14 monitor01 nagios[21972]: HOST ALERT: localhost;DOWN;SOFT;1;(No output on stdout) stderr: execvp(/usr/local/nagios/libexec/check_ping, ...) failed. errno is 2: No such file or directory

Is because we havent installed Nagios monitoring plugins yet. So it is okay to ignore it for now.

Accessing Nagios Web Interface

Restart and enable Apache to run on system reboot;

sudo systemctl restart apache2
sudo systemctl enable apache2

If firewall is running, allow Apache through.

sudo ufw allow Apache

Or Iptables;

sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

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

Enter your basic authentication credentials;

Install Nagios Server on Ubuntu 24.04

Nagios default web interface

nagios server on ubuntu 24.04

Nagios Core server is now running on Ubuntu 24.04

Install Nagios Server Plugins on Ubuntu 24.04

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

sudo apt update
sudo 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;

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

Similarly, you will have to change the path of the monitoring command plugins in the Nagios templates

Ensure you reload Nagios after;

sudo systemctl reload nagios.service

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

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

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

sudo ls -alh /usr/local/nagios/libexec/
total 8.0K
drwxrwxr-x 2 nagios nagios 4.0K May  8 20:05 .
drwxr-xr-x 8 root   root   4.0K May  8 19:47 ..
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_apt -> /usr/lib/nagios/plugins/check_apt
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_breeze -> /usr/lib/nagios/plugins/check_breeze
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_by_ssh -> /usr/lib/nagios/plugins/check_by_ssh
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_clamd -> /usr/lib/nagios/plugins/check_clamd
lrwxrwxrwx 1 root   root     37 May  8 20:05 check_cluster -> /usr/lib/nagios/plugins/check_cluster
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_curl -> /usr/lib/nagios/plugins/check_curl
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_dbi -> /usr/lib/nagios/plugins/check_dbi
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_dhcp -> /usr/lib/nagios/plugins/check_dhcp
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_dig -> /usr/lib/nagios/plugins/check_dig
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_disk -> /usr/lib/nagios/plugins/check_disk
lrwxrwxrwx 1 root   root     38 May  8 20:05 check_disk_smb -> /usr/lib/nagios/plugins/check_disk_smb
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_dns -> /usr/lib/nagios/plugins/check_dns
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_dummy -> /usr/lib/nagios/plugins/check_dummy
lrwxrwxrwx 1 root   root     38 May  8 20:05 check_file_age -> /usr/lib/nagios/plugins/check_file_age
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_flexlm -> /usr/lib/nagios/plugins/check_flexlm
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_fping -> /usr/lib/nagios/plugins/check_fping
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_ftp -> /usr/lib/nagios/plugins/check_ftp
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_game -> /usr/lib/nagios/plugins/check_game
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_host -> /usr/lib/nagios/plugins/check_host
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_hpjd -> /usr/lib/nagios/plugins/check_hpjd
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_http -> /usr/lib/nagios/plugins/check_http
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_icmp -> /usr/lib/nagios/plugins/check_icmp
lrwxrwxrwx 1 root   root     39 May  8 20:05 check_ide_smart -> /usr/lib/nagios/plugins/check_ide_smart
lrwxrwxrwx 1 root   root     42 May  8 20:05 check_ifoperstatus -> /usr/lib/nagios/plugins/check_ifoperstatus
lrwxrwxrwx 1 root   root     38 May  8 20:05 check_ifstatus -> /usr/lib/nagios/plugins/check_ifstatus
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_imap -> /usr/lib/nagios/plugins/check_imap
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_ircd -> /usr/lib/nagios/plugins/check_ircd
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_jabber -> /usr/lib/nagios/plugins/check_jabber
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_ldap -> /usr/lib/nagios/plugins/check_ldap
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_ldaps -> /usr/lib/nagios/plugins/check_ldaps
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_load -> /usr/lib/nagios/plugins/check_load
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_log -> /usr/lib/nagios/plugins/check_log
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_mailq -> /usr/lib/nagios/plugins/check_mailq
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_mrtg -> /usr/lib/nagios/plugins/check_mrtg
lrwxrwxrwx 1 root   root     38 May  8 20:05 check_mrtgtraf -> /usr/lib/nagios/plugins/check_mrtgtraf
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_mssql -> /usr/lib/nagios/plugins/check_mssql
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_mysql -> /usr/lib/nagios/plugins/check_mysql
lrwxrwxrwx 1 root   root     41 May  8 20:05 check_mysql_query -> /usr/lib/nagios/plugins/check_mysql_query
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_nagios -> /usr/lib/nagios/plugins/check_nagios
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_nntp -> /usr/lib/nagios/plugins/check_nntp
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_nntps -> /usr/lib/nagios/plugins/check_nntps
lrwxrwxrwx 1 root   root     32 May  8 20:05 check_nt -> /usr/lib/nagios/plugins/check_nt
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_ntp -> /usr/lib/nagios/plugins/check_ntp
lrwxrwxrwx 1 root   root     38 May  8 20:05 check_ntp_peer -> /usr/lib/nagios/plugins/check_ntp_peer
lrwxrwxrwx 1 root   root     38 May  8 20:05 check_ntp_time -> /usr/lib/nagios/plugins/check_ntp_time
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_nwstat -> /usr/lib/nagios/plugins/check_nwstat
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_oracle -> /usr/lib/nagios/plugins/check_oracle
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_overcr -> /usr/lib/nagios/plugins/check_overcr
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_pgsql -> /usr/lib/nagios/plugins/check_pgsql
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_ping -> /usr/lib/nagios/plugins/check_ping
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_pollen -> /usr/lib/nagios/plugins/check_pollen
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_pop -> /usr/lib/nagios/plugins/check_pop
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_procs -> /usr/lib/nagios/plugins/check_procs
lrwxrwxrwx 1 root   root     36 May  8 20:05 check_radius -> /usr/lib/nagios/plugins/check_radius
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_real -> /usr/lib/nagios/plugins/check_real
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_rpc -> /usr/lib/nagios/plugins/check_rpc
lrwxrwxrwx 1 root   root     39 May  8 20:05 check_rta_multi -> /usr/lib/nagios/plugins/check_rta_multi
lrwxrwxrwx 1 root   root     37 May  8 20:05 check_sensors -> /usr/lib/nagios/plugins/check_sensors
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_simap -> /usr/lib/nagios/plugins/check_simap
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_smtp -> /usr/lib/nagios/plugins/check_smtp
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_snmp -> /usr/lib/nagios/plugins/check_snmp
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_spop -> /usr/lib/nagios/plugins/check_spop
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_ssh -> /usr/lib/nagios/plugins/check_ssh
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_ssmtp -> /usr/lib/nagios/plugins/check_ssmtp
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_swap -> /usr/lib/nagios/plugins/check_swap
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_tcp -> /usr/lib/nagios/plugins/check_tcp
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_time -> /usr/lib/nagios/plugins/check_time
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_udp -> /usr/lib/nagios/plugins/check_udp
lrwxrwxrwx 1 root   root     33 May  8 20:05 check_ups -> /usr/lib/nagios/plugins/check_ups
lrwxrwxrwx 1 root   root     35 May  8 20:05 check_users -> /usr/lib/nagios/plugins/check_users
lrwxrwxrwx 1 root   root     34 May  8 20:05 check_wave -> /usr/lib/nagios/plugins/check_wave
lrwxrwxrwx 1 root   root     30 May  8 20:05 negate -> /usr/lib/nagios/plugins/negate
lrwxrwxrwx 1 root   root     30 May  8 20:05 urlize -> /usr/lib/nagios/plugins/urlize
lrwxrwxrwx 1 root   root     32 May  8 20:05 utils.pm -> /usr/lib/nagios/plugins/utils.pm
lrwxrwxrwx 1 root   root     32 May  8 20:05 utils.sh -> /usr/lib/nagios/plugins/utils.sh
sudo systemctl reload nagios.service

You should see localhost monitoring turn green now!

nagios localhost monitoring

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

Proceed to add hosts to Nagios server for monitoring.

Add Hosts to Nagios Server For Monitoring

Install NRPE Agents on Linux Hosts

Install NRPE Agents to facilitate monitoring.

Install Nagios NRPE Agents on Linux

How to Install NSClient Nagios Monitoring Agent on Windows System

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

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
Kifarunix
Linux Certified Engineer, with a passion for open-source technology and a strong understanding of Linux systems. With experience in system administration, troubleshooting, and automation, I am skilled in maintaining and optimizing Linux infrastructure.

Leave a Comment