****在被监控主机安装nrpe****

(1)在被监控主机上,增加用户和密码

useradd nagios

passwd nagios

(2)安装nagios插件

tar zxf nagios-plugins-1.4.15.tar.gz(nagios-plugins-1.4.15放任意位置,一般习惯放在/opt目录下)

cd nagios-plugins-1.4.15

./configure --prefix=/usr/local/nagios

make

make install

chown nagios:nagios /usr/local/nagios/

chown nagios:nagios /usr/local/nagios/libexec/ -R

(3.1)安装nrpe

tar zxf nrpe-2.12.tar.gz(nrpe-2.12.tar.gz放在任意位置,一般习惯放在/opt目录下)

cd nrpe-2.12

./configure(会默认安装在/usr/local/nagios目录下)

make all

make install-plugin

make install-daemon

make install-daemon-config

(3.2)修改nrpe.conf文件

修改以下内容,将nagios监控主机的ip添加到allowed_hosts字段

allowed_hosts=127.0.0.1,监控主机Ip

否则在监控主机上运行/usr/local/nagios/libexec/check_nrpe -H 远端被监控机ip

时会报以下错误CHECK_NRPE: Error - Could not complete SSL handshake.

(3.3)安装xinetd脚本

在nrpe-2.12目录下执行

make install-xinetd

编辑xinetd脚本

vi /etc/xinetd.d/nrpe

在only_from后面增加监控主机的地址,以空格间隔

only_from       = 127.0.0.1,监控主机Ip

编辑/etc/services文件,增加nrpe服务

vi /etc/services

# Local services

nrpe            5666/tcp                        # nrpe

(3.4)重启xinetd服务

/etc/init.d/xinetd restart

(3.5)启动nrpe服务

检查nrpe服务是否启动

#ps aux|grep nrpe

如果nrpe没有启动,启动nrpe服务

# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

再次查看nrpe是否已经启动,端口是否正常监听

netstat -at|grep nrpe

tcp        0      0 *:nrpe                      *:*                      LISTEN

netstat -ant | grep 5666

tcp        0      0 0.0.0.0:5666                0.0.0.0:*                LISTEN

(3.6)测试nrpe是否正常工作

/usr/local/nagios/libexec/check_nrpe -H localhost

NRPE v2.12(正确的返回值)

(3.7)查看nrpe的监控命令

cd /usr/local/nagios/etc/

vi nrpe.cfg

找到可以监控的命令

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

(3.8)在监控主机上检查nrpe是否可以练到远端的nrpe

在监控主机上运行

#/usr/local/nagios/libexec/check_nrpe -H 远端监控主机ip

NRPE v2.12(正确的返回值)

这样远端nrpe安装成功,并保证监控主机可以连接远端的nrpe

****安装check_traffic插件****

(1)下载chech_traffic.sh

chech_traffic.sh并不是nagios-plugins自带插件,所以需要自行下载

下载后,将chech_traffic.sh放在/usr/local/nagios/libexec/chech_traffic.sh

修改chech_traffic.sh的权限为777,用户及用户组为nagios

chmod 777 chech_traffic.sh

choen nagios:nagios chech_traffic.sh

(2)安装并配置chech_traffic.sh的依赖服务

脚本准本好以后

在执行

#/usr/local/nagios/libexec/chech_traffic.sh  -V 2c -C public -H ***.***.***.*** -I 2 -w 200,300 -c 400,500 -K -B

提示以下错误:

which: no snmpwalk in (/opt/jdk1.6.0_25/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/bin:/opt/dell/srvadmin/sbin:/root/bin)

Can not found command snmpwalk in you system PATH: /opt/jdk1.6.0_25/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/bin:/opt/dell/srvadmin/sbin:/root/bin, pleas check it

是因为chech_traffic.sh依赖snmp服务

(2.1)安装snmp

如果/etc/下已有snmp文件夹,说明snmp已经安装

若果没有,需要安装snmp

因为是redhat系统,首先选择rpm安装

下载对应版本的snmp

rpm -ivh net-snmp-5.3.2.2-7.el5.x86_64.rpm

提示:libsensors.so.3()(64bit) is needed by package 1:net-snmp-5.3.2.2-7.el5.x86_64

依赖libsensors.so.3()(依赖这个库是因为snmp来依赖其他的一些服务)

选择用yum安装,解决依赖库的问题

yum install net-snmp* -y

得知安装net-snmp依赖以下:

lm_sensors*;beecrypt*;elfutils*

下载相应的rpm包,或是使用yum安装以上,再使用

rpm -ivh net-snmp-5.3.2.2-7.el5.x86_64.rpm 安装,即可安装成功

安装成功后,会有/etc/snmp文件

(2.2)配置snmp.conf

修改以下:

# group context sec.model sec.level prefix read write notif

access notConfigGroup "" any noauth exact mib2 none none

##去掉下面此行行首注释#。

view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

备注:有些情况是将snmp.conf里面的以下字段也进行了修改,添加了被监控主机ip

# sec.name source community
com2sec notConfigUser 被监控机ip public

修改了以后再被监控上运行

/usr/local/nagios/libexec/chech_traffic.sh  -V 2c -C public -H ***.***.***.*** -L

提示noresponse form ....

于是就将com2sec notConfigUser 被监控机ip public的被监控ip去掉以后,就可以正常运行了

(3)执行check_traffic.sh

/usr/local/nagios/libexec/chech_traffic.sh  -V 2c -C public -H ***.***.***.*** -I 2 -w 200,300 -c 400,500 -K -B

-I 2 监控的网卡(2是网卡多对应的index值)

-w 200,300 warning的范围

-c 400,500 critical的范围

-K -B是单位

-H 被监测流量的主机ip

使用/usr/local/nagios/libexec/chech_traffic.sh  -V 2c -C public -H ***.***.***.*** -L

可以查看主机的网卡对应的index值

Interface index 1 orrresponding to lo

Interface index 2 orrresponding to eth0

Interface index 3 orrresponding to eth1

使用ifconfig,如果你监控的网卡是eth1,那么-I的参数就是3,即,-I 3

如果执行

#/usr/local/nagios/libexec/chech_traffic.sh  -V 2c -C public -H ***.***.***.*** -I 2 -w 200,300 -c 400,500 -K -B

OK - It's the first time for this plugins run. We'll get the data from the next time

说明check_traffic.sh可以在被测机上正确执行了

(4)将check_traffic.sh命令添加到nrpe.conf中

command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H ***.***.***.*** -I 2 -w 200,300 -c 400,500 -K -B

保存,重启nrpe服务

在被监控机上执行

/usr/local/nagios/libexec/check_nrpe -H ***.***.***.*** -c check_traffic

可能会提示:

SERVICE ALERT: ***.***.***.***;;traffic;UNKNOWN;SOFT;3;Unknown - Read or Write File /var/tmp/check_traffic_***.***.***.***;_11.hist_dat_root__32 Error with user uid=517(nagios) gid=517(nagios) groups=517(nagios)

是因为以非nagios用户身份,手动测试执行过该脚本(也就是command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H ***.***.***.*** -I 2 -w 200,300 -c 400,500 -K -B这个操作),请在正式使用该脚本前,删除/var/tmp下对应测试生成的/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件,否则会造成nagios用户无法读写该文件的错误

删除/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件后

再次执行

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_traffic

可以看见流量的统计结果

(5)在监控主机上验证的被监控上的check_traffic.sh是否可以成功执行

在监控主机上执行/usr/local/nagios/libexec/check_nrpe -H ***.***.***.*** -c check_traffic

得到流量统计结果,可以将check_traffic配到监控主机的服务里面,在nagios上可以监控到远端主机的流量了

以上check_traffic.sh只能监控到某一个网卡的全部流量,一旦nagios流量过高,出现警告,如何排查那个进程所占用的流量

可以使用nethogs工具,可以监控某块网卡上每个进程的流量,可以使用nethogs工具自行写个脚本,监控你所关心的进程流量,配合check_traffic.sh插件使用

redhat--nagios插件--check_traffic.sh的更多相关文章

  1. nagios 配置 check_traffic 流量监控模块(被监控端)

    安装软件包yum -y install net-snmp*chkconfig nrpe onchkconfig snmpd on 使用SCP命令拷贝 check_traffic.sh 到 / usr/ ...

  2. nagios 配置 check_traffic 流量监控模块(Server 端)

    安装软件包yum -y install net-snmp*chkconfig nrpe onchkconfig snmpd onchkconfig nagios on 修改snmp参数,vi /etc ...

  3. 使用nagios插件 check_mysql_health 过程中遇到的error

    使用nagios插件 check_mysql_health 过程中遇到的error 1.如果在运行监控mysql插件的时候遇到了error安装以下依赖包就可以解决: yum install perl- ...

  4. nagios 插件ndoutils 安装配置

    nagios 插件ndoutils 安装配置 原文地址:http://www.cnblogs.com/caoguo/p/5022645.html # Nagios install ndoutils # ...

  5. nagios插件nagiosql安装配置

    nagios插件nagiosql安装配置 # Nagiosql install [root@Cagios ~]# yum install -y libssh2 libssh-devel [root@C ...

  6. nagios插件之登陆SBC监控电话数

    运行:sbc_calls_status_new auto_ssh_sbc_10_17.sh | auto_ssh_sbc_11_17.sh vi sbc_calls_status_new.c #inc ...

  7. nagios插件之登陆防火墙实现session监控

    ssh_firewall_session.sh -- 登陆防火墙并运行dis session statistics firewall_check_sessions.c -- 调用上面脚本.过滤出ses ...

  8. 用python 写一个nagios插件 监控http内容(转载)

     nagios自带的http-check插件主要是检测地址url是否可以访问,在web+中间件的架构中容易出现url能访问,但是后台中间件拓机的情况,因为最近在自学python,所以写了个脚本检测ur ...

  9. nagios插件之监控if8接口日志(新接口)

    vi check_if8_log.c #include <stdio.h> #include <stdlib.h> #include <string.h> #inc ...

随机推荐

  1. PHP之cookie相关实例教程与经典代码

    ·php 中cookie和session的用法比较 ·php会话控制cookie与Session会话处理 ·php中利用cookie实现购物车实例 ·php中cookie与session应用学习笔记 ...

  2. 什么是REST架构(转)

    REST架构风格是全新的针对Web应用的开发风格,是当今世界最成功的互联网超媒体分布式系统架构,它使得人们真正理解了Http协议本来面貌.随着 REST架构成为主流技术,一种全新的互联网网络应用开发的 ...

  3. POJ 1922

    #include<iostream>cheng da cai zi 11.21 //#include<stdio.h> #include<math.h> using ...

  4. java基础知识回顾之javaIO类--RandomAccessFile类

    java.io 类 RandomAccessFile java.lang.Object java.io.RandomAccessFile1.该类不是IO流中的子类.2.该类既能读又能写.3.该对象内部 ...

  5. SDUT1466双向队列

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1466&cid=1182 题目描述 想想双向链表……双向队列的定义差不多,也就是说一个队列 ...

  6. NuGet学习笔记——初识NuGet及快速安装使用

    源自:http://kb.cnblogs.com/page/143190/

  7. C++和pascal之间的通信

    // MyFirst.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include "Winsock2.h"#pragm ...

  8. iOS开发--浅谈CocoaAsyncSocket编程

    Socket就是一种特殊的文件.它是一个连接了两个用户的文件,任何一个用户向Socket里写数据,另一个用户都能看得到,不管这两个用户分布在世界上相距多么遥远的角落,感觉就像坐在一起传纸条一样. 这么 ...

  9. CentOS 7.0安装Nvidia驱动

    entOS 7.0 Nvidia显卡安装步骤: 1 在英伟达官网下载相应驱动 搜索出相应的驱动后,不要直接点,而是右健,Save Link as... 否则,会出现下载半天没动静的情况. 存放的路径上 ...

  10. Filter登录验证过滤器(全局)

    通过Filter来定义一个登录验证过滤器,这是就不需要在每一个JSP页面添加判断用户合法性的代码了. 以下示例中包含了5个文件,一个是登录表单LoginForm.jsp,一个是登录判断页LoginCo ...