There are two ways to install Nagios on CentOS: install from a package, or build from source.
Installing from a package is faster, but you will run into limitations if you try to customize Nagios. For example, you won’t be able to customize the Nagios status-map CGI code. If you want Nagios to log to a SQL backend (for using things like NagVis for SLA purposes) you have to build from source.
I recommend building from source. It’s cleaner than yum, in my opinion, and allows all sorts of fun options to be compiled in.
Note this isn’t a full Nagios guide; just how to build from source.
This is for Nagios Core version 3.4.1 (October 2012).
Setup users and groups
useradd nagios;groupadd nagios
usermod -G nagios nagios
Download the source to your src directory
tar -xvf nagios-3.4.1.tar.gz
mv nagios nagios-3.4.1
The configure script will run and check for appropriate dependencies. Fix as needed.
It’ll also show Nagios’ various config options in a ‘Configuration Summary’ at the end of its output.
Note that building from source installs Nagios in /usr/local/nagios, rather than all over the place as with the yum version.
Verify Nagios runs
service nagios start
service nagios restart
Install web config
In this step, we install a basic Nagios Apache2 config to /etc/httpd/conf.d/nagios.conf. We then create an htpasswd file, which is the backend for Nagios’ web interface password authentication. We use the username ‘nagiosadmin,’ but you can use whatever you want as it’s not referenced elsewhere.
If you ever lose your login, you can delete the htpasswd.users file, then make a new one with the htpasswd command.
By default, Nagios is accessed through http://yourserver/nagios. If you want the simpler URL (http://yourserver) then add the VirtualHost entry shown below.
Go to the Nagios source directory.
Install a fresh nagios.conf file into Apache2′s conf.d directory.
Edit the password for nagiosadmin.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Add a new VirtualHost directive to the nagios.conf file. Save and quit vim when done. (Esc, then :wq to save and quit)
# add these lines between ScriptAlias and the first Directory entry
At this point, it’s a good idea to browse to Nagios and verify that its interface appears. Clicking the Service Status view will result in a lot of “plugin missing” messages, so install the Nagios plugins next.
Install plugin dependencies
Not strictly needed, but adds MySQL, SNMP, and LDAP functionality.
yum install mysql-devel net-snmp-utils openldap-devel
(Tested with 1.4.16 – October 2012)
tar -xvf nagios-plugins-1.4.16.tar.gz
There should now be a directory at /usr/local/nagios/libexec containing the plugins.
Fix permissions on Nagios’ command directory
Commands from the web GUI to the Nagios process are done through the nagios.cmd file in the /usr/local/nagios/var/rw directory.
Both apache (the user that httpd runs as) and nagios (the user that Nagios runs as) need read-write access to this directory.
To achieve this, we will create a group strictly for those users who need to touch that directory. The group is called “nagioscmd.”
We then set the sticky bit for the “rw” directory, so any new files inside it will inherit the rw directory’s permissions.
usermod -G nagioscmd nagios
usermod -G nagioscmd apache
chown nagios.nagioscmd /usr/local/nagios/var/rw
chmod u+rwx /usr/local/nagios/var/rw
chmod g+rwx /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
At this point you should have a core Nagios installation. Proceed to configure it as per the Nagios documentation.