nagios利用NRPE监控CPU、负载、磁盘IO
1.在监控机上安装NRPE
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
 
2.在被监控机上安装nagios插件和NRPE
(1).先增加nagios用户:
useradd nagios

(2.)安装nagios插件:
tar -zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios
make
make install

(3).安装nrpe:
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --prefix=/usr/local/nagios
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd    nrpe安装为xinetd服务(有些服务器没有xinet下面介绍一个通用的方法)

(4).编辑nrpe配置文件,增加监控机地址:
#vi /etc/xinetd.d/nrpe
only_from  = 127.0.0.1 10.1.1.14               

(5).修改services文件,增加端口
#vi /etc/services
nrpe            5666/tcp                        #NRPE

(6).重启xinetd服务
service xinetd restart


没有xinet情况下  make install-xinetd 这一步就不需要编译了~
首先,需要修改/usr/local/nagios/etc/nrpe.cof。
 
找到“allowed_hosts=127.0.0.1”将其改为:
 
allowed_hosts=127.0.0.1,$Nagios监控平台的地址或域名

启动NRPE守护进程:(可以将此命令加入/etc/rc.local,以便开机自动启动)
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d 
此命令生成的日志会在系统的日志(/var/log/message)中。如果没有出错,就基本搞定了。

(7).查看服务是否启动
#/usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12
如果出现Connection refused by host 需要安装yum intall openssl*
至此被监控机上的操作就结束了,如果有需要增加监控项,需修改/etc/xinetd.d/nrpe文件。
 
3.修改监控机上commands.cfg文件,增加check_nrpe的定义:
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

4.在监控机上测试与被监控机的通讯是否正常:
[root@test1 objects]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
OK - load average: 0.05, 0.06, 0.00|load1=0.050;15.000;30.000;0; load5=0.060;10.000;25.000;0; load15=0.000;5.000;20.000;0;
能够正常获取信息。


vim /usr/local/nagios/etc/nrpe.cfg

修改 allowed_hosts=127.0.0.1,10.1.1.14(监控机)

增加
command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2  --意思是监控第二个分区

command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%   -监控内存


修改监控机的services.cfg

增加需要监控的服务
5.修改服务配置文件:
增加:


###########     监控CPU负载

define service {
host_name  1.1.1.1
name                           cpu
service_description             checkLoad           服务描述
check_period                    24x7                监控周期
max_check_attempts              4                   最大检查尝试数
normal_check_interval           3                   正常检测间隔时间
retry_check_interval            2                   重试检测间隔时间
contact_groups                  tomasgroup          联系组
notification_interval           10                  通知间隔                      
notification_period             24x7                通知周期
notification_options            w,u,c,r             通知类型
check_command check_nrpe!check_load

                       }


 ###########监控第二个硬盘

define service {
host_name  1.1.1.1
service_description            checkdisk2
check_period                   24x7
max_check_attempts             4
normal_check_interval          3
retry_check_interval           2
contact_groups                 tomasgroup
notification_interval          10           
notification_period            24x7
notification_options           w,u,c,r
check_command check_nrpe!check_sda2
                       }