keepalived主备切换MSN警告

主备切换MSN警告

   当主备机发生故障切换时,会发MSN消息给警报给管理员,此警报消息是由keepalived上的bash脚本将参数通过crul命令传给PHP接口程序(也就是拓扑中的WEB),由PHP接口程序来完成发送MSN消息。

   在WEB主机上安装php-mcrypt和php-bcmath
下载php发MSN消息类项目
http://code.google.com/p/phpmsmclass/downloads/list
下载完成后把msn.class.php放到/var/www/html目录下面


test1的keepalived的配置

[root@test1 ~]# vim  /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
  router_id  HAWEB
 }
vrrp_sync_group VGM {
      group {
         VI_HA
            }
}

vrrp_instance VI_HA {

   state MASTER
   interface eth0
   virtual_router_id 51
   priority 100
   advert_int 5
   authentication {
       auth_type PASS
       auth_pass 1111
   }
   virtual_ipaddress {
       18.1.30.30/24 dev eth0

   }

 notify_master  "/etc/keepalived/sendmsn.sh   master"

 notify_backup  "/etc/keepalived/sendmsn.sh   backup"

 notify_fault   "/etc/keepalived/sendmsn.sh   fault"

}

[root@test1 ~]# vim  /etc/keepalived/sendmsn.sh

#!/bin/bash
url="http://18.1.30.30/interface.php"
today=$(date -d "today" +"%Y-%m-%d _%H:%M:%S")
ip=$(/sbin/ifconfig  |grep " inet addr"|grep -v "127.0.0.1"|awk '{print $2;}'|awk -F ':' '{print $2;}'|tr -s ';' '\n'|awk "NR==2")
/usr/bin/curl  -d  date=$today -d  ip=$ip -d state=$1  $url

[root@test1 ~]# chmod a+x /etc/keepalived/sendmsn.sh


test2的keepalived的配置

[root@test2 ~]# vim  /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
  router_id  HAWEB
 }
vrrp_sync_group VGM {
      group {
         VI_HA
            }
}

vrrp_instance VI_HA {

   state MASTER
   interface eth0
   virtual_router_id 51
  priority 99
   advert_int 5
   authentication {
       auth_type PASS
       auth_pass 1111
   }
   virtual_ipaddress {
       18.1.30.30/24 dev eth0

   }

 notify_master  "/etc/keepalived/sendmsn.sh   master"

 notify_backup  "/etc/keepalived/sendmsn.sh   backup"

 notify_fault   "/etc/keepalived/sendmsn.sh   fault"

}

[root@test1 ~]# vim  /etc/keepalived/sendmsn.sh

#!/bin/bash
url="http://18.1.30.30/interface.php"
today=$(date -d "today" +"%Y-%m-%d _%H:%M:%S")
ip=$(/sbin/ifconfig  |grep " inet addr"|grep -v "127.0.0.1"|awk '{print $2;}'|awk -F ':' '{print $2;}'|tr -s ';' '\n'|awk "NR==2")
/usr/bin/curl  -d  date=$today -d  ip=$ip -d state=$1  $url

[root@test2 ~]# chmod a+x /etc/keepalived/sendmsn.sh





你可能感兴趣的:(keepalived)