For the next series we will be discussing installing and configuring Nagios for monitoring. The series will include installing Nagios, plugins, agents and various custom monitors. Also, adding other features including graphing and performance charting. Nagios is a powerful monitoring tools used by many IT departments and has the support of the Open Source community. So let’s get started!
Our choice for OS is Scientific Linux 6.0 which is based on RHEL 6.0, a good stable and enterprise level OS. the current version of Nagios is 3.3.1. There are several pieces to Nagios that we will need to install, the core and plugins. This will give us the base installation we need to get running with Nagios. Once they are installed and configured we will install the agents on the systems we want to monitor.
Logon to your Linux installation and download the Nagios Core and the plugins packages from here.
Prerequisites
During portions of the installation you’ll need to have root access to your machine.
Lets download the following packages on your Fedora / RHEL installation before continuing.
- Apache
- PHP
- GCC compiler
- GD development libraries
Change to root (sudo su -)
# yum install httpd php
# yum install gcc glibc glibc-common
# yum install gd gd-devel
Create Nagios Account and Group
Create a new nagios user account and give it a password.
# /usr/sbin/useradd -m nagios
# passwd nagios
Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.
# /usr/sbin/groupadd nagcmd
# /usr/sbin/usermod -a -G nagcmd nagios
# /usr/sbin/usermod -a -G nagcmd apache
Change into a directory or make one for downloading the Nagios Core and plugins then download them using the following commands.
Download the source code tarballs of both Nagios and the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions). These directions were tested with Nagios 3.3.1 and Nagios Plugins 1.4.15.
# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.3.1.tar.gz
# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
Now we can extract and compile the code.
# tar xzf nagios-3.3.1.tar.gz
# cd nagios
Run the Nagios configure script, passing the name of the group you created earlier like so:
# ./configure --with-command-group=nagcmd
When the configure completes you will receive a summary.
*** Configuration summary for nagios 3.3.1 07-25-2011 ***:
General Options:
————————-
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu
Web Interface Options:
————————
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute
Now let’s start to compile the Nagios Core source code.
# make all
Install binaries, init script, sample config files and set permissions on the external command directory.
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf
Now we have Nagios installed but not started, at this point we need to do a bit of customization.
Customize Configuration
Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios.
Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.
# vi /usr/local/nagios/etc/objects/contacts.cfg
Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# New password:
# Re-type new password:
# Adding password for user nagiosadmin
Restart Apache to make the new settings take effect.
# service httpd restart
Compile and Install the Nagios Plugins
Extract the Nagios plugins source code tarball.
# tar xzf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
Compile and install the plugins.
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install
Start Nagios
Add Nagios to the list of system services and have it automatically start when the system boots.
# chkconfig --add nagios
# chkconfig nagios on
Verify the sample Nagios configuration files. This is very important to find the errors and correct them before starting.
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Running pre-flight check on configuration data…
Checking services…
Checked 8 services.
Checking hosts…
Checked 1 hosts.
Checking host groups…
Checked 1 host groups.
Checking service groups…
Checked 0 service groups.
Checking contacts…
Checked 1 contacts.
Checking contact groups…
Checked 1 contact groups.
Checking service escalations…
Checked 0 service escalations.
Checking service dependencies…
Checked 0 service dependencies.
Checking host escalations…
Checked 0 host escalations.
Checking host dependencies…
Checked 0 host dependencies.
Checking commands…
Checked 24 commands.
Checking time periods…
Checked 5 time periods.
Checking for circular paths between hosts…
Checking for circular host and service dependencies…
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 there are no errors, start Nagios.
# service nagios start
Modify SELinux Settings
Fedora / RHEL ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by default. This can result in “Internal Server Error” messages when you attempt to access the Nagios CGIs.
See if SELinux is in Enforcing mode.
# getenforce
Put SELinux into Permissive mode.
# setenforce 0
To make this change permanent, you’ll have to modify the settings in /etc/selinux/config and reboot.
Instead of disabling SELinux or setting it to permissive mode, you can use the following command to run the CGIs under SELinux enforcing/targeted mode:
# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
# chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
For information on running the Nagios CGIs under Enforcing mode with a targeted policy, visit the Nagios Support Portal or Nagios Community Wiki.
Login to the Web Interface
You should now be able to access the Nagios web interface at the URL below. You’ll be prompted for the username (nagiosadmin) and password you specified earlier.
http://localhost/nagios/
Click on the “Service Detail” navbar link to see details of what’s being monitored on your local machine. It will take a few minutes for Nagios to check all the services associated with your machine, as the checks are spread out over time.
Now we have the base Nagios installation running. Look for the next part in the series where we will cover installing the agents!
Note: If you have a fresh install of CentOS 6.2 you will run into an issue with iptables blocking incoming port 80 so you will not be able o bring up Nagios console. Thanks to G Hamilton for reminding me of this feature.
To add the exception perform the following steps.
# iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# service iptables save
# service iptables restart