因爲項目天天都須要更新版本到多臺服務器,爲了節省時間和精力,特寫腳原本代替重複性操做。web
步驟shell
一、ssh-keygen -t rsa 命令本地機器生成密鑰對服務器
Generating public/private rsa key pair.
Enter file in which to save the key (/websphere/wasadmin/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /websphere/wasadmin/.ssh/id_rsa.
Your public key has been saved in /websphere/wasadmin/.ssh/id_rsa.pub.
The key fingerprint is:
97:0a:5a:15:c3:a5:1b:1a:b1:24:1d:5b:84:60:5c:70 wasadmin@CNSZ443817
The key's randomart image is:
+--[ RSA 2048]----+
| .==E==.. |
| ..+o=.+ |
| + + |
| + o . |
| + S o |
| o . o |
| . . |
| |
| |
+-----------------+app
二、scp ~/.ssh/id_rsa.pub user@remoteip:~/.ssh/authorized_keys 將本地生成的公鑰拷貝到遠程服務器上,從而實現從本地能夠無密碼訪問遠程服務器。dom
三、本地腳本實現將應用報拷貝到遠程服務器,並在遠程服務器上生成開關文件。shell腳本以下:ssh
trigger() { echo "begin trigger $1" echo "begin trigger $2" scp /fbs/deploy/ISBS.war $1:$2 ssh user@$1 >/dev/null 2>&1 << eeooff >/tmp/_FBS_Deploy_Swith_$3 exit eeooff echo "trigger $1 done!" } trigger remote /fbs/apps/ISBS_war.ear/ISBS.war B
四、遠程服務器端shell腳本循環檢查開關文件是否存在,當存在時,將was應用服務中止並將應用包進行解壓,而後再自動啓動was服務ide
while true do sleep 60 if [ -r /tmp/_FBS_Deploy_Swith_B ];then echo "Begin to deploy\n" > ./FBSDeploy.log rm /tmp/_FBS_Deploy_Swith_B /websphere/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/stopServer.sh server1 -username wasadmin -password wasadmin -nowait cd /fbs/apps/ISBS_war.ear/ISBS.war jar -xvf ISBS.war /websphere/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/startServer.sh server1 echo "deploy success\n" fi done