前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nagios监控Heartbeat

Nagios监控Heartbeat

作者头像
星哥玩云
发布2022-07-04 10:28:53
7690
发布2022-07-04 10:28:53
举报
文章被收录于专栏:开源部署

Heartbeat架好后,我们就需要监控起来喽,下面我们就来了解下怎么监控。

首先来了解下几个命令,这几个命令在heartbeat安装后会自动加上,我们的监控脚本就用到这几个命令。

[root@usvr-210 libexec]# which cl_status /usr/bin/cl_status [root@usvr-210 libexec]# cl_status listnodes  #列出当前heartbeat集群中的节点 192.168.3.1 usvr-211 usvr-210 [root@usvr-210 libexec]# cl_status nodestatus usvr-211  #列出节点的状态 active [root@usvr-210 libexec]# cl_status nodestatus 192.168.3.1  #列出节点的状态 ping

我们的check_heartbeat.sh原理就是列出集群中所有节点,并监测所有节点的状态是否正常,我们实验的节点状态为ping和active。 

当active+ping的个数为0时critical

当active+ping的个数小于节点总个数时为warn

当active+ping的个数等于节点总个数时为ok

[root@usvr-210 libexec]# cat check_heartbeat.sh #!/bin/bash # Author: Emmanuel Bretelle # Date: 12/03/2010 # Description: Retrieve Linux HA cluster status using cl_status # Based on http://www.randombugs.com/linux/howto-monitor-linux-heartbeat-snmp.html # # Autor: Stanila Constantin Adrian # Date: 20/03/2009 # Description: Check the number of active heartbeats # http://www.randombugs.com

# Get program path REVISION=1.3 PROGNAME=`/bin/basename $0` PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`

NODE_NAME=`uname -n` CL_ST='/usr/bin/cl_status'

#nagios error codes #. $PROGPATH/utils.sh OK=0 WARNING=1 CRITICAL=2 UNKNOWN=3

usage () {     echo "\ Nagios plugin to heartbeat.

Usage:   $PROGNAME   $PROGNAME [--help | -h]   $PROGNAME [--version | -v]

Options:   --help -l Print this help information   --version -v  Print version of plugin " }

help () {     print_revision $PROGNAME $REVISION     echo; usage; echo; support }

while test -n "$1" do   case "$1" in     --help | -h)       help       exit $STATE_OK;;     --version | -v)       print_revision $PROGNAME $REVISION       exit $STATE_OK;; #    -H) #      shift #      HOST=$1;; #    -C) #      shift #      COMMUNITY=$1;;     *)       echo "Heartbeat UNKNOWN: Wrong command usage"; exit $UNKNOWN;;   esac   shift done

$CL_ST hbstatus > /dev/null res=$? if [ $res -ne 0 ] then   echo "Heartbeat CRITICAL: Heartbeat is not running on this node"   exit $CRITICAL fi

declare -i I=0 declare -i A=0 NODES=`$CL_ST listnodes`

for node in $NODES do   status=`$CL_ST nodestatus $node`   let I=$I+1 #  if [ $status == "active" ] 默认情况下检测active状态的个数,但是ping状态也为正常状态,因此改成如下条件。   if [ $status == "active" -o $status == "ping" ]   then     let A=$A+1   fi done

if [ $A -eq 0 ] then   echo "Heartbeat CRITICAL: $A/$I"   exit $CRITICAL elif [ $A -ne $I ] then   echo "Heartbeat WARNING: $A/$I"   exit $WARNING else   echo "Heartbeat OK: $A/$I"   exit $OK fi

我们在nagios客户端,也就是我们的lvs集群usvr-210,usvr-211,我们通过nagios服务器端的check_nrpe来获取监控信息。

naigos客户端

1.先将脚本复制到nagios命令目录下并修改相应权限

cp check_heartbeat.sh /usr/local/nagios/libexec/

chmod a+x check_heartbeat.sh

chown nagios.nagios check_heartbeat.sh

2.在naigos客户端的配置文件中加入监控命令。

vim /usr/local/nagios/etc/nrpe.cfg

command[check_heartbeat]=/usr/local/nagios/libexec/check_heartbeat.sh

3.重新载入配置文件。

service xinetd reload

nagios服务端

1.加入相关监控服务

define service {     use                    local-service     service_description    heartbeat-lvs-master     check_command          check_nrpe!check_heartbeat     service_groups          heartbeat_services     host_name              usvr-210     check_interval          5      notifications_enabled  1      notification_interval  30      contact_groups          admins } define service {     use                    local-service     service_description    heartbeat-lvs-slave     check_command          check_nrpe!check_heartbeat     service_groups          heartbeat_services     host_name              usvr-211     check_interval          5      notifications_enabled  1      notification_interval  30      contact_groups          admins }

2.检查并载入配置文件

nagioscheck

service nagios reload

监控如下:

ok,我们的heartbeat监控完成了。 

我是参考这个网站http://wiki.debuntu.org/wiki/Linux_HA_Heartbeat/Monitoring_with_Nagios,希望能对大家有所帮助。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档