Distribution packages can lag behind the upstream Nagios Core release. Building Nagios Core from its release tarball installs the upstream monitoring daemon and CGI web interface on Ubuntu or Debian with Apache and systemd.

The source installer creates the nagios service account, installs sample monitoring objects, and registers a service that starts at boot. This is a fresh installation on a server where you have sudo access; installing sample configuration over an existing monitoring setup can replace settings that need to be preserved during an upgrade.

Nagios Core schedules checks, while separate plugins perform them. The distribution-maintained Monitoring Plugins packages supply the local checks here, so the completed installation can monitor the server as well as serve the password-protected web interface. Remote browser access needs HTTPS and a firewall policy appropriate for a management service.

Steps to install Nagios Core from source:

  1. Refresh the package index.
    $ sudo apt update
  2. Install the compiler, web server, and monitoring plugins.
    $ sudo apt install --assume-yes autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php libgd-dev openssl libssl-dev apache2-utils curl ca-certificates monitoring-plugins-basic monitoring-plugins-standard

    The distribution supplies the build dependencies and plugins; Nagios Core itself comes from the upstream release tarball. The unzip utility is required by the Core build.

  3. Download the Nagios Core release tarball.
    $ wget --output-document=/tmp/nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.5.14/nagios-4.5.14.tar.gz

    The upstream release page lists release 4.5.14. A different release requires its matching download URL and source directory.

  4. Extract the source archive.
    $ tar --extract --gzip --file /tmp/nagioscore.tar.gz --directory /tmp
  5. Enter the extracted source directory.
    $ cd /tmp/nagios-4.5.14
  6. Configure the build for Apache and the packaged plugin directory.
    $ ./configure --with-httpd-conf=/etc/apache2/sites-enabled --libexecdir=/usr/lib/nagios/plugins

    The generated command definitions use plugins in /usr/lib/nagios/plugins. Without this option, a source installation expects them in /usr/local/nagios/libexec.

  7. Compile Nagios Core and its CGI programs.
    $ make all
  8. Create the nagios service account.
    $ sudo make install-groups-users
  9. Add Apache's runtime user to the nagios group.
    $ sudo usermod --append --groups nagios www-data

    The web interface uses this group membership to access Nagios's command directory. Ubuntu and Debian use www-data for Apache.

  10. Install the binaries and web files.
    $ sudo make install
  11. Install the Nagios service unit.
    $ sudo make install-daemoninit

    On a systemd server, this target also enables nagios.service at boot.

  12. Install the external command directory permissions.
    $ sudo make install-commandmode
  13. Install the sample monitoring configuration.

    This installs a new sample configuration under /usr/local/nagios/etc. Do not use it to upgrade a configured monitoring server.

    $ sudo make install-config
  14. Install the Apache configuration for Nagios.

    The web configuration uses HTTP Basic authentication. Do not expose port 80 to untrusted networks or send the web password over an unencrypted remote connection.

    $ sudo make install-webconf
  15. Enable Apache's rewrite and CGI modules.
    $ sudo a2enmod rewrite cgi
  16. Create the first web login as nagiosadmin.

    The -c option creates the password file and overwrites it if it already exists. For an existing password file, omit -c. Password entry is hidden.

    $ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
    New password:
    Re-type new password:
    Adding password for user nagiosadmin

    The sample CGI authorization configuration grants nagiosadmin administrative access.
    Related: How to reset a Nagios Core web user password

  17. Validate the installed Nagios Core configuration.
    $ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    
    Nagios Core 4.5.14
    ##### snipped #####
    Reading configuration data...
       Read main config file okay...
       Read object config files okay...
    ##### snipped #####
    Total Warnings: 0
    Total Errors:   0
    
    Things look okay - No serious problems were detected during the pre-flight check

    Configuration errors must be resolved before the service starts.
    Related: How to validate the Nagios Core configuration

  18. Test the Apache configuration.
    $ sudo apache2ctl configtest
    Syntax OK

    An additional AH00558 hostname warning does not invalidate Syntax OK.

  19. Restart Apache to load the Nagios site.

    Restarting Apache briefly interrupts every site served by that instance.

    $ sudo systemctl restart apache2.service
  20. Start Nagios Core with boot-time startup enabled.
    $ sudo systemctl enable --now nagios.service
  21. Confirm both services are active.
    $ systemctl is-active apache2.service nagios.service
    active
    active
  22. Run the HTTP plugin as the nagios service account.
    $ sudo -u nagios /usr/lib/nagios/plugins/check_http -H 127.0.0.1
    HTTP OK: HTTP/1.1 200 OK - 10945 bytes in 0.000 second response time |time=0.000391s;;;0.000000;10.000000 size=10945B;;;0;

    This checks Apache's default site and proves that the service account can execute a real plugin. Response size and timing vary.
    Related: How to run a Nagios plugin manually

  23. Remove the temporary source files.
    $ rm -rf /tmp/nagios-4.5.14 /tmp/nagioscore.tar.gz

    The installed files remain under /usr/local/nagios.

  24. Check authenticated access to the Nagios localhost service page.
    $ curl --head --fail --user nagiosadmin 'http://127.0.0.1/nagios/cgi-bin/status.cgi?host=localhost'
    Enter host password for user 'nagiosadmin':
    HTTP/1.1 200 OK
    ##### snipped #####
    Content-Type: text/html; charset=utf-8

    The password prompt uses the login created earlier. 200 OK confirms that Apache can run the authenticated Nagios CGI. The browser interface is at /nagios/ on this server; HTTPS is needed before remote sign-in.
    Related: How to troubleshoot Nagios Core web interface access

Share this guide