Nagios Core installation guide on Debian 8.x (Jessie)

Nagios Core serves as the basic event scheduler, event processor, and alert manager for elements that are monitored. It features several APIs that are used to extend its capabilities to perform additional tasks, is implemented as a daemon written in C for performance reasons, & is designed to run natively on Linux/*nix systems.

More information about nagios core and how it works can be found here. I will focus on setting in since if I you are reading this, you are probably know what it is, but have problems with setting in up and running. So here it is.

  1. Installing required packages
  2. Getting nagios-core installation files
  3. Necessary configuration
  4. Running install script
  5. After install tasks
  6. Enabling LDAP
  7. Finish!

Latest versions of nagios and plugins cane be found here:
nagios core: https://www.nagios.org/downloads/nagios-core/
nagios plugins: http://nagios-plugins.org/download/

1. Installing required packages

SSH to server, then su to root in order to avoid typing sudo all the time.

REMEMBER TO TYPE COMMANDS ONE AT A TIME IN ORDER TO SEE ERRORS AND WARNINGS!

Like always on Debian, start with updating and upgrading package repositories:

Now, install required packages:

Next thing I often do is allowing specific user to act as root and to sudo without a password. I know it isn’t the most elegant way, but for installing and later, editing files with for example WinSCP – is quite comfortable. Later you can always revert the changes. Just add following line into: /etc/sudoers

After all, reboot system (yes, I know, after Windows habits;))
Now, lets continue with installing rest of required packages (apache, php etc.):

Keep in mind to save somewhere passwords for apache etc…

2. Getting nagios-core installation files

Now, pwd to temporary directory and download nagios-core files:

3. Necessary configuration

After downloading we need to add some users and groups:

exctract archives and cd into nagios folder:

4. Running install script

Time to run some install scripts:

Now, we need to copy some defaults in order to actually start nagios:

Now, add and allow nagios user to login to nagios:

Ok, now we DO NOT HAVE a running nagios core instance:)
We have managed to install it but we are still a few steps before actually running it.Let’s proceed to:

5. After install tasks

Copy event handlers to nagios directory

go up one folder, back to /tmp:

Now, download,untar and cd to nagios plugins directory:

and run install script:

Now, set permissions:

And check nagios config:

Output of above command should be as follows:

If something is wrong, check and correct errors

Now, enable apache modules and make sure nagios is started on each reboot:

Now we need to change a few lines in nagios.conf as we copied default config which includes environmental variable which we do not have. This “normal” behaviour but will not allow to start nagios deamon. Error you will get looks something like:

In order to correct this we need to change paths in nagios.conf from variables to absolute strings. Nano file /etc/apache2/sites-enabled/nagios.conf, and change:

row numberOriginal valueChanged value
8@cgiurl@/nagios/cgi-bin
8"@sbindir@""/usr/local/nagios/sbin"
10"@sbindir@""/usr/local/nagios/sbin"
21@sysconfdir@/htpasswd.users/usr/local/nagios/etc/htpasswd.users
34@sysconfdir@/htpasswd.users/usr/local/nagios/etc/htpasswd.users
39@htmurl@/nagios
39"@datadir@""/usr/local/nagios/share"
41"@datadir@""/usr/local/nagios/share"
52@sysconfdir@/htpasswd.users/usr/local/nagios/etc/htpasswd.users
65@sysconfdir@/htpasswd.users/usr/local/nagios/etc/htpasswd.users

Ok, restart apache or even the whole server. After reboot you can check apache and nagios status

You should get output like (apache2):

and for nagios:

At this point nagios is working! You can login to the console by specifying login nagiosadmin and password for this account.

In the next part I will cover LDAP configuration and basic host and services creation/adding, so stay tuned![/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

By |2016-12-22T21:35:10+00:00November 23rd, 2015|How-To's, Nagios Core|42 Comments

About the Author:

I am passionate about Systems Administration. I like to face new challenges and test new environments.Windows and Linux Debian boxes (both physical and virtual) are my favourites. I like solving problems related to Windows Server roles and services as well as Linux but some distributions in particular. I'm not considering myself as Linux master but surely, I always do my best to fit the needs. On the other hand I consider myself as a Windows Server Professional and in terms of WS and Windows Desktops I always follow best practices, good advices and opinions from other admins.

42 Comments

  1. Eduardo Mozart de Oliveira March 22, 2016 at 17:58 - Reply

    The message “[….] Starting nagios (via systemctl): nagios.serviceFailed to start nagios.service: Unit nagios.service failed to load: No such file or directory.
    failed!” keeps happening to me.

    I found a solution at https://support.nagios.com/forum/viewtopic.php?f=7&t=35220#p157005

    Create this file at /etc/systemd/system/nagios.service with the following contents.

    [Unit]
    Description=Nagios
    BindTo=network.target

    [Install]
    WantedBy=multi-user.target

    [Service]
    User=nagios
    Group=nagios
    Type=simple
    ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg

    After that, run the following commands:

    sudo systemctl enable /etc/systemd/system/nagios.service
    sudo systemctl start nagios
    sudo systemctl status nagios

    • milosz March 22, 2016 at 21:08 - Reply

      Thank you for your comment! Have you tried the steps provided in this guide? Did they happened to be insufficient to correct that error?

      • Christopher Noyes March 22, 2016 at 23:07 - Reply

        I followed the steps in this tutorial and Eduardo is correct. Nagios does not install the correct systemd service start file to start the nagios process. Nagios seems to still be configured to install the old SysV init scripts.

        • milosz March 23, 2016 at 14:34 - Reply

          Ok, thank you Christopher for your input! I will double check the steps and post an update, since guide was done some time ago.
          Milosz

      • Eduardo Mozart de Oliveira March 23, 2016 at 16:44 - Reply

        Yes, I had. This post was very useful to me, everything is working fine! Only this bug was happening to me.

        • milosz March 24, 2016 at 09:52 - Reply

          This is quite strange. I downloaded the latest version of Jessie, followed the steps to the line remembering that you have to be either root or insert sudo before each make/install/cp/configure command and ended up with working nagios in about 10 minutes. The error you described was due to using variables in /etc/apache2/sites-avaialable/nagios.conf but after changing to correct values nagios was running no matter if started with /etc/init.d/nagios start or service nagios start and is started on each reboot. If you want I can provide a VHD with it:)

    • Ariel November 8, 2016 at 22:59 - Reply

      Hello Eduardo, your solutions works for me, I had the same error (debian 8 64 bits last update an Nagios 4.4.x)

  2. waqas April 15, 2016 at 13:06 - Reply

    I am installing it on AWS ec2 instance and same Nagios serivce error is happening to me. Otherwise things are well.

  3. nagios May 4, 2016 at 09:33 - Reply

    Hello i have problem with starting nagios.
    When i run: sudo systemctl status nagios, this comes out:

    root@Debian8-Nagios:/etc/systemd/system# sudo systemctl status nagios
    ● nagios.service – Nagios
    Loaded: loaded (/etc/systemd/system/nagios.service; enabled)
    Active: failed (Result: exit-code) since Mi 2016-05-04 09:27:32 CEST; 6s ago
    Process: 1960 ExecStop=/etc/systemd/system/nagios.service stop (code=exited, status=203/EXEC)
    Process: 1958 ExecStart=/etc/systemd/system/nagios.service start (code=exited, status=203/EXEC)
    Main PID: 1958 (code=exited, status=203/EXEC)

    Mai 04 09:27:32 Debian8-Nagios systemd[1]: nagios.service: main process exited, code=exited, status=203/EXEC
    Mai 04 09:27:32 Debian8-Nagios systemd[1960]: Failed at step EXEC spawning /etc/systemd/system/nagios.ser…rror
    Mai 04 09:27:32 Debian8-Nagios systemd[1]: nagios.service: control process exited, code=exited status=203
    Mai 04 09:27:32 Debian8-Nagios systemd[1]: Unit nagios.service entered failed state.
    Hint: Some lines were ellipsized, use -l to show in full.

    I have installed nagios on Debia

    • Miłosz Engel May 4, 2016 at 10:17 - Reply

      Seems like init scripts are corrupted. Have you tried init script fix that Eduardo Mozart de Oliveira posted?

      • Miłosz Engel May 4, 2016 at 10:20 - Reply

        Also, please include your /etc/systemd/system/nagios.service script

        • nagios May 4, 2016 at 10:58 - Reply

          yes i did them but it doesnt help.

          • nagios May 4, 2016 at 11:17

            if i try this: sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf

            it cames: root @ Debian8-Nagios: / usr / local / nagios / etc / objects # sudo / usr / bin / install -c -m 644 sample-config / httpd.conf /etc/apache2/sites-enabled/nagios.conf
            / Usr / bin / install: the stat for sample-config / httpd.conf is not possible: file or directory not found
            root @ Debian8-Nagios: / usr / local / nagios / etc / objects #

          • Miłosz Engel May 4, 2016 at 11:34

            This line:
            install -c -m 644 sample-config/httpd.conf.in /etc/apache2/sites-enabled/nagios.conf
            Assumes that you are in unpacked install directory, eg /tmp/nagios-4.1.1/
            Are you?
            I think you are missing “.in” in httpd.conf.in part of the command:
            install -c -m 644 sample-config/httpd.conf.in /etc/apache2/sites-enabled/nagios.conf
            Also, you do not need to specify /usr/bin/install, just sudo install
            Above error says, that httpd.conf cannot be found, but you would like to have httpd.conf.in instead:)

  4. nagios May 4, 2016 at 12:14 - Reply

    the problem is that i havent the directory sample-config, isnt it?

    • Miłosz Engel May 4, 2016 at 12:27 - Reply

      Yes, but it is because you are in wrong directory:)
      Your command:
      / usr / local / nagios / etc / objects # sudo / usr / bin / install -c -m 644 sample-config / httpd.conf /etc/apache2/sites-enabled/nagios.conf
      says that you want to execute install script beeing in /usr/loca/nagios/etc but you should be in extracted install directory (where you downloaded installation files at the beginning) like /tmp/nagios as stated in point 3. Also keep in mind there is a typoo in your command. There should be httpd.conf.in not httpd.conf

  5. nagios May 4, 2016 at 12:40 - Reply

    oh okey, I looked in this directory /tmp but i cant find the install directory but i did the installation identic with your how to. I dont know whats wrong

  6. nagios May 6, 2016 at 09:16 - Reply

    Now i have the problem that Nagios shows this when i want to open:
    Not Found

    The requested URL /nagios was not found on this server.
    Apache/2.4.10 (Debian) Server at 213.0.1.137 Port 80

    But i didnt do anything since the problem was solved.

    • Miłosz Engel May 6, 2016 at 09:28 - Reply

      Seems to me that configuration for site: nagios is missing in apache2 configuration in /etc/apache2/sites-enabled or pointing to wrong directory 🙂
      Look for /nagios alias in default.conf in above directory or in nagios.conf up there. If it’s missing, site config is missing for nagios

      • nagios May 6, 2016 at 09:45 - Reply

        i didnt understand how i can solve the problem. Do i have to change something in the nagios.conf?

        • Miłosz Engel May 6, 2016 at 09:49 - Reply

          No, please attach 000-default.conf and (if exists) nagios.conf from /etc/apache2/sites-enabled

  7. Andres Fernandez May 25, 2016 at 21:36 - Reply

    I keep getting the following after apachectl restart:

    root@kanotixbox:~# apachectl restart
    AH00526: Syntax error on line 12 of /etc/apache2/sites-enabled/nagios.conf:
    Invalid command ‘<"usr/local/nagios/sbin"Directory', perhaps misspelled or defined by a module not included in the server configuration
    Action 'restart' failed.
    The Apache error log may have more information.
    root@kanotixbox:~#

    But I have this in the line 12 of /etc/apache2/sites-enabled/nagios.conf

    • Miłosz Engel May 27, 2016 at 11:29 - Reply

      Seems to me that directory directive is declared wrong. Could you post whole nagios.conf from sites-enabled?

  8. ioan May 30, 2016 at 15:51 - Reply

    Hi Milosz, so far, so good. But how about NRPE install on the server? Can we add hosts without NRPE on the server?

    • Miłosz Engel May 30, 2016 at 17:07 - Reply

      I think yes, but installing NRPE on localhost enables you to monitor it as well. I will get back to Nagios soon because I had some other work to do.

  9. Adam Kowalski June 22, 2016 at 11:40 - Reply

    Hello Miłosz

    First of all, very nice tutorial!
    I`m waiting for more 🙂

  10. ioan July 3, 2016 at 17:28 - Reply

    Hi Milosz, it seems there is a Debian package in the repository, nagios3, which may have all that is needed.

  11. Ganesan November 28, 2016 at 13:56 - Reply

    Hi Milosz, thanks much for the good and useful article. I followed your above commands on Debian Jessie and everything going well.

    I want to know how to connect and monitor other Debian servers on the same network.

  12. VideoPortal March 18, 2017 at 01:29 - Reply

    Definitely the best guide out there for installing Nagios on Ubuntu. It works perfectly. Thanks a million.

    • Miłosz Engel March 18, 2017 at 07:48 - Reply

      Thanks a million for such a comment! Glad it worked for you. Hope Nagios will serve you well!

  13. Abdoulie May 15, 2017 at 22:10 - Reply

    Thanks for this very clear step-by-step guide. It works out just fine for me. I am waiting for the next next phase: how to add and monitor both clients including windows, network printers as well as other Linux servers.

  14. Dapo November 8, 2017 at 21:10 - Reply

    I used this giude and it saved me so much stress setting up nagios core on Turnkeylinux Lampstack

    • Miłosz Engel November 19, 2017 at 20:05 - Reply

      Hi Dapo, thanks for your comment. Glad it worked for you! Good luck!

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.