内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

怎么用shell腳本實(shí)現(xiàn)自動(dòng)切換內(nèi)網(wǎng)和外網(wǎng)-創(chuàng)新互聯(lián)

小編給大家分享一下怎么用shell腳本實(shí)現(xiàn)自動(dòng)切換內(nèi)網(wǎng)和外網(wǎng),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

為競(jìng)秀等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及競(jìng)秀網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站建設(shè)、做網(wǎng)站、競(jìng)秀網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!

首先說明下我們的配置文件,都是類似格式的,假如內(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';

這個(gè)時(shí)候就是外網(wǎng)是注釋的狀態(tài)。走的是內(nèi)網(wǎng)。
說下思路,就是一個(gè)配置文件,復(fù)制出來2分放到別的地方,這兩份一個(gè)里面設(shè)置的是內(nèi)網(wǎng),一個(gè)里面設(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)的配置文件再?gòu)?fù)制到網(wǎng)站文件里。就相當(dāng)于是內(nèi)網(wǎng)IP是主,外網(wǎng)IP是備一樣。把這個(gè)腳本放在計(jì)劃任務(wù)里,1分鐘執(zhí)行一次。

代碼如下:


#!/bin/bash
#主從數(shù)據(jù)庫(kù)的內(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/
#檢測(cè)當(dāng)前使用的網(wǎng)卡
function check_ip(){
IP_config=`cat $1  |grep $2 | cut -c1-2`
if [ "$IP_config" == "//" ];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
}
#檢測(cè)各個(gè)網(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


以上是“怎么用shell腳本實(shí)現(xiàn)自動(dòng)切換內(nèi)網(wǎng)和外網(wǎng)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

文章標(biāo)題:怎么用shell腳本實(shí)現(xiàn)自動(dòng)切換內(nèi)網(wǎng)和外網(wǎng)-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://www.rwnh.cn/article22/ppocc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、響應(yīng)式網(wǎng)站、定制開發(fā)、手機(jī)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司
内黄县| 睢宁县| 嘉善县| 旬阳县| 潮安县| 河东区| 冕宁县| 绿春县| 静安区| 翁源县| 阿拉善右旗| 原阳县| 韶山市| 东乌珠穆沁旗| 民和| 日喀则市| 阜城县| 宁明县| 巴马| 临潭县| 金川县| 疏附县| 同江市| 尚志市| 鲁甸县| 雷波县| 新沂市| 九龙坡区| 景泰县| 滦平县| 伊宁县| 客服| 来安县| 樟树市| 宁国市| 曲周县| 平远县| 淅川县| 繁峙县| 天镇县| 蓬安县|