|
要监视客户机的本地信息需要用到nrpe这个程序
NRPE的原理如下图
NRPE总共由两部分组成:? check_nrpe 插件,位于在监控主机上? NRPE daemon,运行在远程的linux主机上(通常就是被监控机)按照上图,整个的监控过程如下:当nagios需要监控某个远程linux主机的服务或者资源情况时1.nagios会运行check_nrpe这个插件,告诉它要检查什么.2.check_nrpe插件会连接到远程的NRPE daemon,所用的方式是SSL3.NRPE daemon会运行相应的nagios插件来执行检查4.NRPE daemon将检查的结果返回给check_nrpe插件,插件将其递交给nagios做处理.注意:NRPE daemon需要nagios插件安装在远程的linux主机上,否则,daemon不能做任何的监控. 通过NRPE的检测分为两种:1).直接检测:检测的对象是运行NRPE的那台linux主机的本地资源,原理如下图
2).间接检测:当运行nagios的监控主机无法访问到某台被监控机,但是运行NRPE的机器可以访问到时,NRPE就可以充当一个代理,将监控请求发送到被监控机
必须要说明的是,通常被监控机与监控机在同一网络内,所以这样的情况很少.下面我讲的都是直接检测.所以我们按照图示在监控主机(nagios-server)和被监控主机(dbpi,也就是图中运行NRPE的remote linux host)上安装相应的软件 一,在被监控主机上1增加用户[iyunv@dbpi root]# useradd nagios设置密码[iyunv@dbpi root]# passwd nagios 2安装nagios插件解压缩tar -zxvf nagios-plugins-1.4.9.tar.gzcd nagios-plugins-1.4.9编译安装./configuremakemake install这一步完成后会在/usr/local/nagios/下生成两个目录libexec和share[iyunv@dbpi local]# ls /usr/local/nagios/libexec share修改目录权限[iyunv@dbpi local]# chown nagios.nagios /usr/local/nagios[iyunv@dbpi local]# chown -R nagios.nagios /usr/local/nagios/libexec 3安装nrpe解压缩tar -zxvf nrpe-2.8.1.tar.gzcd nrpe-2.8.1编译./configure输出如下*** Configuration summary for nrpe 2.8.1 05-10-2007 ***: General Options: ------------------------- NRPE port: 5666 NRPE user: nagios NRPE group: nagios Nagios user: nagios Nagios group: nagiosReview the options above for accuracy. If they look okay,type 'make all' to compile the NRPE daemon and client.可以看到NRPE的端口是5666,下一步是make all make all输出如下*** Compile finished ***If the NRPE daemon and client compiled without any errors, youcan continue with the installation or upgrade process.Read the PDF documentation (NRPE.pdf) for information on the nextsteps you should take to complete the installation or upgrade.接下来安装NPRE插件,daemon和示例配置文件 安装check_nrpe这个插件make install-plugin之前说过监控机需要安装check_nrpe这个插件,被监控机并不需要,我们在这里安装它是为了测试的目的安装deamonmake install-daemon安装配置文件make install-daemon-config 现在再查看nagios目录就会发现有4个目录了[iyunv@dbpi nrpe-2.8.1]# ls /usr/local/nagios/bin etc libexec share按照安装文档的说明,是将NRPE deamon作为xinetd下的一个服务运行的.在这样的情况下xinetd就必须要先安装好,不过一般系统已经默认装了 4.安装xinetd脚本[iyunv@dbpi nrpe-2.8.1]# make install-xinetd输出如下/usr/bin/install -c -m 644 sample-config/nrpe.xinetd /etc/xinetd.d/nrpe可以看到创建了这个文件/etc/xinetd.d/nrpe编辑这个脚本vi /etc/xinetd.d/nrpe# default: on# description: NRPE (Nagios Remote Plugin Executor)service nrpe{ flags = REUSE socket_type = stream port = 5666 wait = no user = nagios group = nagios server = /usr/local/nagios/bin/nrpe server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd log_on_failure += USERID disable = no only_from = 127.0.0.1在后面增加监控主机的地址0.111,以空格间隔}改后 only_from = 127.0.0.1 192.168.0.1 编辑/etc/services文件,增加NRPE服务vi /etc/services增加如下# Local servicesnrpe 5666/tcp # nrpe重启xinetd服务[iyunv@dbpi nrpe-2.8.1]# service xinetd restartStopping xinetd: [ OK ]Starting xinetd: [ OK ] 查看NRPE是否已经启动[iyunv@dbpi nrpe-2.8.1]# netstat -at|grep nrpetcp 0 0 *:nrpe *:* LISTEN [iyunv@dbpi nrpe-2.8.1]# netstat -an|grep 5666tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 可以看到5666端口已经在监听了 5.测试NRPE是否则正常工作之前我们在安装了check_nrpe这个插件用于测试,现在就是用的时候.执行/usr/local/nagios/libexec/check_nrpe -H localhost会返回当前NRPE的版本[iyunv@dbpi nrpe-2.8.1]# /usr/local/nagios/libexec/check_nrpe -H localhostNRPE v2.8.1也就是在本地用check_nrpe连接nrpe daemon是正常的注:为了后面工作的顺利进行,注意本地防火墙要打开5666能让外部的监控机访问 /usr/local/nagios/libexec/check_nrpe ?h查看这个命令的用法可以看到用法是check_nrpe ?H 被监控的主机 -c要执行的监控命令注意:-c后面接的监控命令必须是nrpe.cfg文件中定义的.也就是NRPE daemon只运行nrpe.cfg中所定义的命令 查看NRPE的监控命令cd /usr/local/nagios/etcvi nrpe.cfg找到下面这段话# The following examples use hardcoded command arguments...command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommand[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200红色部分是命令名,也就是check_nrpe 的-c参数可以接的内容,等号=后面是实际执行的插件程序(这与commands.cfg中定义命令的形式十分相似,只不过是写在了一行).也就是说check_users就是等号后面/usr/local/nagios/libexec/check_users -w 5 -c 10的简称.我们可以很容易知道上面这5行定义的命令分别是检测登陆用户数,cpu负载,hda1的容量,僵尸进程,总进程数.各条命令具体的含义见插件用法(执行”插件程序名 ?h”)由于-c后面只能接nrpe.cfg中定义的命令,也就是说现在我们只能用上面定义的这五条命令.我们可以在本机实验一下.执行/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users/usr/local/nagios/libexec/check_nrpe -H localhost -c check_load/usr/local/nagios/libexec/check_nrpe -H localhost -c check_hda1/usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs/usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs 二.在运行nagios的监控主机上之前已经将nagios运行起来了,现在要做的事情是:? 安装check_nrpe插件? 在commands.cfg中创建check_nrpe的命令定义,因为只有在commands.cfg中定义过的命令才能在services.cfg中使用? 创建对被监控主机的监控项目安装check_nrpe插件[iyunv@server1 yahoon]# tar -zxvf nrpe-2.8.1.tar.gz[iyunv@server1 yahoon]# cd nrpe-2.8.1[iyunv@server1 nrpe-2.8.1]# ./configure[iyunv@server1 nrpe-2.8.1]# make all[iyunv@server1 nrpe-2.8.1]# make install-plugin只运行这一步就行了,因为只需要check_nrpe插件 在dbpi上我们刚装好了nrpe,现在我们测试一下监控机使用check_nrpe与被监控机运行的nrpedaemon之间的通信.[iyunv@server1 nrpe-2.8.1]# /usr/local/nagios/libexec/check_nrpe -H 192.168.0.100NRPE v2.8.1看到已经正确返回了NRPE的版本信息,说明一切正常. 在commands.cfg中增加对check_nrpe的定义vi /usr/local/nagios/etc/commands.cfg在最后面增加如下内容########################################################################## 2007.9.5 add by yahoon# NRPE COMMAND########################################################################## 'check_nrpe ' command definitiondefine 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中定义对dbpi主机cpu负载的监控define service{ host_name dbpi被监控的主机名,这里注意必须是linux且运行着nrpe,而且必须是hosts.cfg中定义的 service_description check-load 监控项目的名称 check_command check_nrpe!check_load 监控命令是check_nrpe,是在commands.cfg中定义的,带的参数是check_load,是在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 }像这样将其余四个监控项目加进来. 之前我们说过了,今天还有一个任务是要监控dbpi的swap使用情况.但是很遗憾,在nrpe.cfg中默认没有定义这个监控功能的命令.怎么办?手动在nrpe.cfg中添加,也就是自定义NRPE命令. |
|