nagios監控對於你們而言,已經並不陌生,相信它工做的原理及相互間的調用關係也有必定的瞭解,在生產環境中,監控linux服務器很明顯你們都知道能夠藉助nrpe來檢測間接的監控。node
其實,監控分爲兩類【本身理解定義】,一類是主動式,好比像ping、ssh之類,只須要監控主機執行相應的命令就能夠實現監控;另外一類是被動式,也就是監控主機這是抽象爲了客戶端用於接收數據,藉助nrpe插件實現與被監控端的通訊,好比像disk、load等。linux
對於主動式的監控,天然主動在監控主機手裏,參數的設置與修改天然不是問題,而對於被動式的監控,好比之前我想監控服務器的根分區使用狀況,如今因爲生產環境的改變須要去監控/home分區的使用,並且可能我磁盤使用的告警值也須要修改,若是還分別登陸到被監牢主機上去修改相應的參數顯然不是很明智的選擇。若是咱們監控主機可以變被動爲主動,得到修改參數的權力,豈不很好,下面就來配置說明一下,供你們參考。ios
監控主機想變爲主動,很明顯,被監控主機要容許傳參數,因此就要在被監控主機上下些功夫。centos
一、被監控主機上從新編譯nrpe bash
./configure --enable-command-args 服務器
make allssh
make install-pluginide
make install-daemon測試
make install-daemon-configspa
二、打開容許傳遞參數
dont_blame_nrpe=0 ---》 dont_blame_nrpe=1
三、設置帶參數的檢測指令[示例]
command[check_disk]=/usr/local/nagios/libexec/check_disk -w$ARG1$ -c $ARG2$ -p $ARG3$
四、reload nrpe,
kil -HUP `ps-ef |grep nrpe |grep -v grep | awk'{print $2}'`
###########################################################
下面就監控主機上的操做
注意,監控主機的其他配置不在此說明了,只簡述與傳參配置相關的。
1、先直接執行命令測試:
[root@localhost libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.15.183 -c check_disk -a 20% 15% /
DISK OK - free space: / 14250 MB (79% inode=91%);|/=3645MB;15083;16025;0;18854
2、定義命令模板
vi /usr/local/nagios/etc/objects/commands.cfg
添加
define command {
command_name check_remote_disk
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_disk -a $ARG1$ $ARG2$ $ARG3$
}
3、修改主機配置文件
vi /usr/local/nagios/etc/objects/services.cfg
修改添加
define service{
use generic-service
host_name centos6
service_description check_load
check_command check_remote_load!20%!10%!/
}
四、檢測語法,重載nagios
[root@localhost~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@localhost~]# service nagios reload
附上被監控主機的安裝及初始化腳本,
安裝腳本:
#! /bin/bash #install nagios-plugins,nrpe #auth colynn.liu echo 'install nagios-plugins,nrpe....' wget -t 3 -T 15 http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz wget -t 3 -T 15 http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.13/nagios-plugins-1.4.13.tar.gz useradd nagios -s /sbin/nologin -M tar zxf nagios-plugins-1.4.13.tar.gz cd nagios-plugins-1.4.13 ./configure --prefix=/usr/local/nagios make && make install cd .. tar zxf nrpe-2.12.tar.gz cd nrpe-2.12 sed -i '1657 s/^/\/\*/' src/nrpe.c sed -i '1662 s/^/\*\//' src/nrpe.c ./configure --enable-command-args make all make install-plugin make install-daemon make install-daemon-config echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.d/rc.local echo "DONE."
經過參數實現更合理監控
#! /bin/bash # CONFFILE=/usr/local/nagios/etc/nrpe.cfg MASTERIP=192.168.15.188 cd /usr/local/nagios/etc/ && cp nrpe.cfg nrpe.cfg.$(date +%Y%m%d-%H).bak && echo "bakup is succeess nrpe.cfg.$(date +%Y%m%d-%H).bak" sed -i "/allowed_hosts/s/allowed_hosts=127.0.*/allowed_hosts=127.0.0.1,${MASTERIP}/" $CONFFILE && echo "allowed_hosts add successfully" sed -i '/dont_blame_nrpe/s/dont_blame_nrpe=0/dont_blame_nrpe=1/' $CONFFILE sed -i '/^command\[/s/^/#/' $CONFFILE sed -i '/\$$/s/^#//' $CONFFILE ###start nrpe PID=`ps -ef |grep nrpe |grep -v grep | awk '{print $2}'` if [ -z $PID ] then /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d else kill -HUP $PID && echo "reload nrpe is ok" fi