mac电脑
安装homebrew(已安装请跳过)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
安装rsync同步工具
brew install rsync
配置服务器免密
生成公/私钥(生成过的请跳过)
ssh-keygen -t rsa -b 4096 -C "zhuangyan@163.com"
执行公钥拷贝,命令执行后需要输入服务器密码
ssh-copy-id -i /Users/zhuangyan/.ssh/deploy_zzy_rsa.pub username@remoteserver
验证免密是否成功
ssh -i /Users/zhuangyan/.ssh/deploy_zzy_rsa username@remoteserver
maven打包配置
<!-- 其他插件配置 -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>run-local-script</id>
<phase>package</phase> <!-- 执行阶段,例如这里设置为 package -->
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>/Users/zhuangyan/project/java/myserver/service/deploy/pom_package_deploy_and_restart.sh</executable>
<!-- 设置您的本地脚本路径 -->
</configuration>
</execution>
</executions>
</plugin>
同步脚本pom_package_deploy_and_restart.sh
#!/bin/bash
rsa_file=/Users/zhuangyan/.ssh/deploy_zzy_rsa
server_ip=10.10.10.142
server_user=mbs
deploy_from_file_one=/Users/zhuangyan/project/java/uusafe-mbs-ios/uusafe-mbs-ios-service/target/mytest/classes/
deploy_from_file_two=/Users/zhuangyan/project/java/uusafe-mbs-ios/uusafe-mbs-ios-service/target/mytest/lib/
deploy_to_file_one=/home/mbs/emm/ios-service/classes
deploy_to_file_two=/home/mbs/emm/ios-service/lib
echo "-----------------编译完成-----------------"
echo "----------------安装包解压----------------"
mkdir target/mytest/
tar -xf target/ios-service-dist.tar.gz -C target/mytest/
echo "-----------------开始同步-----------------"
rsync -avz -e "ssh -i ${rsa_file}" ${deploy_from_file_one} ${server_user}@${server_ip}:${deploy_to_file_one}
rsync -avz -e "ssh -i ${rsa_file}" ${deploy_from_file_two} ${server_user}@${server_ip}:${deploy_to_file_two}
echo "-----------------同步完成-----------------"
echo "-----------------重启服务-----------------"
ssh -i ${rsa_file} mbs@${server_ip} '/home/mbs/emm/emm.sh restart ios'
echo "-----------------重启完成-----------------"