容災半自動化的實現思路(二)
容災的半自動化的部分,自己寫了下面的指令碼,也算是一個基本實現,因為時間倉促,還是存在一些不足,稍後完善
整個切換的步驟分為三部分,第一部分是備份當前備庫的配置檔案,第二部分是使用dg broker決定是failover還是switchover 第三部分是切換之後開始替換引數檔案。
所以需要的指令碼為dg_pre.sh dg_post.sh
dg_pre.sh是作為基本的備份,內容如下:
#### validate input parameters
#### validate if ip address is available
#### validate if ip address is the same as standby
#### get current ip address
curr_ipadd=`cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
echo '###### INFO Current IP ADDRESS IS : '$curr_ipadd
echo .
ip_std_bak=${curr_ipadd}_std_bak
##get network card name
eth_code=`/sbin/ifconfig |grep -B1 ${curr_ipadd}|head -1|awk '{print $1}'`
echo '###### INFO Current NETWORK CARD NAME IS : '$eth_code
/sbin/ifconfig|grep -B1 `cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
echo .
sleep 2
#### backup all conf files
mkdir -p /home/conf/${ip_std_bak};
ORACLE_HOME=`cat /etc/oratab | tail -1 | awk -F: '{print \$2}' `
echo '###### INFO Current ORACLE_HOME is : '$ORACLE_HOME
echo .
sleep 1
if [ -n "$ORACLE_HOME" ]; then
cp $ORACLE_HOME/network/admin/tnsnames.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/network/admin/listener.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/network/admin/sqlnet.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/dbs/init*.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/dbs/spfile*.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/dbs/orapw* /home/conf/${ip_std_bak}
echo '###### INFO BACKUP DB LEVEL CONF FILES ... DONE'
fi
sleep 1
echo .
cp /etc/hosts /home/conf/${ip_std_bak}
cp /etc/sysconfig/iptables /home/conf/${ip_std_bak}
cp /etc/sysconfig/network /home/conf/${ip_std_bak}
cp /etc/sysconfig/network-scripts/ifcfg-${eth_code} /home/conf/${ip_std_bak}
cp /etc/sysctl.conf /home/conf/${ip_std_bak}
cp /etc/security/limits.conf /home/conf/${ip_std_bak}
echo '###### INFO BACKUP OS LEVEL CONF FILES ... DONE'
sleep 1
####
dg_post是作為切換之後的補充,指令碼如下:
#### validate input parameters
new_ip=$1
if [ ! $new_ip ];then
echo 'Target IP ADDRESS is needed ... '
exit;
fi
if [ ! -d /home/conf/$new_ip ];then
echo 'TARGET IP CONF FILES NOT FOUND,SHOULD BE /home/conf/'$new_ip
exit;
fi
#### validate if ip address is available
#### get current ip address
curr_ipadd=`cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
echo '###### INFO Current IP ADDRESS IS : '$curr_ipadd
sleep 1 ;
if [ ! -d /home/conf/$curr_ipadd ];then
echo 'SOURCE IP CONF FILES NOT FOUND,SHOULD BE /home/conf/'${curr_ipadd}_std_bak
exit;
fi
#### validate if ip address is the same as standby
#if [[ ${new_ip} -eq ${curr_ipadd} ]];then
#echo 'SOURCE AND TARGET IP ADDRESS SHOULD NOT BE THE SAME ...'
#fi
echo .
ip_std_bak=${curr_ipadd}_std_bak
##get network card name
eth_code=`/sbin/ifconfig |grep -B1 ${curr_ipadd}|head -1|awk '{print $1}'`
echo '###### INFO Current NETWORK CARD NAME IS : '$eth_code
/sbin/ifconfig|grep -B1 `cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
if [ ! $eth_code ];then
echo 'WARNING... NETWORK CARD CODE IS EMPTY ...'
exit
fi
sleep 1 ;
echo .
#### backup all conf files
mkdir -p /home/conf/${ip_std_bak};
ORACLE_HOME=`cat /etc/oratab | tail -1 | awk -F: '{print \$2}' `
echo '###### INFO Current ORACLE_HOME is : '$ORACLE_HOME
echo .
if [ -n "$ORACLE_HOME" ]; then
echo '###### INFO RESTORE DB LEVEL CONF FILES'
echo .
cp /home/conf/${new_ip}/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora
cp /home/conf/${new_ip}/listener.ora $ORACLE_HOME/network/admin/listener.ora
cp /home/conf/${new_ip}/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora > /dev/null 2>&1
fi
sleep 1 ;
echo '###### INFO RESTORE OS LEVEL CONF FILES'
echo .
cp /home/conf/${new_ip}/hosts /etc/hosts
cp /home/conf/${new_ip}/iptables /etc/sysconfig/iptables
cp /home/conf/${new_ip}/network /etc/sysconfig/network
sleep 1 ;
####change IP address
echo '###### INFO IP ADDRESS BEFORE CHANGE AS BELOW'
cat /home/conf/${ip_std_bak}/ifcfg-${eth_code} |tee /home/conf/tmp_eth.lst
sed -i "s/${curr_ipadd}/${new_ip}/g" /home/conf/tmp_eth.lst
sleep 1;
echo .
echo '###### INFO IP ADDRESS CHANGED AS BELOW'
cat /home/conf/tmp_eth.lst
cp /home/conf/tmp_eth.lst /etc/sysconfig/network-scripts/ifcfg-${eth_code}
cp /home/conf/$new_ip/network /etc/sysconfig/network
sleep 1;
echo .
new_hostname=`cat /etc/hosts|grep $new_ip|awk '{print $2}'`
echo $new_hostname
sleep 1;
hostname $new_hostname
ifdown ${eth_code}
sleep 1;
ifup ${eth_code}
sleep 1;
service network restart
dg_pre.sh執行的基本日誌如下:
###### INFO Current IP ADDRESS IS : 10.127.133.46
.
###### INFO Current NETWORK CARD NAME IS : eth0
eth0 Link encap:Ethernet HWaddr 84:2B:2B:69:EF:F8
inet addr:10.127.133.46 Bcast:10.127.133.255 Mask:255.255.255.0
.
###### INFO Current ORACLE_HOME is : /U01/app/oracle/product/11.2.0.2/db_1
.
###### INFO BACKUP DB LEVEL CONF FILES ... DONE
.
###### INFO BACKUP OS LEVEL CONF FILES ... DONE
dg_post.sh的日誌如下:
# cat dg_post.log
###### INFO Current IP ADDRESS IS : 10.127.133.46
.
###### INFO Current NETWORK CARD NAME IS : eth0
eth0 Link encap:Ethernet HWaddr 84:2B:2B:69:EF:F8
inet addr:10.127.133.46 Bcast:10.127.133.255 Mask:255.255.255.0
.
###### INFO Current ORACLE_HOME is : /U01/app/oracle/product/11.2.0.2/db_1
.
###### INFO RESTORE DB LEVEL CONF FILES
.
###### INFO RESTORE OS LEVEL CONF FILES
.
###### INFO IP ADDRESS BEFORE CHANGE AS BELOW
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.127.133.46
NETMASK=255.255.255.0
#GATEWAY=10.127.133.254
ONBOOT=yes
TYPE=Ethernet
.
###### INFO IP ADDRESS CHANGED AS BELOW
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.127.133.45
NETMASK=255.255.255.0
#GATEWAY=10.127.133.254
ONBOOT=yes
TYPE=Ethernet
.
BX_133_45
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth1: [ OK ]
後續繼續完善。
整個切換的步驟分為三部分,第一部分是備份當前備庫的配置檔案,第二部分是使用dg broker決定是failover還是switchover 第三部分是切換之後開始替換引數檔案。
所以需要的指令碼為dg_pre.sh dg_post.sh
dg_pre.sh是作為基本的備份,內容如下:
#### validate input parameters
#### validate if ip address is available
#### validate if ip address is the same as standby
#### get current ip address
curr_ipadd=`cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
echo '###### INFO Current IP ADDRESS IS : '$curr_ipadd
echo .
ip_std_bak=${curr_ipadd}_std_bak
##get network card name
eth_code=`/sbin/ifconfig |grep -B1 ${curr_ipadd}|head -1|awk '{print $1}'`
echo '###### INFO Current NETWORK CARD NAME IS : '$eth_code
/sbin/ifconfig|grep -B1 `cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
echo .
sleep 2
#### backup all conf files
mkdir -p /home/conf/${ip_std_bak};
ORACLE_HOME=`cat /etc/oratab | tail -1 | awk -F: '{print \$2}' `
echo '###### INFO Current ORACLE_HOME is : '$ORACLE_HOME
echo .
sleep 1
if [ -n "$ORACLE_HOME" ]; then
cp $ORACLE_HOME/network/admin/tnsnames.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/network/admin/listener.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/network/admin/sqlnet.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/dbs/init*.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/dbs/spfile*.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/dbs/orapw* /home/conf/${ip_std_bak}
echo '###### INFO BACKUP DB LEVEL CONF FILES ... DONE'
fi
sleep 1
echo .
cp /etc/hosts /home/conf/${ip_std_bak}
cp /etc/sysconfig/iptables /home/conf/${ip_std_bak}
cp /etc/sysconfig/network /home/conf/${ip_std_bak}
cp /etc/sysconfig/network-scripts/ifcfg-${eth_code} /home/conf/${ip_std_bak}
cp /etc/sysctl.conf /home/conf/${ip_std_bak}
cp /etc/security/limits.conf /home/conf/${ip_std_bak}
echo '###### INFO BACKUP OS LEVEL CONF FILES ... DONE'
sleep 1
####
dg_post是作為切換之後的補充,指令碼如下:
#### validate input parameters
new_ip=$1
if [ ! $new_ip ];then
echo 'Target IP ADDRESS is needed ... '
exit;
fi
if [ ! -d /home/conf/$new_ip ];then
echo 'TARGET IP CONF FILES NOT FOUND,SHOULD BE /home/conf/'$new_ip
exit;
fi
#### validate if ip address is available
#### get current ip address
curr_ipadd=`cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
echo '###### INFO Current IP ADDRESS IS : '$curr_ipadd
sleep 1 ;
if [ ! -d /home/conf/$curr_ipadd ];then
echo 'SOURCE IP CONF FILES NOT FOUND,SHOULD BE /home/conf/'${curr_ipadd}_std_bak
exit;
fi
#### validate if ip address is the same as standby
#if [[ ${new_ip} -eq ${curr_ipadd} ]];then
#echo 'SOURCE AND TARGET IP ADDRESS SHOULD NOT BE THE SAME ...'
#fi
echo .
ip_std_bak=${curr_ipadd}_std_bak
##get network card name
eth_code=`/sbin/ifconfig |grep -B1 ${curr_ipadd}|head -1|awk '{print $1}'`
echo '###### INFO Current NETWORK CARD NAME IS : '$eth_code
/sbin/ifconfig|grep -B1 `cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
if [ ! $eth_code ];then
echo 'WARNING... NETWORK CARD CODE IS EMPTY ...'
exit
fi
sleep 1 ;
echo .
#### backup all conf files
mkdir -p /home/conf/${ip_std_bak};
ORACLE_HOME=`cat /etc/oratab | tail -1 | awk -F: '{print \$2}' `
echo '###### INFO Current ORACLE_HOME is : '$ORACLE_HOME
echo .
if [ -n "$ORACLE_HOME" ]; then
echo '###### INFO RESTORE DB LEVEL CONF FILES'
echo .
cp /home/conf/${new_ip}/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora
cp /home/conf/${new_ip}/listener.ora $ORACLE_HOME/network/admin/listener.ora
cp /home/conf/${new_ip}/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora > /dev/null 2>&1
fi
sleep 1 ;
echo '###### INFO RESTORE OS LEVEL CONF FILES'
echo .
cp /home/conf/${new_ip}/hosts /etc/hosts
cp /home/conf/${new_ip}/iptables /etc/sysconfig/iptables
cp /home/conf/${new_ip}/network /etc/sysconfig/network
sleep 1 ;
####change IP address
echo '###### INFO IP ADDRESS BEFORE CHANGE AS BELOW'
cat /home/conf/${ip_std_bak}/ifcfg-${eth_code} |tee /home/conf/tmp_eth.lst
sed -i "s/${curr_ipadd}/${new_ip}/g" /home/conf/tmp_eth.lst
sleep 1;
echo .
echo '###### INFO IP ADDRESS CHANGED AS BELOW'
cat /home/conf/tmp_eth.lst
cp /home/conf/tmp_eth.lst /etc/sysconfig/network-scripts/ifcfg-${eth_code}
cp /home/conf/$new_ip/network /etc/sysconfig/network
sleep 1;
echo .
new_hostname=`cat /etc/hosts|grep $new_ip|awk '{print $2}'`
echo $new_hostname
sleep 1;
hostname $new_hostname
ifdown ${eth_code}
sleep 1;
ifup ${eth_code}
sleep 1;
service network restart
dg_pre.sh執行的基本日誌如下:
###### INFO Current IP ADDRESS IS : 10.127.133.46
.
###### INFO Current NETWORK CARD NAME IS : eth0
eth0 Link encap:Ethernet HWaddr 84:2B:2B:69:EF:F8
inet addr:10.127.133.46 Bcast:10.127.133.255 Mask:255.255.255.0
.
###### INFO Current ORACLE_HOME is : /U01/app/oracle/product/11.2.0.2/db_1
.
###### INFO BACKUP DB LEVEL CONF FILES ... DONE
.
###### INFO BACKUP OS LEVEL CONF FILES ... DONE
dg_post.sh的日誌如下:
# cat dg_post.log
###### INFO Current IP ADDRESS IS : 10.127.133.46
.
###### INFO Current NETWORK CARD NAME IS : eth0
eth0 Link encap:Ethernet HWaddr 84:2B:2B:69:EF:F8
inet addr:10.127.133.46 Bcast:10.127.133.255 Mask:255.255.255.0
.
###### INFO Current ORACLE_HOME is : /U01/app/oracle/product/11.2.0.2/db_1
.
###### INFO RESTORE DB LEVEL CONF FILES
.
###### INFO RESTORE OS LEVEL CONF FILES
.
###### INFO IP ADDRESS BEFORE CHANGE AS BELOW
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.127.133.46
NETMASK=255.255.255.0
#GATEWAY=10.127.133.254
ONBOOT=yes
TYPE=Ethernet
.
###### INFO IP ADDRESS CHANGED AS BELOW
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.127.133.45
NETMASK=255.255.255.0
#GATEWAY=10.127.133.254
ONBOOT=yes
TYPE=Ethernet
.
BX_133_45
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth1: [ OK ]
後續繼續完善。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23718752/viewspace-1984190/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 利用Python實現微信半自動化操作!Python
- 自動化測試思路
- 實現動態自動匹配輸入的內容
- Selenium自動化實現web自動化-1Web
- dom xss->半自動化
- 介面自動化測試框架搭建的思路框架
- IT 自動化:如何去實現
- pyest+appium實現APP自動化測試,思路全總結在這裡APP
- 資料價值凸顯容災備份的重要性,摩杜雲主機實現多雲容災
- Docker容器的自動化監控實現Docker
- 如何實現辦公自動化?
- 使用gulp實現前端自動化前端
- iOS如何實現自動化打包iOS
- 使用 fastlane 實現自動化打包AST
- 自動化測試平臺設計與實現(二、自動化測試用例物件設計實現、關鍵字物件設計與實現)物件
- 利用 ChangeStream 實現 Amazon DocumentDB 表級別容災複製
- 容災方案
- 前端容災前端
- 使用 Git 實現 專案的自動化部署Git
- 利用github提供的Webhooks實現自動化部署GithubWebHook
- 是否只有實現了容器化、自動編排等等才算是實現了運維自動化?運維
- API自動化測試平臺,高效實現對API的自動化測試API
- 鴻蒙 next 原生系統自動化框架要怎麼實現?有啥思路提供不?鴻蒙框架
- APP UI自動化測試思路總結APPUI
- 分析阿里前端-自動化架構思路-react阿里前端架構React
- Postman實現UI自動化測試PostmanUI
- 基於RestAssured實現介面自動化REST
- CRD實現自動化容器安全方法
- python自動化審計及實現Python
- python實現自動化辦公01Python
- Python 實現自動化 Excel 報表PythonExcel
- 利用Github Actions實現自動化部署Github
- [原] php + Laravel 實現部署自動化PHPLaravel
- 如何實現高度自動化測試?
- GaussDB跨雲容災:實現跨地域的資料庫高可用能力資料庫
- 通過自動化和現代化實現網路優化優化
- 實現動態表單的一種思路
- 雲容災最佳實踐!美創DBRA助力包頭醫學院第二附屬醫院核心系統容災建設
- UI自動化關鍵字驅動的簡單設計思路UI