Nagios – Installation, Configuration, and Use
Operating System: Debian Etch 4.0
An excellent resource to deploying Nagios is a book by Wolfgang Barth called "Nagios System and Network Monitoring" from No Scratch Press. It goes into nice detail on how to get the basics running or write your own plugins if you wish, plus many 3rd party tools to assist in monitoring.
Installation
First install the essential packages needed to compile and use Nagios as root.
apt-get install build-essential
apt-get install openssl
apt-get install apache2 mysql-server libmysqlclient-dev
apt-get install gcc make autoconf automake libgd ntpdate libperl-dev libnet-snmp-perl libdbd-sybase-perl
Create the users and groups that will be used to run Nagios.
groupadd -g 9001 nagcmd
useradd -u 9000 -g nagios -G nagcmd -d /usr/local/nagios -c "Nagios Admin" nagios
Add the Apache dameon user to Nagios group, which by default in Debian is www-data.
Now setup the initial directories and permissions where we'll keep the files. I chose to create /home/nagios because that's where I'll store the data files since the home partition is the largest on the server.
chown nagios:nagios /usr/local/nagios /etc/nagios /home/nagios
Download the Nagios source and unpack.
wget http://superb-east.dl.sourceforge.net/sourceforge/nagios/nagios-3.x.x.tar.gz
tar zxvf nagios-3.x.x.tar.gz
Build the source including the location of the directories created previously. The sysconfdir is pretty standard, but localstatedir needs to have a bit more space if you have it.
Observe configuration summary and make sure everything is OK.
General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Embedded Perl: yes, with caching
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: /home/nagios/nagios.lock
Check result directory: /home/nagios/spool/checkresults
Init directory: /etc/init.d
Apache conf.d directory: /etc/apache2/conf.d
Mail program: /usr/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): /usr/sbin/traceroute
If the config looks OK, compile all:
make install
make install-init
make install-commandmode
make install-config
This will allow Nagios to be started upon boot.
Now download and install the latest batch of plugins so Nagios has something to run. Again, pay close attention to the configure statement so that the directories are the same as those specified for compiling Nagios itself.
wget http://superb-west.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.x.tar.gz
tar zxvf nagios-plugins-1.4.x
cd nagios-plugins-1.4.x
./configure --sysconfdir=/etc/nagios --localstatedir=/home/nagios --enable-perl-modules
make
make check
make install
Test the ICMP plugin since it is a necessary component.
Configuration
Configure the Nagios web interface (Apache):
make install-webconf
/etc/init.d/apache2 reload
Create an htaccess file for simple authentication into the Nagios monitoring site.
htpasswd -c htpasswd.users nagios
chown www-data htpasswd.users
chmod 600 htpasswd.users
Be sure when you add other users that can login, you add them to the cgi.cfg as well.
For easier readability and configuration, set configuration site with a unique name. This will help if you're monitoring multiple sites and will have many config files. Notice the primary and global config files are in /etc/nagios but the primary configurations that need editing can go under it. Nagios will recursively check all files the end with .cfg.
mv objects mysite
Third-party Utilities
These utilities make it easier to manage and gather information from Nagios, especially for reporting reasons.
NDOUtils
Download and install ndoutils for database storage of performance data.
wget http://superb-east.dl.sourceforge.net/sourceforge/nagios/ndoutils-1.4.x.tar.gz
tar zxvf ndoutils-1.4.x.tar.gz
Check to make sure you're using the right versions for compatibility.
define CURRENT_OBJECT_STRUCTURE_VERSION 307 /* increment when changes are made to data structures... */
fgrep CURRENT_OBJECT_STRUCTURE_VERSION ndoutils-1.4.x/include/*/objects.h
include/nagios-2x/objects.h:#define CURRENT_OBJECT_STRUCTURE_VERSION 2
include/nagios-3x/objects.h:#define CURRENT_OBJECT_STRUCTURE_VERSION 307 /* increment when changes are made to data structures... */
./configure --sysconfdir=/etc
make
cd src
cp ndo2db-3x ndomod-3x.o log2ndo file2sock /usr/local/nagios/bin/
Prepare MySQL for ndoutils.
mysql> grant usage on *.* to 'nagios'@'localhost' identified by 'password' with max_queries_per_hour 0 max_connections_per_hour 0 max_updates_per_hour 0;
mysql> grant select, insert, update, delete on 'nagios_perfdata'.* to 'nagios'@'localhost';
mysql> flush privileges;
mysql> quit
cd /usr/src/ndoutil-1.4.x/db
mysql -u root -p nagios_level3 < mysql.sql
Configure ndoutil for use.
cp config/ndo*.cfg /etc/nagios/
cd /etc/nagios
Modify /etc/nagios/ndomod.cfg:
Test the ndoutil daemon and see if it runs.
ls -l /home/nagios/ndo.sock srwxr-xr-x 1 nagios nagios 0 2009-01-02 15:02 /home/nagios/ndo.sock
kill -9 [ndo2db-3x pid]
rm /home/nagios/ndo.sock
Create an inet daemon for ndoutil.
cp skeleton ndo2db-3x
chmod 755 ndo2db-3x
Edit the new ndo2db-3x file:
### BEGIN INIT INFO
# Provides: ndo2db-3x
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Ryan Rosiek
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="ndoutil daemon startup for ndo2db-3x"
NAME=ndo2db-3x
DAEMON=/usr/local/nagios/bin/$NAME
DAEMON_ARGS="-c /etc/nagios/ndo2db.cfg"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
...
do_stop() {
...
# Remove sock file
rm -r /home/nagios/ndo.sock
...
}
...
Modify the Nagios config to start event broker module.
...
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/etc/nagios/ndomod.cfg
Start the services.
Log into the database and make sure information is being written.
mysql> use nagios_level3
mysql> select * from nagios_objects where objecttype_id=2;
NRPE
NRPE makes it easier to run service checks on remote clients. First add it to the server.
wget http://localhost/nrpe-2.x.tar.gz
tar zxvf nrpe-2.x.tar.gz
cd nrpe-2.x.tar.gz
./configure --sysconfdir=/etc/nagios --localstatedir=/home/nagios --enable-ssl=no
make
make install
Note: SSL was not configured in this case because all monitoring traffic is internal and no access to this network is allowed
NSClient++
The NSClient++ is a great utility to run on Windows servers and for NRPE to check. Download latest client and unzip.
- Create folder C:\Program Files\NSClient
- Copy unzipped files into this folder
- Uncomment these lines in NSC.ini
;CheckSystem.dll
;CheckDisk.dll
;CheckEventLog.d
;allowed_hosts= (under Settings)
;use_file=1
;allow_arguments=1
;port=5666
;use_ssl=0
Comment out:
In a command prompt:
cd "Program Files\NSClient"
NSClient++ /install





