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.
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-getinstall.
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
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
Compile 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 nagiosin 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.
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;
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;
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
We’ve managed to successfully install Nagios on a Raspberry Pi! Now all we need to do is to use it :-)
The post above (and heaps of other stuff) is in the book 'Just Enough Linux' that can be downloaded for free (or donate if you really want to :-)).