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.
- Installing required packages
- Getting nagios-core installation files
- Necessary configuration
- Running install script
- After install tasks
- Enabling LDAP
- 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:
apt-get update -y apt-get upgrade -y
Now, install required packages:
apt-get install -y wget build-essential unzip open-vm-tools
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
your_user_name ALL=NOPASSWD: ALL
After all, reboot system (yes, I know, after Windows habits;))
Now, lets continue with installing rest of required packages (apache, php etc.):
apt-get install -y apache2 php5-gd libgd2-xpm-dev libapache2-mod-php5
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:
cd /tmp wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
3. Necessary configuration
After downloading we need to add some users and groups:
useradd nagios groupadd nagcmd usermod -a -G nagcmd nagios
exctract archives and cd into nagios folder:
tar -zxf nagios-4.1.1.tar.gz cd nagios-4.1.1/
4. Running install script
Time to run some install scripts:
./configure --with-nagios-group=nagios --with-command-group=nagcmd make all make install make install-init make install-commandmode make install-config
Now, we need to copy some defaults in order to actually start nagios:
install -c -m 644 sample-config/httpd.conf.in /etc/apache2/sites-enabled/nagios.conf
Now, add and allow nagios user to login to nagios:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
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
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
go up one folder, back to /tmp:
cd ..
Now, download,untar and cd to nagios plugins directory:
wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz tar -zxf nagios-plugins-2.1.1.tar.gz cd nagios-plugins-2.1.1
and run install script:
./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install
Now, set permissions:
chown -R nagios:nagios /usr/local/nagios/etc/nagios.cfg chown -R nagios:www-data /usr/local/nagios/var/rw/ chmod +x /etc/init.d/nagios
And check nagios config:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output of above command should be as follows:
Nagios Core 4.1.1 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 08-19-2015 License: GPL Website: https://www.nagios.org Reading configuration data... Read main config file okay... Read object config files okay... Running pre-flight check on configuration data... Checking objects... Checked 8 services. Checked 1 hosts. Checked 1 host groups. Checked 0 service groups. Checked 1 contacts. Checked 1 contact groups. Checked 24 commands. Checked 5 time periods. Checked 0 host escalations. Checked 0 service escalations. Checking for circular paths... Checked 1 hosts Checked 0 service dependencies Checked 0 host dependencies Checked 5 timeperiods Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check
If something is wrong, check and correct errors
Now, enable apache modules and make sure nagios is started on each reboot:
a2enmod rewrite a2enmod cgi ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
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:
root@nagios-core-test3:/tmp/nagios-plugins-2.1.1# /etc/init.d/nagios start[....] Starting nagios (via systemctl): nagios.serviceFailed to start nagios.service: Unit nagios.service failed to load: No such file or directory. failed!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:
[table id=2 /]Ok, restart apache or even the whole server. After reboot you can check apache and nagios status
service apache2 status service nagios statusYou should get output like (apache2):
root@nagios-test04:/home/milosz# service apache2 status ● apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2) Active: active (running) since Tue 2015-11-24 14:27:41 CST; 1min 17s ago Process: 527 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCES S) CGroup: /system.slice/apache2.service ├─801 /usr/sbin/apache2 -k start ├─821 /usr/sbin/apache2 -k start ├─822 /usr/sbin/apache2 -k start ├─823 /usr/sbin/apache2 -k start ├─824 /usr/sbin/apache2 -k start └─825 /usr/sbin/apache2 -k start Nov 24 14:27:41 nagios-test04 apache2[527]: Starting web server: apache2.and for nagios:
root@nagios-test04:/home/milosz# service nagios status ● nagios.service - LSB: Starts and stops the Nagios monitoring server Loaded: loaded (/etc/init.d/nagios) Active: active (running) since Tue 2015-11-24 14:27:34 CST; 2min 21s ago Process: 460 ExecStart=/etc/init.d/nagios start (code=exited, status=0/SUCCESS) CGroup: /system.slice/nagios.service ├─497 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg ├─499 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh ├─500 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh ├─501 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh ├─502 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh └─805 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg Nov 24 14:27:34 nagios-test04 nagios[497]: nerd: Channel servicechecks registered successfully Nov 24 14:27:34 nagios-test04 nagios[497]: nerd: Channel opathchecks registered successfully Nov 24 14:27:34 nagios-test04 nagios[497]: nerd: Fully initialized and ready to rock! Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Successfully registered manager as @wproc with query handler Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Registry request: name=Core Worker 501;pid=501 Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Registry request: name=Core Worker 499;pid=499 Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Registry request: name=Core Worker 502;pid=502 Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Registry request: name=Core Worker 500;pid=500 Nov 24 14:27:34 nagios-test04 nagios[460]: Starting nagios: done. Nov 24 14:27:40 nagios-test04 nagios[497]: Successfully launched command file worker with pid 805At 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!
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
Thank you for your comment! Have you tried the steps provided in this guide? Did they happened to be insufficient to correct that error?
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.
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
Yes, I had. This post was very useful to me, everything is working fine! Only this bug was happening to me.
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:)
Hello Eduardo, your solutions works for me, I had the same error (debian 8 64 bits last update an Nagios 4.4.x)
I am installing it on AWS ec2 instance and same Nagios serivce error is happening to me. Otherwise things are well.
Glad you liked it, thanks for your comment!
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
Seems like init scripts are corrupted. Have you tried init script fix that Eduardo Mozart de Oliveira posted?
Also, please include your /etc/systemd/system/nagios.service script
yes i did them but it doesnt help.
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 #
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:)
the problem is that i havent the directory sample-config, isnt it?
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
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
Enter these commands, followed by ENTER:
cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
tar -zxf nagios-4.1.1.tar.gz
cd nagios-4.1.1/
sudo install -c -m 644 sample-config/httpd.conf.in /etc/apache2/sites-enabled/nagios.conf
I did that now and now there is no nagios.service at /etc/systemd/system/nagios.service
ITS RUNNING NOW!!
THANK YOU
You’re welcome, glad it works now. Now, add some hosts and services!
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.
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
i didnt understand how i can solve the problem. Do i have to change something in the nagios.conf?
No, please attach 000-default.conf and (if exists) nagios.conf from /etc/apache2/sites-enabled
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
Seems to me that directory directive is declared wrong. Could you post whole nagios.conf from sites-enabled?
Hi Milosz, so far, so good. But how about NRPE install on the server? Can we add hosts without NRPE on the server?
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.
Hello Miłosz
First of all, very nice tutorial!
I`m waiting for more :)
There will be more soon, thanks!
Hi Milosz, it seems there is a Debian package in the repository, nagios3, which may have all that is needed.
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.
Hi Ganesan! Glad it worked for you! Linux monitoring is not very hard to accomplish:) you can add them just the same way you added localhost. Just keep in mind that you need to have nrpe installed on target machine.Good know how located at: http://www.tecmint.com/how-to-add-linux-host-to-nagios-monitoring-server/
Definitely the best guide out there for installing Nagios on Ubuntu. It works perfectly. Thanks a million.
Thanks a million for such a comment! Glad it worked for you. Hope Nagios will serve you well!
[…] https://miloszengel.com/nagios-core-installation-guide-on-debian-8-x-jessie/ […]
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.
It will be… soon :)
I used this giude and it saved me so much stress setting up nagios core on Turnkeylinux Lampstack
Hi Dapo, thanks for your comment. Glad it worked for you! Good luck!