****在被監控主機安裝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插件使用