Table of Contents

Building Nagios on CentOS 5

Nagios Core

Source used: nagios-3.2.0

Prepare user and group:

useradd -r -d /var/lib/nagios -s /bin/sh -c "nagios" nagios
/usr/sbin/usermod -G nagios apache
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd apache

Compile and install:

cd /unpacked-src-folder
./configure \
	--prefix=/usr \
	--exec-prefix=/usr/sbin \
	--bindir=/usr/sbin \
	--sbindir=/usr/lib/nagios/cgi \
	--libexecdir=/usr/lib/nagios/plugins \
	--datadir=/usr/share/nagios \
	--sysconfdir=/etc/nagios \
	--localstatedir=/var/lib/nagios \
	--with-init-dir=/etc/rc.d/init.d \
	--with-cgiurl=/nagios/cgi-bin \
	--with-htmurl=/nagios \
	--with-lockfile=/var/run/nagios.pid \
	--with-nagios-user=nagios \
	--with-nagios-group=nagios \
        --with-command-group=nagcmd \
	--with-file-perfdata \
	--disable-embedded-perl \
	--without-perlcache \
	--with-gd-lib=/usr/lib \
	--with-gd-inc=/usr/include \
	--with-template-objects \
	--with-template-extinfo \
        --enable-nanosleep

make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf

chkconfig --add nagios
chkconfig nagios on

Plugins

Source used: nagios-plugins-1.4.14

./configure \
 --prefix=/usr \
 --libexecdir=/usr/lib/nagios/plugins \
 --sysconfdir=/etc/nagios \
 --with-cgiurl=/nagios/cgi-bin \
 --without-ipv6

make
make install

Also install dependencies using cpan:

install Net::SNMP

NRPE

Source used: nrpe-2.12

yum install openssl-devel 

./configure \
  --prefix=/usr \
  --libexecdir=/usr/lib/nagios/plugins \
  --sysconfdir=/etc/nagios

make all
cp src/check_nrpe /usr/lib/nagios/plugins/

Additional steps for a monitored target

Install nrpe daemon:

# setup the daemon
cp src/nrpe /usr/bin/
chmod 755 /usr/bin/nrpe
chown root:root /usr/bin/nrpe

# setup the config file
mkdir -p /etc/nagios/
cp sample-config/nrpe.cfg /etc/nagios/

# setup the init script
cp init-script /etc/init.d/nrpe
chmod 755 /etc/init.d/nrpe
chown root:root /etc/init.d/nrpe
chkconfig nrpe on

NSCA

Source used: nsca-2.7.2

./configure --prefix=/usr --sysconfdir=/etc/nagios
make all
cp src/nsca /usr/sbin/
cp src/send_nsca /usr/bin/
cp sample-config/nsca.cfg /etc/nagios/
cp sample-config/send_nsca.cfg /etc/nagios/

Edit the config file /etc/nagios/nsca.cfg to your needs. Normally these:

# this should match with the option "command_file=" in nagios.cfg
command_file=/var/lib/nagios/rw/nagios.cmd

alternate_dump_file=/var/lib/nagios/rw/nsca.dump

Edit the config file /etc/nagios/send_nsca.cfg to your needs.

Make sure xinetd is installed and running:

yum install xinetd

Make sure /etc/services contains the port definition:

nsca            5667/tcp                        # Nagios NSCA daemon

Create /etc/xinetd.d/nsca for running by xinetd:

nsca
# default: on
# description: NSCA (Nagios Service Check Acceptor)
service nsca
{
        disable = no
        flags           = REUSE
        socket_type     = stream
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/sbin/nsca
        server_args     = -c /etc/nagios/nsca.cfg --inetd
        #log_on_failure  += USERID
        #only_from       = 127.0.0.1
}