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打包配置

org.codehaus.mojoexec-maven-plugin3.0.0run-local-scriptpackage exec/Users/zhuangyan/project/java/myserver/service/deploy/pom_package_deploy_and_restart.sh

同步脚本pom_package_deploy_and_restart.sh

#!/bin/bashrsa_file=/Users/zhuangyan/.ssh/deploy_zzy_rsaserver_ip=10.10.10.142server_user=mbsdeploy_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/classesdeploy_to_file_two=/home/mbs/emm/ios-service/libecho "-----------------编译完成-----------------"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 "-----------------重启完成-----------------"