一.在被监控端(lvs主机)上安装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参数里加入nagios服务器的IP地址(中间用英文逗号隔开)
vi /etc/xinetd.d/nrpe
only_from = 127.0.0.1,xxx.xxx.xxx.xxx #监控服务器的可信IP
2),在/etc/services中添加NRPE
vi /etc/services
nrpe 5666/tcp #NRPE
3),service xinetd restart
检查NRPE 是否运行
#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 #监控服务器的可信IP
添加
command[check_conn]=/usr/local/nagios/libexec/check_lvs
5)运行nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
6)运行check_nrpe脚本
/usr/local/nagios/libexec/check_nrpe -H localhost
若出现NRPE版本信息则表示成功,若出现openssl表示openssl没有被安装,安装openssl yum -y install openssl*
7)修改/etc/sudoers
找到 #Defaults requiretty 并取消注释,另外新增一行。表示nagios用户不需要登陆终端就可以调用命令。
Defaults requiretty
Defaults:nagios !requiretty
#添加nagios 请求sudo,允许特定指令时(可跟参数),不需要密码(如)。
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 ,在监控端运行
/usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xxx.xxx -c check_conn,好了配置成功
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com