Make the server SSH-free before running.
The configuration file does not have much change to overwrite the previous configuration
Profile configuration file
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 Copy related war and script to remote service
scp.sh
#!/bin/bash# copy war|deploy.sh|profile#scp 1.war deploy.sh profile [email protected]:/home/wsm scpdep () {echo ' Start SCP ... ' SCP $ 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 $ ' profile ' newwar= ' awk-f ' = ' {if ($1== "Newwar") print $} ' profile ' for I in $hostdo E Cho ' SCP [email protected] ' $ISCPDEP $newwar root $i/home/wsmecho ' SCP [email protected] ' done
Backup Script 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-$} ' profile ' if [-d ' $dire]; Then echo "Bak folder exists" Else Mkdir-p $dire Fibackupweb
Installation Script deploy.sh
#!/bin/bash#dire= "/home/wsm/bak" #备份webapps #cp War to/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 ... '}# Stop Tomcatfunction Killtomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk ' {print $} ' | Xargs kill-9echo " Killd Tomcat "}function Starttomcat () {PS-EF | grep "/home/wsm/bin/tomcat" | Grep-v grep | awk ' {print $} ' | Xargs Kill-9cd/home/wsm/bin/startup.sh echo "Start Tomcat End"}dire= ' awk-f ' = ' {if ($1== "bak") print $} ' profile ' back Upwebcpwarappsrepconfkilltomcatstarttomcat
Remote execution rangerun.sh
Script SCP to target server to execute script via 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 $ ' profile ' For i in $hostdo echo ' ssh [email protected] backup started ... ' $irangback $iecho ' ssh [email protected] End of backup ... stop ' $iecho ' start installation ... ' $i Rangdeploy $iecho ' End installation ... ' $idone
Rollback Script rollback.sh
<pre name= "code" class= "java" >#!/bin/bash# rollback 1 Stop Tomcat 2 Delete the backup copy in WebApp content 3bak to WebApp under 4 start tomcat# Stop Tomcatfunction Killtomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk ' {print $} ' | Xargs kill-9}funct Ion Starttomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk ' {print $} ' | 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 script Replacement Tomcat cluster War package