执行前server造成免费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 $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 /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...'<span style="white-space:pre"> </span>
} #停止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`
newwar=`awk -F '=' '{if($1=="newwar")print $2}' profile`
backupWeb
cpWarApps $newwar
RepConf
killTomcat
startTomcat #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到目标server通过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 $host
do
echo 'ssh root@-备份開始...'$i
rangback $i
echo 'ssh root@-备份结束...stop'$i
echo '開始安装...'$i
rangdeploy $i
echo '结束安装...'$i
done
</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 #停止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
版权声明:本文博主原创文章。博客,未经同意不得转载。