Shell 脚本 更换tomcat集群war包
运行之前将服务器弄成免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 $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 $host do echo 'scp root@'$i scpdep $newwar root $i /home/wsm echo 'scp root@...stop' done
备份脚本 backup.sh
#!/bin/bash #dire="/home/wsm/bak" #备份webapps function backupWeb(){ echo 'BackUp Start....' `\cp -R /home/wsm/webapps/WSMMeasure $dire` cd $dire rm -rf $dirdate mv $dire/WSMMeasure $dirdate echo '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 fi backupWeb
安装脚本 deploy.sh
#!/bin/bash #dire="/home/wsm/bak" #备份webapps #cp war到/home/wsm/webapps/WSMMeasure function cpWarApps(){ echo 'cpwarApps Start...' rm -rf /home/wsm/webapps/WSMMeasure/* `\cp /home/wsm/1.war /home/wsm/webapps/WSMMeasure` cd /home/wsm/webapps/WSMMeasure jar -xvf *.war echo 'cpwarApps End...' } #拷贝配置文件 function RepConf(){ #/home/wsm/webapps/WSMMeasure/WEB-INF/classes #$dire/$dirdate/WEB-INF/classes dirdate=`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...' } #停止tomcat function killTomcat(){ ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}' | xargs kill -9 echo "killd tomcat " } function startTomcat(){ ps -ef | grep "/home/wsm/bin/tomcat" | grep -v grep | awk '{print $2}' | xargs kill -9 cd /home/wsm/bin ./startup.sh echo "start tomcat end" } dire=`awk -F '=' '{if($1=="bak")print $2}' profile` backupWeb cpWarApps RepConf killTomcat startTomcat
远程执行 rangerun.sh
将脚本scp到目标服务器通过ssh去执行脚本
#!/bin/bash
#ssh登陆远程执行脚本 #ssh root@host cd /home/wsm ./deploy.sh #ssh [email protected] "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 $host do echo 'ssh root@-备份开始...'$i rangback $i echo 'ssh root@-备份结束...stop'$i echo '开始安装...'$i rangdeploy $i echo '结束安装...'$i done
回滚脚本 rollback.sh
<pre name="code" class="java">#!/bin/bash #回滚1停掉tomcat 2删除webapp内容 3bak中的备份拷贝到webapp下 4 启动tomcat #停止tomcat function 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 -9 cd /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` killTomcat rollback startTomcat
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。