一.在被監(jiān)控端(lvs主機(jī))上安裝nrpe以及nagios-plugins,具體如下:
1)安裝nagios-plugins
groupadd nagios
useradd -g nagios nagios
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
tar -zxf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --enable-redhat-pthread-workaround
make && make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec
2)安裝nrpe
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar -zxf nrpe-2.12.tar.gz
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
二.修改/etc/xinetd.d/nrpe的文件
1)在only_from參數(shù)里加入nagios服務(wù)器的IP地址(中間用英文逗號(hào)隔開)
vi /etc/xinetd.d/nrpe
only_from = 127.0.0.1,xxx.xxx.xxx.xxx #監(jiān)控服務(wù)器的可信IP
2),在/etc/services中添加NRPE
vi /etc/services
nrpe 5666/tcp #NRPE
3),service xinetd restart
檢查NRPE 是否運(yùn)行
#netstat -at | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
4).修改nrpe.cfg文件
vi /usr/local/nagios/etc/nrpe.cfg
找到allowed_hosts=127.0.0.1
allowed_hosts=127.0.0.1,xxx.xxx.xxx.xxx #監(jiān)控服務(wù)器的可信IP
添加
command[check_conn]=/usr/local/nagios/libexec/check_lvs
5)運(yùn)行nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
6)運(yùn)行check_nrpe腳本
/usr/local/nagios/libexec/check_nrpe -H localhost
若出現(xiàn)NRPE版本信息則表示成功,若出現(xiàn)openssl表示openssl沒有被安裝,安裝openssl yum -y install openssl*
7)修改/etc/sudoers
找到 #Defaults requiretty 并取消注釋,另外新增一行。表示nagios用戶不需要登陸終端就可以調(diào)用命令。
Defaults requiretty
Defaults:nagios !requiretty
#添加nagios 請(qǐng)求sudo,允許特定指令時(shí)(可跟參數(shù)),不需要密碼(如)。
nagios ALL=(ALL) NOPASSWD: ALL
三.建立check_lvs腳本并將其保存至/usr/local/nagios/libexec/目錄下:
#!/bin/bash
#Author: uxin
ACT_COUNT=0
Inactive_count=0
stat1=`sudo ipvsadm | grep http |wc -l`
if [ $stat1 -ne 0 ];then
for NUM in `sudo ipvsadm | grep http | awk '{print $5}'`
do
ACT_COUNT=$(($ACT_COUNT+ $NUM))
done
for NUM in `sudo ipvsadm | grep http | awk '{print $6}'`
do
Inactive_count=$(($Inactive_count+ $NUM))
done
else
echo "LVS CRITICAL, "LVS is Down""
exit 2
fi
if [ $ACT_COUNT == 0 ];then
echo "LVS ok, "0 active connection""
exit 1
else
echo "LVS OK - LVS is running (conn: $ACT_COUNT active, $Inactive_count inactive)|active=$ACT_COUNT;80000;99999;0; inactive=$Inactive_count;80000;99999;0;"
fi
OK ,在監(jiān)控端運(yùn)行
/usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xxx.xxx -c check_conn,好了配置成功
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。