由于项目每天都需要更新版本到多台服务器,为了节省时间和精力,特写脚本来代替重复性操作。
步骤
1、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 |
| . . |
| |
| |
+-----------------+
2、scp ~/.ssh/id_rsa.pub user@remoteip:~/.ssh/authorized_keys 将本地生成的公钥拷贝到远程服务器上,从而实现从本地可以无密码访问远程服务器。
3、本地脚本实现将应用报拷贝到远程服务器,并在远程服务器上生成开关文件。shell脚本如下:
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
4、远程服务器端shell脚本循环检查开关文件是否存在,当存在时,将was应用服务停止并将应用包进行解压,然后再自动启动was服务
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