Ubuntu Server 13: Nagios 4

Installing Nagios on Ubuntu (or any Debian) isn’t smooth or easy; and the instructions that are on Nagios’s site don’t work. Through much trial and error and Googling I have finally managed to get a good installation working. I had the same issues with Nagios 3.5, and while there are older packages you can install from apt-get, they seem to be broken, or set up in some weird way I can’t fathom. I prefer to install from scratch as much as possible, both for compiling to my environment and for learning. This should probably still work on Ubuntu Server 12.x and Nagios 3.5 also.

Note: As usual I use vim (vi type editor, but easier to use), and in this case we are going to make ourselves root since there are so many commands, using sudo over and over again will be too much work. I also recommend starting from a fresh but completely updated box.

Here we go! Do the following commands:

If everything goes ok and there are no config errors, continue on:

Now, the init script that comes with Nagios does not work in Debian. It was made for RedHat/CentOS. Someone kindly uploaded an older script for Nagios that does work for Debian. Do the following to replace the broken script easily:

First, delete the old file:

Then, make a new file:

and paste the contents below:

Save and exit.
Note: If you are in VIM through ssh/putty, you can just right-click and it pastes in perfectly.

Next, make the file executable:

Finally, start the Nagios service and restart Apache2:

At this point you will have seen another error when apache2 restarts. See this post to fix the Apache2 Fully Qualified Name Error.

Now, you should be able to go to your machine in a web browser. Go to http://yourmachineipornamehere/nagios.

Optional but recommended:
If you would like the service to start up automatically on boot (which is recommended), just add it to rc.d: