redhat--nagios插件--check_traffic.sh

****在被監控主機安裝nrpe****html

(1)在被監控主機上,增長用戶和密碼linux

useradd nagiosios

passwd nagiostcp

(2)安裝nagios插件工具

tar zxf nagios-plugins-1.4.15.tar.gz(nagios-plugins-1.4.15聽任意位置,通常習慣放在/opt目錄下)測試

cd nagios-plugins-1.4.15this

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

makepwa

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插件使用

相關文章
相關標籤/搜索