Shell 指令碼 更換tomcat叢集war包,tomcatwar

來源:互聯網
上載者:User

Shell 指令碼 更換tomcat叢集war包,tomcatwar

運行之前將伺服器弄成免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 root@192.168.68.29:/home/wsm scpdep(){echo 'Start Scp ...'scp $1 deploy.sh backup.sh profile $2@$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 root@'$iscpdep $newwar root $i /home/wsmecho 'scp root@...stop'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  /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...'<span style="white-space:pre"></span>}#停止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`newwar=`awk -F '=' '{if($1=="newwar")print $2}' profile`backupWebcpWarApps $newwarRepConfkillTomcatstartTomcat#LocatIP=ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'#STATUS_CODE=`curl -o /dev/null -s -m 13 --connect-timeout 20 -w %{http_code} $LocatIP:8080/WSMMeasure/str/report/performancereport`

遠程執行 rangerun.sh

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

#!/bin/bash

#ssh登陸遠程執行指令碼#ssh root@host cd /home/wsm ./deploy.sh#ssh  root@192.168.68.29 "cd /home/wsm && ls"rangback(){ssh root@$1 "cd /home/wsm && ./backup.sh"}rangdeploy(){ssh root@$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 root@-備份開始...'$irangback $iecho 'ssh root@-備份結束...stop'$iecho '開始安裝...'$irangdeploy $iecho '結束安裝...'$idone
</pre><pre code_snippet_id="507753" snippet_file_name="blog_20141104_4_9361903" name="code" class="java">復原指令碼 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









war包部署到tomcat之後,tomcat跑的項目是war包?如果想更改項目的java檔案也就是類,應該在什地方更改

如上,WAR部署後,自動解壓為檔案夾,不是直接跑war包。一般war包中就不包含原始碼了,如果想修改Java代碼,應該在打包前的項目中修改,修改後再重新打包成war,卸載原來的應用,重新部署。
 
對於tomcat 部署WAR包後訪問系統的問題:

1.你是否修改過tomcat預設的連接埠?沒有就是8080.
2.你WAR包的名稱,比如test
3.一般網站都有一個index.jsp/index.html即你輸入localhost:8080/項目名就可以訪問。
那麼,你可以這樣試試:localhost:8080/你的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.