linxu将文件/代码从一台机器同步到另外一台机器
作者:互联网
# 代码同步
DevOps中,常常需要将一个linux A环境中的代码或文件同步到另外一台linux机器B,同步后重启Linxu B上的应用服务器,
其shell脚本如下:
```shell
[lxl@WeifuwuServer sh]$ vim tongbu_service_order_to_174.sh
#!/bin/bash
# 同步
rsync -avz -e 'ssh -p 10068' --delete /anjutu/tomcat8_service_order/webapps/service-order/ ajtuser@111.230.134.174:/anjutu/tomcat8_service_order/webapps/service-order
# 修改环境变量
ssh -p 10068 ajtuser@111.230.134.174 sed -i 's/spring.profiles.active=dev/spring.profiles.active=prd/g' /anjutu/tomcat8_service_order/webapps/service-order/WEB-INF/classes/application.properties
# 重启项目
ssh -p 10068 ajtuser@111.230.134.174 /anjutu/sh/150jenkins_service_order_restart.sh
```
说明
> 111.230.134.174 是目标服务器ip
>
> ajtuser 是174服务器上的用户
```shell
150jenkins_service_order_restart.sh 是在111.230.134.174服务器上的tomcat重启命令脚本,脚本命令如下
#! /bin/sh
# 找到 tomcat pid
ui=$(ps x |grep java |grep tomcat8_service_order/ |grep -v grep|awk '{print $1}')
echo 'tomcat8_service_order pid is' $ui
# then restart tomcat
echo 'then tomcat restart now '
# User add system enviroment vars
#JAVA_HOME=/anjutu/jdk1.6
#JAVA_HOME=/anjutu/jdk1.7
JAVA_HOME=/anjutu/jdk1.8
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=./:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/jre/lib/rt.jar
export JAVA_HOME PATH CLASSPATH
export PATH=$PATH:/usr/local/ImageMagick/bin
kill -9 $ui
sleep 5
/anjutu/tomcat8_service_order/bin/startup.sh
#sleep 5 sec , wait tomcat start
sleep 5
echo "tomcat8_service_order restart ok.."
# start log
#tail -f /anjutu/tomcat8_service_order/logs/catalina.out
```
标签:JAVA,机器,service,一台,anjutu,HOME,linxu,order,tomcat8 来源: https://blog.csdn.net/ll535299/article/details/120449089