Since this post is a snapshot in time. I recommend that you download a copy of the book which is updated frequently to improve and expand the content.
---------------------------------------
Historically, installation of Nagios on a Raspberry Pi has been somewhat ‘problematic’. The reason being that while Nagios has been compiled to work with a wide range of different computer types, installation onto the ARM architecture used by the Pi has not been common. There has been good work done to pre-compile and distribute images for use, but in may cases these do not support the later versions of Raspbian and they take some of the ‘mystery’ and learning away from the process.
What follows is heavily drawn from the good work of Farooq Mohammed Ahmed who has been a stalwart of a range of open source topics including the Raspberry Pi and Nagios.
First we need to set ourselves as the root user for all the following commands;
We should be able to see the immediate difference as the command prompt changes to indicate that we are now operating as root;
Get the required supporting packages
We need to download and install the required packages via apt-get
install
.
We will be informed of the additional packages that will also need to be installed and asked to agree to the process. Once we agree it will start and work its way through the various applications.
Then we need to create a ‘nagios’ user using useradd
and then set the password using passwd
(choose something appropriate and note it down somewhere).
Now we create a group ‘nagcmd’ (using groupadd
) to facilitate external commands via the Web User Interface and then add both Nagios (‘nagios’) and Apache (‘www-data’) users to it with the usermod
command.
Now we can download Nagios Core and associated plugins using wget
to the /tmp
directory. The latest current versions are Nagios 4.1.1 and Nagios Plugins 2.1.1. We’ll do this in the /tmp
directory to keep out of the way of the rest of the system during the installation (hence the cd
into /tmp
).
Once these have finished downloading we need to un-bundle (tar
) and decompress the files;
Once this is complete we will have two folders with the name nagios-4.1.1
and nagios-plugins-2.1.1
apt-get
install
.useradd
and then set the password using passwd
(choose something appropriate and note it down somewhere).groupadd
) to facilitate external commands via the Web User Interface and then add both Nagios (‘nagios’) and Apache (‘www-data’) users to it with the usermod
command.wget
to the /tmp
directory. The latest current versions are Nagios 4.1.1 and Nagios Plugins 2.1.1. We’ll do this in the /tmp
directory to keep out of the way of the rest of the system during the installation (hence the cd
into /tmp
).tar
) and decompress the files;nagios-4.1.1
and nagios-plugins-2.1.1
Compile and configure Nagios Core
First we will start with Nagios Core install by changing into the appropriate directory;
Now we’re going to compile the source and install it. All the files from this process will go into /usr/local/nagios/
directory.
This process will whistle through a considerable amount of processing and then display a configuration summary.
As the final portion of the output states, assuming that the configuration looks OK we can then go ahead and start the make
process. This will carry out the process of building the executable programs and libraries from the available source code.
This is a complex process that will take some time to complete (especially on a ‘Pi’) so prepare to be patient while it works through the required computation.
Once successfully complete we will continue with installing Nagios as follows;
make install
: This installs the main program, CGIs, and HTML files
make install-init
: This installs the init script in /etc/init.d
make install-config
: This installs sample config files in /usr/local/nagios/etc
make install-commandmode
: This installs and configures permissions on the directory for holding the external command file
Now we need to install and configure web access to Nagios via our web server apache. First copy the appropriate files and adjust permissions;
Then make the directory for the httpd.conf
file by creating the /etc/httpd/conf.d/nagios.conf
directory;
And then make install-webconf
to install the Apache config file for the Nagios web interface
Now we can create a user and a password to use to access the Nagios Web User Interface via the Apache HTTP server. The name ‘nagiosadmin’ used below can be substituted for an alternative if desired.
We will be prompted (twice) for a new password for the ‘nagiosadmin’ user. Note it down somewhere appropriate.
Once that is done we need to restart the Apache service
/usr/local/nagios/
directory.make
process. This will carry out the process of building the executable programs and libraries from the available source code.make install
: This installs the main program, CGIs, and HTML filesmake install-init
: This installs the init script in /etc/init.dmake install-config
: This installs sample config files in /usr/local/nagios/etcmake install-commandmode
: This installs and configures permissions on the directory for holding the external command filehttpd.conf
file by creating the /etc/httpd/conf.d/nagios.conf
directory;make install-webconf
to install the Apache config file for the Nagios web interfaceCompile and configure Nagios plugins
Now we need to install the plugins for Nagios by first changing to the nagios-plugins-2.1.1
directory;
Then we compile and install the plugins in a similar way to the process we used earlier on Nagios Core. Firstly we compile the appropriate executables from the source;
As with the previous effort this will proceed through a considerable amount of processing. Then we can carry out the make
process on the installation;
Once complete we need to ensure that the Nagios service starts up at runtime when the system boots up by creating a link from nagios
in the init.d directory;
At this point we should have successfully installed Nagios. We should verify this by checking for errors;
An output should be produced that looks a little like the following;
Per the final line, it looks as if everything has gone smoothly.
nagios-plugins-2.1.1
directory;make
process on the installation;nagios
in the init.d directory;Configure Nagios as a service
Now we can create a nagios.service
file with the file editor ‘nano’ (or the editor of your choice) with the following content. This will allow us to start and stop Nagios in a standardised way.
To enable the cgi links from the Nagios Web UI we move the cgi.load
file as follows;
Then we can restart the Apache web service;
If no errors are reported then we can start the Nagios service.
At this point Nagios should be running, but it’s worth checking to see if there are any reported problems;
If everything has gone smoothly we should see a report similar to the following;
nagios.service
file with the file editor ‘nano’ (or the editor of your choice) with the following content. This will allow us to start and stop Nagios in a standardised way.cgi.load
file as follows;Access the Nagios Web Interface
We are now ready to access the Nagios Web User Interface. We can do this by using the static IP address that we set up for our Pi at the following URL http://10.1.1.230/nagios. This can be accessed from a machine (our Windows desktop for example) by simply typing it into the browser.
(Remembering that the IP address that you enter here needs to be your address. Not necessarily 10.1.1.230.)
When we first enter this in our browser we will be asked to authenticate ourselves;
Login |
We need to enter the username and password that we set up earlier to access the Web interface. The one we used in the example was ‘nagiosadmin’. Once entered we should see the front page of our Nagios page looking a little like the following;
Nagios Start Page |
Congratulations!
We’ve managed to successfully install Nagios on a Raspberry Pi! Now all we need to do is to use it :-)
Excellent!
ReplyDeleteWithout any issues I was able to follow your guide.
Now for me to see what I can do with Nagios.
Thanks!
I am trying to run the commands but when i authenticate i get an internal server error what is that i am not doing correct.
ReplyDeleteI'm not sure what would be causing the problem. The best I could recommend is to re-try the installation and see if there is something different in the process that might be causing the problem.
DeleteI wonder if you can help I still get Not Found
ReplyDeleteThe requested URL /nagios/< was not found on this server.
Hi. That would tend to indicate that the web server is running, but for some other reason the Nagios page isn't operative. I can't really suggest why unfortunately. Try a repeat of the install and see if the problem is consistent.
DeleteWorks great for me! Thanks for the guide!
ReplyDeleteWorks great for me! Thanks for the guide!
ReplyDeleteHi!
ReplyDeleteThis is useless:
mkdir /etc/httpd
mkdir /etc/httpd/conf.d
mkdir /etc/httpd/conf.d/nagios.conf
make install-webconf
You do the config with:
install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf
That is all you need. It writes the Config to /etc/apache2/sites-enabled/nagios.conf.
The Path under /etc/httpd/conf.d is old and inactive stuff.
Read here, Point 10 (Sorry, is in german): https://help.ubuntu.com/lts/serverguide/httpd.html
Thanks! That's a great link and the good news is that Ubuntu appears to auto translate it :-). I should clearly go through the instructions and update them.
DeleteGood tutorial, perfect function
ReplyDeleteroot@mackapi:~# apt-get install apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev
ReplyDeleteReading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libgd-dev' instead of 'libgd2-xpm-dev'
Package libapache2-mod-php5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'libapache2-mod-php5' has no installation candidate
root@mackapi:~#
anyone hit this issue?
This has occurred with the transition from using PHP 5 to PHP 7 with Raspbian. There are some different ways to approach resolving this outlined here https://www.raspberrypi.org/forums/viewtopic.php?t=195818
DeleteGreat turorial, even applies tot latest version of Nagios, just need to change the filenames
ReplyDeleteHello. Everything went ok but upon connecting to my Nagios, all i can see is the... page's source code
ReplyDeletePlease accept my apologies. This book and the versions of software that it is referencing is pretty old. I suspect that is where things haven't gone according to the instructions. Over time I have moved away from Nagios to a Prometheus / Grafana stack which I have found a lot more flexible. If you are interested in that option you could check out the following - https://leanpub.com/rpcmonitor
Delete