nagios客户端程序的安装(翻译官方文档 NRPE.pdf)

要监视客户机的本地信息需要用到nrpe这个程序
NRPE的原理如下图
NRPE总共由两部分组成:
? check_nrpe 插件,位于在监控主机上
? NRPE daemon,运行在远程的linux主机上(通常就是被监控机)
按照上图,整个的监控过程如下:
当nagios需要监控某个远程linux主机的服务或者资源情况时
1.nagios会运行check_nrpe这个插件,告诉它要检查什么.
2.check_nrpe插件会连接到远程的NRPE daemon,所用的方式是SSL
3.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增加用户
[root@dbpi root]# useradd nagios
设置密码
[root@dbpi root]# passwd nagios
 
2安装nagios插件
解压缩
tar -zxvf nagios-plugins-1.4.9.tar.gz
cd nagios-plugins-1.4.9
编译安装
./configure
make
make install
这一步完成后会在/usr/local/nagios/下生成两个目录libexec和share
[root@dbpi local]# ls /usr/local/nagios/
libexec  share
修改目录权限
[root@dbpi local]# chown nagios.nagios /usr/local/nagios
[root@dbpi local]# chown -R nagios.nagios /usr/local/nagios/libexec
 
3安装nrpe
解压缩
tar -zxvf nrpe-2.8.1.tar.gz
cd 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: nagios
Review 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, you
can continue with the installation or upgrade process.
Read the PDF documentation (NRPE.pdf) for information on the next
steps you should take to complete the installation or upgrade.
接下来安装NPRE插件,daemon和示例配置文件
 
安装check_nrpe这个插件
make install-plugin
之前说过监控机需要安装check_nrpe这个插件,被监控机并不需要,我们在这里安装它是为了测试的目的
安装deamon
make install-daemon
安装配置文件
make install-daemon-config
 
现在再查看nagios目录就会发现有4个目录了
[root@dbpi nrpe-2.8.1]# ls /usr/local/nagios/
bin      etc      libexec  share
按照安装文档的说明,是将NRPE deamon作为xinetd下的一个服务运行的.在这样的情况下xinetd就必须要先安装好,不过一般系统已经默认装了
 
4.安装xinetd脚本
[root@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 services
nrpe            5666/tcp                        # nrpe
重启xinetd服务
[root@dbpi nrpe-2.8.1]# service xinetd restart
Stopping xinetd: [  OK  ]
Starting xinetd: [  OK  ]
 
查看NRPE是否已经启动
[root@dbpi nrpe-2.8.1]# netstat -at|grep nrpe
tcp        0      0 *:nrpe                  *:*                     LISTEN   
[root@dbpi nrpe-2.8.1]# netstat -an|grep 5666
tcp        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的版本
[root@dbpi nrpe-2.8.1]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE 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/etc
vi nrpe.cfg
找到下面这段话
# The following examples use hardcoded command arguments...
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[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插件
[root@server1 yahoon]# tar -zxvf nrpe-2.8.1.tar.gz
[root@server1 yahoon]# cd nrpe-2.8.1
[root@server1 nrpe-2.8.1]# ./configure
[root@server1 nrpe-2.8.1]# make all
[root@server1 nrpe-2.8.1]# make install-plugin
只运行这一步就行了,因为只需要check_nrpe插件
 
在dbpi上我们刚装好了nrpe,现在我们测试一下监控机使用check_nrpe与被监控机运行的nrpedaemon之间的通信.
[root@server1 nrpe-2.8.1]# /usr/local/nagios/libexec/check_nrpe -H 192.168.0.100
NRPE 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 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中定义对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命令.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值