Shell 指令碼 更換tomcat叢集war包

來源:互聯網
上載者:User

標籤:style   blog   io   color   ar   os   java   for   sp   

運行之前將伺服器弄成免ssh登陸。

設定檔沒有太大的改動 可以覆蓋之前的配置

profile 設定檔

bak=/home/wsm/bak
webapps=/home/wsm/webapps/WSMMeasure
arry=192.168.68.29 192.168.10.147
newwar=1.war
deplypath=/home/wsm/deploy



scp.sh 拷貝相關war和指令碼到遠程服務上

scp.sh

#!/bin/bash#拷貝war|deploy.sh|profile#scp 1.war deploy.sh profile [email protected]:/home/wsm scpdep(){echo 'Start Scp ...'scp $1 deploy.sh backup.sh profile [email protected]$3:$4 echo 'End Scp ...'}#arry ="192.168.68.29 192.168.10.147"host=`awk -F '=' '{if($1=="arry")print $2}' profile`newwar=`awk -F '=' '{if($1=="newwar")print $2}' profile`for i in $hostdo echo 'scp [email protected]'$iscpdep $newwar root $i /home/wsmecho 'scp [email protected]'done


備份指令碼 backup.sh

#!/bin/bash#dire="/home/wsm/bak"#備份webappsfunction backupWeb(){echo 'BackUp Start....'`\cp -R /home/wsm/webapps/WSMMeasure $dire`cd $direrm -rf $dirdatemv $dire/WSMMeasure $dirdateecho 'BackUp End'}dirdate=`date +%Y%m%d`echo '$dirdate'dire=`awk -F '=' '{if($1=="bak")print $2}' profile` if [ -d "$dire" ]; then echo "bak檔案夾存在" else mkdir -p $dire fibackupWeb


安裝指令碼 deploy.sh

#!/bin/bash#dire="/home/wsm/bak"#備份webapps#cp war到/home/wsm/webapps/WSMMeasurefunction cpWarApps(){echo 'cpwarApps Start...'rm -rf /home/wsm/webapps/WSMMeasure/*`\cp /home/wsm/1.war  /home/wsm/webapps/WSMMeasure`cd /home/wsm/webapps/WSMMeasurejar -xvf *.warecho 'cpwarApps End...'}#拷貝設定檔function RepConf(){#/home/wsm/webapps/WSMMeasure/WEB-INF/classes#$dire/$dirdate/WEB-INF/classesdirdate=`date +%Y%m%d` echo 'RepConf Start...'`\cp -R $dire/$dirdate/WEB-INF/classes/spring /home/wsm/webapps/WSMMeasure/WEB-INF/classes``\cp -R $dire/$dirdate/WEB-INF/classes/hbase /home/wsm/webapps/WSMMeasure/WEB-INF/classes``\cp -R $dire/$dirdate/WEB-INF/classes/dubbo /home/wsm/webapps/WSMMeasure/WEB-INF/classes``\cp  $dire/$dirdate/WEB-INF/classes/xmpp.properties /home/wsm/webapps/WSMMeasure/WEB-INF/classes``\cp  $dire/$dirdate/WEB-INF/classes/quertz.properties /home/wsm/webapps/WSMMeasure/WEB-INF/classes``\cp  $dire/$dirdate/WEB-INF/classes/file.properties /home/wsm/webapps/WSMMeasure/WEB-INF/classes``\cp  $dire/$dirdate/WEB-INF/classes/const.properties /home/wsm/webapps/WSMMeasure/WEB-INF/classes``\cp  $dire/$dirdate/WEB-INF/classes/jdbc.properties /home/wsm/webapps/WSMMeasure/WEB-INF/classes`  echo 'RepConf End...'}#停止tomcatfunction killTomcat(){ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}' | xargs kill -9echo "killd tomcat "}function startTomcat(){ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}' | xargs kill -9cd /home/wsm/bin ./startup.sh echo "start tomcat end"}dire=`awk -F '=' '{if($1=="bak")print $2}' profile`backupWebcpWarAppsRepConfkillTomcatstartTomcat

遠程執行 rangerun.sh

將指令碼scp到目標伺服器通過ssh去執行指令碼

#!/bin/bash

#ssh登陸遠程執行指令碼#ssh [email protected] cd /home/wsm ./deploy.sh#ssh  [email protected] "cd /home/wsm && ls"rangback(){ssh [email protected]$1 "cd /home/wsm && ./backup.sh"}rangdeploy(){ssh [email protected]$1 "cd /home/wsm && ./deploy.sh"}#arry ="192.168.68.29 192.168.10.147"host=`awk -F '=' '{if($1=="arry")print $2}' profile`for i in $hostdo echo 'ssh [email protected]備份開始...'$irangback $iecho 'ssh [email protected]備份結束...stop'$iecho '開始安裝...'$irangdeploy $iecho '結束安裝...'$idone

復原指令碼 rollback.sh
<pre name="code" class="java">#!/bin/bash#復原1停掉tomcat 2刪除webapp內容 3bak中的備份拷貝到webapp下 4 啟動tomcat#停止tomcatfunction killTomcat(){ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}' | xargs kill -9}function startTomcat(){ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}' | xargs kill -9cd /home/wsm/bin ./startup.sh}function rollback(){echo 'Start rollback....'#`\cp -R /home/wsm/webapps/WSMMeasure $dire`rm -rf /home/wsm/webapps/WSMMeasure/*`\cp -R /home/wsm/bak/$dirdate/*  /home/wsm/webapps/WSMMeasure/ `}dirdate=`date +%Y%m%d`killTomcatrollbackstartTomcat








Shell 指令碼 更換tomcat叢集war包

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.