最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

用shell腳本實(shí)現(xiàn)自動切換內(nèi)網(wǎng)和外網(wǎng)實(shí)現(xiàn)高可用

 更新時間:2013年06月10日 14:11:08   作者:  
因?yàn)楣镜姆?wù)器這段時間內(nèi)網(wǎng)網(wǎng)卡老是出現(xiàn)問題,然后就導(dǎo)致了網(wǎng)站的各種問題,因?yàn)槲覀兊臄?shù)據(jù)庫鏈接,redis還有sphinx鏈接都是走的內(nèi)網(wǎng),,所以就寫了這個腳本,在線上也跑了一段時間了,,也沒出過什么問題

首先說明下我們的配置文件,都是類似格式的,假如內(nèi)網(wǎng)是192.168.0.3,外網(wǎng)是123.123.123.123,配置文件如下:

$db['salver']['hostname'] = '192.168.0.3:3306';
//$db['salver']['hostname'] = '123.123.123.123:3306';

這個時候就是外網(wǎng)是注釋的狀態(tài)。走的是內(nèi)網(wǎng)。
說下思路,就是一個配置文件,復(fù)制出來2分放到別的地方,這兩份一個里面設(shè)置的是內(nèi)網(wǎng),一個里面設(shè)置的是外網(wǎng),如果內(nèi)網(wǎng)不通的情況下,判斷當(dāng)前用的是內(nèi)網(wǎng)還是外網(wǎng),如果是內(nèi)網(wǎng)的情況下,就把外網(wǎng)的配置文件復(fù)制到網(wǎng)站文件里,如果內(nèi)網(wǎng)通了,就把內(nèi)網(wǎng)的配置文件再復(fù)制到網(wǎng)站文件里。就相當(dāng)于是內(nèi)網(wǎng)IP是主,外網(wǎng)IP是備一樣。把這個腳本放在計劃任務(wù)里,1分鐘執(zhí)行一次。

復(fù)制代碼 代碼如下:

#!/bin/bash
#主從數(shù)據(jù)庫的內(nèi)外網(wǎng)IP
master_IP_N=
master_IP_W=
salver_IP_N=
salver_IP_W=
#mongo的內(nèi)外網(wǎng)IP
mongo_IP_W=
mongo_IP_N=
#redis的主從內(nèi)外網(wǎng)IP
redis_master_IP_W=
redis_master_IP_N=
redis_slave_IP_W=
redis_slave_IP_N=
#sphinx的內(nèi)外網(wǎng)IP
sphinx_IP_W=
sphinx_IP_N=
#網(wǎng)站配置文件的位置
database_path=/home/caoy/database.php
mongo_path=/home/caoy/over_sea_stock.php
redis_path=/home/caoy/Rediska_connector.php
sphinx_path=/home/caoy/SphinxConnector.php
config_path=/data/check_ip_config/
#檢測當(dāng)前使用的網(wǎng)卡
function check_ip(){
IP_config=`cat $1  |grep $2 | cut -c1-2`
if [ "$IP_config" == "http://" ];then
        ip_status=1
else
        ip_status=0
fi
}
#判斷內(nèi)網(wǎng)網(wǎng)卡是否故障
function check_network(){
nmap -sP $1 | grep "1 host up" >/dev/null || (sleep 5 ; nmap -sP $1) | grep "1 host up" >/dev/null
#ping $1 -c 5 > /dev/null
if [[ "$?" == "1" ]]; then
        check_ip $database_path $1
        if [[ "$ip_status" == "0" ]];then
                cp -r $config_path/database_w.php $database_path
                echo "cp database_w.php is ok!"
        fi
        check_ip $mongo_path $1
        if [[ "$ip_status" == "0" ]];then
                cp -r $config_path/over_sea_stock_w.php $mongo_path
                echo "cp over_sea_stock_w.php is ok!"
        fi
        check_ip $redis_path $1
        if [[ "$ip_status" == "0" ]];then
                cp -r $config_path/Rediska_connector_w.php $redis_path
                echo "cp Rediska_connector_w.php is ok!"
        fi
        check_ip $sphinx_path $1
        if [[ "$ip_status" == "0" ]];then
                cp -r $config_path/SphinxConnector_w.php $sphinx_path
                echo "cp SphinxConnector_w.php is ok!"
        fi
else
        check_ip $database_path $1
        if [[ "$ip_status" == "1" ]];then
                cp -r $config_path/database_n.php $database_path
                echo "cp database_n.php is ok!"
        fi
        check_ip $mongo_path $1
        if [[ "$ip_status" == "1" ]];then
                cp -r $config_path/over_sea_stock_n.php $mongo_path
                echo "cp over_sea_stock_n.php is ok!"
        fi
        check_ip $redis_path $1
        if [[ "$ip_status" == "1" ]];then
                cp -r $config_path/Rediska_connector_n.php $redis_path
                echo "cp Rediska_connector_n.php is ok!"
        fi
        check_ip $sphinx_path $1
        if [[ "$ip_status" == "1" ]];then
                cp -r $config_path/SphinxConnector_n.php $sphinx_path
                echo "cp SphinxConnector_n.php is ok!"
        fi
fi
}
#檢測各個網(wǎng)卡是否通暢
check_network $master_IP_N
check_network $salver_IP_N
check_network $mongo_IP_N
check_network $redis_master_IP_N
check_network $redis_slave_IP_N
check_network $sphinx_IP_N

相關(guān)文章

最新評論

井陉县| 西丰县| 泾阳县| 永德县| 化州市| 同仁县| 休宁县| 安阳县| 奉节县| 盘山县| 泸溪县| 屯昌县| 金沙县| 永寿县| 金川县| 西宁市| 库车县| 察隅县| 沈阳市| 专栏| 申扎县| 合作市| 措美县| 长顺县| 新干县| 连城县| 句容市| 扶风县| 驻马店市| 来凤县| 包头市| 高要市| 松桃| 山丹县| 肥城市| 永昌县| 铁岭县| 巴青县| 喀喇沁旗| 易门县| 灯塔市|