Nagiosインストール(Client)

NagiosインストールといってもClient側はNagios PluginsとNRPEのみインストールする。

ユーザ追加(Client)

groupadd -g 2002 nagios
useradd -u 2002 -g nagios -m -d /usr/local/nagios -s /bin/sh nagios
chmod 755 /usr/local/nagios

Nagios Pluginsダウンロード(Client)

cd /usr/local/src
wget -c http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz

Nagios Pluginsインストール(Client)

tar zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

NRPEダウンロード(Client)

cd /usr/local/src
wget -c http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz

NRPEインストール(Client)

apt-get update
apt-get install libssl-dev
tar zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure --enable-ssl --with-command-args
make all
make install

NRPE設定(Client)

mkdir -p /usr/local/nagios/etc
chown nagios. /usr/local/nagios/etc
cp -a /usr/local/src/nrpe-2.13/sample-config/nrpe.cfg /usr/local/nagios/etc/.
vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,[ServerIP]
command[check_users]=/usr/local/nagios/libexec/check_users -w 2 -c 4
command[check_load]=/usr/local/nagios/libexec/check_load -w 5.0,4.0,3.0 -c 10.0,6.0,4.0
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 30% -c 10% -p /
command[check_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 60 -c 30
command[check_ssh]=/usr/local/nagios/libexec/check_ssh -p 22 [HOSTNAME]

起動スクリプト作成(Client)

そのままでは自動起動設定時にエラーが出る為、起動スクリプトにLSBを追記。

cp /usr/local/src/nrpe-2.13/init-script.debian /etc/init.d/nrpe
chmod 755 /etc/init.d/nrpe
vi /etc/init.d/nrpe
### BEGIN INIT INFO
# Provides:          nrpe
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: NRPE start/stop script.
# Description:       Start and stop NRPE.
### END INIT INFO

services追記(Client)

nrpeを追記。

vi /etc/services
nrpe            5666/tcp

自動起動設定、起動(Client)

update-rc.d nrpe defaults
/etc/init.d/nrpe start

Nagios設定(Server側)

hostgroup.cfg修正
vi /usr/local/nagios/etc/objects/hostgroup.cfg
# Real Server Group
define hostgroup{
        hostgroup_name  real-servers
        alias           Real Servers
        members         localhost,[HOSTNAME]
        }

# [HOSTNAME]
define host{
        use                     linux-server
        host_name               [HOSTNAME]
        alias                   [HOSTNAME]
        address                 [IPADDR]
        }
servicegroup.cfg
vi /usr/local/nagios/etc/objects/servicegroup.cfg
define servicegroup{
        servicegroup_name	server-resource
        alias			Server Resource
        members			localhost,DISK,localhost,LOAD,localhost,LOGIN,localhost,PROC,localhost,SWAP,localhost,PING,localhost,SSH,[HOSTNAME],DISK,[HOSTNAME],LOAD,[HOSTNAME],LOGIN,[HOSTNAME],PROC,[HOSTNAME],SWAP,[HOSTNAME],PING,[HOSTNAME],SSH
        }
commands.cfg修正
vi /usr/local/nagios/etc/objects/commands.cfg
# 'check_nrpe' command definition
define command{
 	command_name	check_nrpe
	command_line	$USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
	}
server.cfg修正
vi /usr/local/nagios/etc/servers/[HOSTNAME].cfg
define service{
	use			generic-service
	host_name		[HOSTNAME]
	service_description	PING
	check_command		check_ping!100.0,20%!500.0,60%
	}

define service{
	use			generic-service
	host_name		[HOSTNAME]
	service_description	LOAD
	check_command		check_nrpe!check_load
	}

define service{
	use			generic-service
	host_name		[HOSTNAME]
	service_description	DISK
	check_command		check_nrpe!check_disk
	}

define service{
	use			generic-service
	host_name		[HOSTNAME]
	service_description	LOGIN
	check_command		check_nrpe!check_users
	}

define service{
	use			generic-service
	host_name		[HOSTNAME]
	service_description	PROC
	check_command		check_nrpe!check_procs
	}

define service{
 	use			generic-service
	host_name		[HOSTNAME]
	service_description	SWAP
	check_command		check_nrpe!check_swap
	}

define service{
	use			generic-service
	host_name		[HOSTNAME]
	service_description	SSH
	check_command		check_nrpe!check_ssh
	}

Nagios再起動(Server)

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios restart