码迷,mamicode.com
首页 > 其他好文 > 详细

双机热备脚本

时间:2017-04-17 14:58:48      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:双机热备

      这个服务的脚本是在备机上跑的,主机ip是192.168.2.168,在主机上多添加一个ip:192.168.2.169

每隔5秒钟去探测下对端机机器,ping 192.168.2.169,看是否ping的通,如果ping通了,则不管。

#!/bin/bash

masterip_add=192.168.2.169

masterip=192.168.2.168

mfile=/run/nginx.pid

start_nginx(){

if [ ! -f "$mfile" ];then

nginx -s start

fi

}


c1=$(ping $masterip_add -c 1|grep Unreachable|wc -l)

if [ $c1 -gt 0 ] ; then

c2=$(ping $masterip_add -c 10|grep Unreachable|wc -l)

if [ $c2 -gt 9 ] ; then

    c3=$(ping $masterip -c 10|grep Unreachable|wc -l)

      if [ $c3 -gt 9 ] ; then

        /sbin/ifconfig eth0 $masterip netmask 255.255.255.0

start_nginx

echo "float ip to 168"

      fi

fi

echo "can not connect"

else

c4=$(/sbin/ifconfig|grep $masterip|wc -l)

if [ $c4 -gt 0 ] ; then

    /sbin/ifconfig eth0 $masterip netmask 255.255.255.0

    echo "reset ip"

fi 

echo "connection is ok"

fi


双机热备脚本

标签:双机热备

原文地址:http://12725080.blog.51cto.com/12715080/1916563

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!