要实现资源和服务两个方面的监控,需要配置服务器端(nagios server)及被监控端 

(NRPE-nagios remote plugin executor).为了能顺利地、有条理的部署nagios 监控平台, 
一个好的工作风格是在nagios server 自身实现服务和资源的监控,然后再在其他监控端部 
署nrpe,从nagios server 端用check_nrpe 测试通过后,再在nagios server 配置文件中逐 
一增加监控项目。当然如果只是监控服务而不监控主机资源,则被监控端不做任何nrpe 的 
安装。为了方便初学者更容易上手和成功,我们就从简单的步骤开始。 
1. 在配监控的机器安装nrpe 
1)增加用户 
[root@cacti ~]# useradd nagios 
[root@cacti ~]# passwd nagios 
2)安装nagios 插件 
[root@cacti ~]# cd /srv/ 
[root@cacti srv]# tar zvxf nagios-plugins-1.4.14.tar.gz 
[root@cacti srv]# cd nagios-plugins-1.4.14 
[root@cacti nagios-plugins-1.4.14]# ./configure --enable-redhat-pthread-workaround 
[root@cacti nagios-plugins-1.4.14]# make 
[root@cacti nagios-plugins-1.4.14]# make install 
3)修改目录权限 
[root@cacti nagios-plugins-1.4.14]# chown nagios:nagios /usr/local/nagios 
[root@cacti nagios-plugins-1.4.14]# chown -R nagios:nagios /usr/local/nagios/libexec 
4)安装nrpe 
[root@cacti nagios-plugins-1.4.14]# cd .. 
[root@cacti srv]# tar zxvf nrpe-2.12.tar.gz 
[root@cacti srv]# cd nrpe-2.12 
[root@cacti nrpe-2.12]# ./configure 
[root@cacti nrpe-2.12]# make all 
(1) 安装check_nrpe 这个插件 
[root@cacti nrpe-2.12]# make install-plugin 
(2) 安装deamon 
[root@cacti nrpe-2.12]# make install-daemon 
(3) 安装配置文件 
[root@cacti nrpe-2.12]# make install-daemon-config 
(4) 编辑nrpe配置文件 
[root@cacti nrpe-2.12]# vi /usr/local/nagios/etc/nrpe.cfg(更改如下) 
allowed_hosts=127.0.0.1,192.168.10.8 
默认为allowed_hosts=127.0.0.1 
5) 启动nrpe 
[root@cacti nrpe-2.12]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d 
6) 查看NRPE 是否已经启动 
[root@cacti nrpe-2.12]# netstat -nltp |grep nrpe 
tcp 0 0 0.0.0.0:5666 0.0.0.0:* 
LISTEN 5163/nrpe 
7) 测试NRPE 是否则正常工作 
之前安装了check_nrpe 这个插件用于测试,现在就是用的时候.执行 
[root@cacti nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H localhost 
NRPE v2.12 
2. 在监控机器上安装nrpe 
之前已经将nagios 运行起来了,现在要做的事情是: 安装check_nrpe 插件 
在commands.cfg 中创建check_nrpe 的命令定义,因为只有commands.cfg 
中定义过的命令才能在services.cfg 中使用创建对被监控主机的监控项目 
1)安装check_nrpe 插件 
# tar -zxvf nrpe-2.8.1.tar.gz 
# cd nrpe-2.8.1 
# ./configure 
# make all 
# make install-plugin 
只运行这一步就行了,因为只需要check_nrpe 插件 
2)在apache 刚装好了nrpe,现在我们测试一下监控机使用 
check_nrpe 与被监控机运行的nrpedaemon 之间的通信. 
# /usr/local/nagios/libexec/check_nrpe -H 192.168.10.195 
NRPE v2.8.1 
看到已经正确返回了NRPE 的版本信息,说明一切正常. 
3)在commands.cfg 中增加对check_nrpe 的定义 
# 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$ 

意义如下 
command_name check_nrpe 
定义命令名称为check_nrpe,在services.cfg 中要使用这个名称. 
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 
这是定义实际运行的插件程序.这个命令行的书写要完全按照check_nrpe 这个命令的 
用法.不知道用法的就用check_nrpe –h 查看-c 后面带的$ARG1$参数是传给nrpe 
daemon 执行的检测命令,之前说过了它必须是nrpe.cfg中所定义的那5 条命令中的其 
中一条.在services.cfg 中使用check_nrpe 的时候要用!带上这个参数 
########################################### 
举例: 
下面就可以在services.cfg 中定义对apache 主机磁盘容量的监控 
define service{ 
host_name apache 
被监控的主机名,这里注意必须是linux 且运行着nrpe,而且必须是hosts.cfg 中定义的 
service_description check-disk 
监控项目的名称 
check_command check_nrpe!check_disk 
监控命令是check_nrpe,是在commands.cfg 中定义的,带的参数是check_disk,是 
在nrpe.cfg 中定义的 
max_check_attempts 5 
normal_check_interval 3 
retry_check_interval 2 
check_period 24x7 
notification_interval 10 
notification_period 24x7 
notification_options w,u,c,r 
contact_groups sagroup 

像这样将其余几个监控项目加进来.