Nagios监控lvs服务
1在lvs server上安装nrpe客户端:
1.1,rpm方式安装nrpe客户端
下载地址:http://download.csdn.net/detail/mchdba/7493875
[root@localhost nagios]# ll 总计 768
-rw-r--r-- 1 root root 713389 12-16 12:08 nagios-plugins-1.4.11-1.x86_64.rpm
-rw-r--r-- 1 root root 32706 12-16 12:09 nrpe-2.12-1.x86_64.rpm
-rw-r--r-- 1 root root 18997 12-16 12:08 nrpe-plugin-2.12-1.x86_64.rpm
[root@localhost nagios]# rpm -ivh *.rpm --nodeps --force
1.2 在配置文件最末尾,加入配置信息以及监控主机serverip地址
[root@ localhost nagios]# vim /etc/nagios/nrpe.cfg
# add by tim on 2014-06-11
command[check_users]=/usr/local/nagios/libexec/check_users -w 8 -c 15
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda
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 50 -c 80
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 750 -c 800
command[check-host-alive]=/usr/local/nagios/libexec/check_ping -H localhost -w 3000.0,80% -c 5000.0,100% -p 5
allowed_hosts = 127.0.0.1, 10.2xx.3.xx
check下命令是否生效:
[root@web-9 nrpe-2.15]# /usr/local/nagios/libexec/check_users -w 8 -c 15
USERS OK - 2 users currently logged in |users=2;8;15;0
[root@web-9 nrpe-2.15]#
看到已经USERS OK -….命令已经生效。
1.3 启动nrpe报错例如以下:
[root@web-9 ~]# service nrpe restart
Shutting down nrpe: [失败]
Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory
[失败]
[root@web-9 ~]#
[root@db-m2-slave-1 nagios_client]# service nrpe start
Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory
[失败]
[root@db-m2-slave-1 nagios_client]#
建立连接
[root@db-m2-slave-1 nagios_client]# ln -s /usr/lib64/libssl.so /usr/lib64/libssl.so.6
(假设没有libssl.so,就採用别的libssl.so.10来做软连接,ln -s /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6)
[root@db-m2-slave-1 nagios_client]#
再又一次启动例如以下:
[root@db-m2-slave-1 nagios_client]# service nrpe start
Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libcrypto.so.6: cannot open shared object file: No such file or directory
[失败]
[root@web-10 ~]# ll /usr/lib64/libcrypto.so
lrwxrwxrwx. 1 root root 18 10月 13 2013 /usr/lib64/libcrypto.so -> libcrypto.so.1.0.0
[root@db-m2-slave-1 nagios_client]#
再建链接:
[root@db-m2-slave-1 nagios_client]# ln -s /usr/lib64/libcrypto.so /usr/lib64/libcrypto.so.6
(或者假设没有libcrypto.so,就採用libcrypto.so.10做软连接, ln -s /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.6)
[root@db-m2-slave-1 nagios_client]# service nrpe start
Starting nrpe: [确定]
[root@db-m2-slave-1 nagios_client]#
1.4 检測下nrpe是否正常执行:
去nagiosserver端check下
[root@cache-2 ~]# /usr/local/nagios/libexec/check_nrpe -H xx.xx3.xx
NRPE v2.12
[root@cache-2 ~]#
[root@cache-2 ~]# /usr/local/nagios/libexec/check_nrpe -H xx.xx3.xx
NRPE v2.12
[root@cache-2 ~]#
看到返回NRPE v2.15表示已经连接成功。
2 编写shell脚本实现lvs监控
2.1 监控脚本
Nagios里面没有现成的监控lvs的状态脚本,所以须要去网上找一个简单的监控脚本check_lvs.sh,copy到/usr/lib/nagios/plugins/文件夹,赋予nagios权限,脚本内容例如以下:
#!/bin/bash
# http://www.ohlinux.com/archives/632/
# add by tim on 20140613
USAGE_Method=\"$(basename $0)[-h|--hostname] <Free ip or hostname> [-w|--warning] <Free integer> [-c|--critical] <Free integer>\"
USAGE_Value=\"warning value must be small than critical value: `basename $0` $*\"
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3 if [ $# -lt 4 ];then
echo
echo \"Usage: $USAGE_Method\"
echo
exit 0
fi
while [ $# -gt 0 ];
do
case \"$1\" in
-w|--warning)
shift
warning=$1
;;
-c|--critical)
shift
critical=$1
;;
esac
shift
done if [[ $warning == $critical || $warning -gt $critical ]]
then
#echo $warning
#echo $critical
echo \"$USAGE_Value\"
echo \"Usage: $USAGE_Method\"
exit 0
fi ACT_COUNT=0
Inactive_count=0
stat1=`sudo ipvsadm | grep http | grep Route|wc -l`
if [ $stat1 -ne 0 ];then
for NUM in `sudo ipvsadm | grep http | grep Route | awk \'{print $5}\'`
do
ACT_COUNT=$(($ACT_COUNT+ $NUM))
done
for NUM in `sudo ipvsadm | grep http | grep Route | awk \'{print $6}\'`
do
Inactive_count=$(($Inactive_count+ $NUM))
done
else
echo \" stat1:$stat1, lvs critical,lvs is down now.\"
exit 3
fi if [[ \"$ACT_COUNT\" -gt \"$critical\" ]]
then
echo \"critical - lvs connetion is : $ACT_COUNT active\"
exit 2
fi
if [[ \"$ACT_COUNT\" -gt \"$warning\" && \"$ACT_COUNT\" -lt \"$critical\" ]]
then
echo \"warning - lvs connetions is : $ACT_COUNT active\"
exit 1
fi
if [[ \"$ACT_COUNT\" -lt \"$warning\" || $ACT_COUNT == 0 ]]
then
echo \"LVS OK - LVS is running (conn: $ACT_COUNT active, $Inactive_count inactive)|active=$ACT_COUNT;69999;99999;0; inactive=$Inactive_count;69999;99999;0;\"
exit 0
fi
2.2 nrpe.cfg里面配置例如以下
Vim /etc/nagios/nrpe.cfg,在里面加入一行check_lvs命令:
command[check_lvs]=/usr/lib/nagios/plugins/check_lvs -w 300 -c 600
之后重新启动nrpe
[root@/root/nagios/check_lvs ~]# service nrpe restart;
Shutting down nrpe: [确定]
Starting nrpe: [确定]
[root@/root/nagios/check_lvs ~]#service nrpe restart;
2.3 去nagios服务端check一下
[root@cache-2 ~]# /usr/local/nagios/libexec/check_nrpe -H 1x.xx4.x.x5 -c check_lvs
lvs critical,lvs is down now.
[root@cache-2 ~]#
看到check出来lvs服务已经处于down模式。
说明:因为check_lvs是要调用ipvsadm命令来获取LVS状态的,而ipvsadm命令是仅仅能以root用户来执行的, 所以须要将nagios用户设置成能够无需password直接su成root,这样就能以nagios用户执行命令sudo /usr/lib/nagios/plugins/check_lvs 。在centos系统中,无法直接调用sudo命令,须要改动/etc/sudoers, 找到 #Defaults requiretty 并取消凝视,另外新增一行。表示nagios用户不须要登陆终端就能够调用命令,例如以下所看到的:
Defaults requiretty
Defaults:nagios !requiretty
#加入nagios 请求sudo,同意特定指令时(可跟參数),不须要password(如)。
nagios ALL=(ALL) NOPASSWD: ALL
再去naigosserver上面check下,已经生效,例如以下所看到的:
[root@cache-2 etc]# /usr/local/nagios/libexec/check_nrpe -H 10.xx.xx.xx -c check_lvs
LVS OK - LVS is running (conn: 16 active, 77 inactive)|active=16;69999;99999;0; inactive=77;69999;99999;0;
[root@cache-2 etc]#
2.4 在nagiosserver上加入配置
vim services.cfg
define service{
host_name lvs-lan
service_description Check lvs
check_command check_nrpe!check_lvs
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,c,r
contact_groups opsweb
}
vim objects/commands.cfg
define command{
command_name check_lvs
command_line $USER1$/check_lvs -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
}
之后又一次载入nagios既完毕了对lvs的监控服务。
[root@cache-2 etc]# service nagios reload
Running configuration check...
Reloading nagios configuration...
done
[root@cache-2 etc]#
至此,nagios以下对lvs服务的监控已经完毕。
參考资料:http://c20031776.blog.163.com/blog/static/684716252013627506890/
Nagios监控lvs服务的更多相关文章
- 通过Nagios监控weblogic服务
1.前言 前段时间搭建了一套Nagios监控服务,心血来潮想自己写一个脚本,拓展Nagios插件来监控公司的weblogic服务. 环境:weblogic10.3.3.0 . CentOS6 ...
- Nagios监控nginx服务具体过程
1在nginx 服务器上安装nrpe客户端: Nginx的服务须要监控起来.不然万一down了而不及时修复,会影响web应用.例如以下web应用上面启动的nginx后台进程[root@lb-net-2 ...
- nagios监控远程主机服务可能出现的问题
1.使用插件NRPE监控命令不存在 在添加服务的时候,命令配置文件中需要传递一个参数,那么在监控服务配置文件中,需要添加一个!表示后面的为参数. 出现未定义的命令,查看被监控主机上的配置文件,添加监控 ...
- 一步步实现Nagios监控linux主机及飞信报警
一步步实现Nagios监控linux主机及飞信报警 上篇文章介绍了在linux主机上架设nagios监控服务,并对windows主机进行服务状态变化的监控,这次我们继续上次内容. 首先实现n ...
- Nagios监控mongodb分片集群服务实战
1,监控插件下载 Mongodb插件下载地址为:git clone git://github.com/mzupan/nagios-plugin-mongodb.git,刚開始本人这里没有安装gitpu ...
- Nagios监控服务
Nagios监控服务 案例1:常用系统监控命令 案例2:搭建nagios监控服务器 案例3:配置文件及插件使用 案例4:监控远程主机的公有数据 案例5:监控远程主机的私有数据 1 案例1:常用系统监控 ...
- [工具开发] keepalived使用nagios监控脚本
最近在做开发和办公环境的高可用,采用的是keepalived:keepalived基于Linux内核支持的LVS,既能实现高可用,又能实现负载均衡,非常实用. keepalived监控服务状态时可以用 ...
- Nagios监控平台搭建
Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员, ...
- nagios二次开发(四)---nagios监控原理和nagios架构简介
nagios监控原理 下面根据上面摘自网络的原理图对nagios的监控原理进行一下简单的说明: 1.nagios通过nsca进行被动监控.那么什么是被动监控呢?被动监测:就是指由被监测的服务器主动上传 ...
随机推荐
- Android决议具体解释
1.Android手机常见的分辨率 WVGA:800x480 FWVGA:854x480 QHD:960x540 720P:1280x720(SD.standard definition,SD) 10 ...
- hdu4499 Cannon (DFS+回溯)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4499 Cannon ...
- apache tomcat 集群! (转)
公司需要一个内部测试局域网, 要求可以支持3000并发访问!以前也没做过服务器这方面.临时抱佛脚,查看了N多文档,他人经验,布置好之后,又遇到了N多问题,功夫不负有心人.终于还是完成了要求!观他人的布 ...
- Codeforces Beta Round #3 A. Shortest path of the king
标题效果: 鉴于国际棋盘两点,寻求同意的操作,是什么操作的最小数量,在操作过程中输出. 解题思路: 水题一个,见代码. 以下是代码: #include <set> #include < ...
- java科学和艺术语言 第六章 课后编程
家转载,为保留作者成果.转载请注明出处,http://blog.csdn.net/netluoriver,有些文件在资源中也能够下载!假设你没有积分,能够联系我索要. 1. package Sixth ...
- android可扩展自己的定义,运动图像裁剪框
在实际项目中,常常要制作一个简易的图像裁剪功能,即获取一张图片.并用一个遮罩层选择目标范围并截取保存的功能.例如以下图所看到的: 在此分享下该自己定义视图的制作过程. 需求说明 整一个视图包括一个透明 ...
- 有趣 IOS 开展 - block 使用具体解释
Block 它是iOS于4.0新的程序语法之后,于iOS SDK 4.0之后,block应用几乎无处不在. 在其他语言中也有类似的概念,称为闭包(closure),实例object C兄弟swift ...
- NET MVC
NET MVC 1.为 Action 标注 Attribute 限制访问 public class HomeController : Controller { [HttpPost] public Ac ...
- webserver实现
最近的工作需求client和server使用https协议进行通讯,我负责client编写程序,在操作系统的-depth理解认为一旦前webserver实现,整理代码: #include"a ...
- 关于在同一母版页中使用多个CSS文件的解决方案
原文:关于在同一母版页中使用多个CSS文件的解决方案 以前都用.NET1.1没遇到这问题,现在换了2.0开始学着使用母版,结果就遇到了这个问题,在百度上一搜索才发现有不少人提出这个问题,但没找到好的解 ...