因为项目天天都须要更新版本到多台服务器,为了节省时间和精力,特写脚原本代替重复性操做。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