Chinaunix首页 | 论坛 | 博客
  • 博客访问: 43691343
  • 博文数量: 384
  • 博客积分: 9990
  • 博客等级: 中将
  • 技术积分: 5644
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-05 17:44
文章分类

全部博文(384)

文章存档

2011年(1)

2008年(383)

分类: 服务器与存储

2008-06-07 18:00:12

公司要求 随便写了个
因为heartbeat自带的那个PING侦测实在几乎不能用。。。太简单了 几乎不能控制侦测服务
上MON又太麻烦 一堆PERL 看着头疼 自己写个SHELL来针对端口侦测
脚本如下
[root@node1 ~]# cat monitor.sh
#Monitor.sh
#!/bin/bash
email=xxxx@xxxx.com
ip=$1
port=$2

if [ "$#" != 2 ]
then
echo "USEAGE:./`basename $0` "
exit 0
fi

telnet $ip $port > /tmp/monitor.tmp << pass

quit
pass

cat /tmp/monitor.tmp |grep 'Escape character' > /dev/null

if [ "$?" = 0 ]
then
        echo "`date |awk '{print $6"."$2"."$3"."$4}'`:port is listening" >> /var/log/ha_log/monitor.log
        /etc/init.d/heartbeat status|grep "heartbeat OK" >> /dev/null
        if [ "$?" = 1 ]
        then
                /etc/init.d/heartbeat start
        fi
else
        echo "`hostname`:$port is not listening.And now forward to another active node"|mail -s "Warning:Cannot reach $ip:$port" $email
        /etc/init.d/heartbeat stop
#       echo "`date |awk '{print $6"."$2"."$3"."$4}'`:port is not listening" >> /var/log/ha_log/monitor.log
fi

自动执行侦测多端口 请写个FOR循环到CRONTAB里面
为什么是执行STOP HEARTBEAT 请参考HEARTBEAT特性 希望对各位有用

阅读(817) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~