注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Oracle、MySQL资料及经验

.

 
 
 

日志

 
 

利用Keepalived配置VIP  

2015-12-18 09:43:38|  分类: 操作系统 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
本例中keepalived的master端和backup端ip:
master:10.1.5.112
backup: 10.1.5.117

安装keepalived 
linux6自带keepalived,yum install keepalived 配置样本是vi /etc/keepalived/keepalived.conf 
linux5需下载安装,如下:
下载:http://www.keepalived.org/download.html
# tar zxvf keepalived-1.2.19.tar.gz
# cd keepalived-1.2.19 
# ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.39-300.26.1.el5uek
如遇到configure: error: No SO_MARK declaration in headers,则用./configure --prefix=/usr/local/keepalived --disable-fwmark
# make
# make install
# cp /usr/local/keepalived/sbin/keepalived  /usr/sbin/
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived  /etc/init.d/
# cp /usr/local/keepalived/etc/sysconfig/keepalived  /etc/sysconfig/

配置keepalived,创建虚拟服务器和realserver节点:
# mkdir /etc/keepalived

master配置:
# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     zhangwz@umessage.com.cn
     393741056@qq.com
     13520660360@139.com
   }
   notification_email_from root@localhost.localdomain
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    virtual_ipaddress {
        10.1.5.244/24
    }
}


backup配置:
# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     zhangwz@umessage.com.cn
     393741056@qq.com
     13520660360@139.com
   }
   notification_email_from root@localhost.localdomain
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    virtual_ipaddress {
        10.1.5.244/24
    }
}
 
 

安装keepalieved的节点定时任务每分钟运行一次以下脚本
# crontab -l
* * * * * /data/mysqldata/scripts/kill_keepalived.sh > /dev/null  2>&1 &

# cat /data/mysqldata/scripts/kill_keepalived.sh
#/bin/bash
source /root/.bash_profile
source /data/mysqldata/scripts/mysql_env.ini
MYSQL_CMD=/usr/local/mysql/bin/mysql
CHECK_TIME=3  #check 3 times
MYSQL_OK=1    #MYSQL_OK values to 1 when mysql service work,else values to 0

function check_mysql_health () {
   $MYSQL_CMD -usystem -p123456 -S /data/mysqldata/3307/mysql.sock -e "show status;" > /dev/null 2>&1
   if [ $? = 0 ] 
   then
      MYSQL_OK=1
      /etc/init.d/keepalived start
   else
      MYSQL_OK=0
   fi
   return $MYSQL_OK
}

while [ $CHECK_TIME -ne 0 ]
do
   let "CHECK_TIME -=1"
   check_mysql_health
   if [ $MYSQL_OK = 1 ] 
   then
      CHECK_TIME=0
      exit 0
   fi
   if [ $MYSQL_OK -eq 0 ] && [ $CHECK_TIME -eq 0 ]  
   then
      /etc/init.d/keepalived stop
      echo "mysql 3307实例宕掉,keepalived已关闭" | mutt  -s "112 keepalived已关闭" 393741056@qq.com
      exit 1
   fi
   sleep 1
done
  评论这张
 
阅读(179)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017