1:利用好工具确实能事半功倍,最重要的是减少重复劳动。
jenkins的安装就不再重复提取说明了,网上安装步骤太多了。
(1)下面来记录下部署微服务项目的步骤:
脚本:demo.sh
#!/bin/bash #pring cloud工程自动关闭 #(如果不加这个变量,任务执行成功之后Spring Cloud工程会自动停止) BUILD_ID=demo #先删除之前启动的进程 echo "kill demo... start" #根据自己的工程的jar包查找进程 #PROCESS="$(ps -ef|grep demox|grep -v grep|awk '{print $2}')" PROCESS="$(ps -ef | grep -E 'demo-eureka|demo-api|demo-system|demo-sso|demo-user|demo-web' | grep -v grep | awk '{print$2}' )" if [[ -n $PROCESS ]]; then echo "demo running... start kill..." kill -9 $PROCESS else echo "demo not running" fi echo "kill demo... end" #为了方便启动,将打好的jar包复制到同一个目录下 JAR_PATH="/home/zzjs/app/demo/bin" echo "copy jars to $JAR_PATH... start" #从Git上下载的源码的放到任务的工作空间中 WORKSPACE="/root/.jenkins/workspace/demo" API="demo-api" EUREKA="demo-eureka" SSO="demo-sso" SYSTEM="demo-system" USER="demo-user" WEB="demo-web" TARGET_PATH="target" #根据自己的Spring Cloud工程中打包的jar包名称匹配 #(也可以直接写死jar包的名称,比如这里我打好jar包的名称就是module的名称,如demo-eureka.jar) cd $WORKSPACE/$API/$TARGET_PATH #AUTH_JAR=$(ls |grep $BASE.jar) echo "copy $API.jar" cp -b $API-1.0-SNAPSHOT.jar $JAR_PATH/$API.jar cd $WORKSPACE/$EUREKA/$TARGET_PATH #EUREKA_JAR=$(ls |grep $EUREKA.jar) echo "copy $EUREKA.jar" cp -b $EUREKA-1.0-SNAPSHOT.jar $JAR_PATH/$EUREKA.jar cd $WORKSPACE/$SSO/$TARGET_PATH #ZUUL_JAR=$(ls |grep $ZUUL.jar) echo "copy $SSO.jar" cp -b $SSO-1.0-SNAPSHOT.jar $JAR_PATH/$SSO.jar cd $WORKSPACE/$SYSTEM/$TARGET_PATH #ZUUL_JAR=$(ls |grep $ZUUL.jar) echo "copy $SYSTEM.jar" cp -b $SYSTEM-1.0-SNAPSHOT.jar $JAR_PATH/$SYSTEM.jar cd $WORKSPACE/$USER/$TARGET_PATH #ZUUL_JAR=$(ls |grep $ZUUL.jar) echo "copy $USER.jar" cp -b $USER-1.0-SNAPSHOT.jar $JAR_PATH/$USER.jar cd $WORKSPACE/$WEB/$TARGET_PATH #ZUUL_JAR=$(ls |grep $ZUUL.jar) echo "copy $WEB.jar" cp -b $WEB-1.0-SNAPSHOT.jar $JAR_PATH/$WEB.jar echo "copy jars to $JAR_PATH... end" #启动工程 echo "start demo..." #需要按照eureka/auth/zuul的顺序启动,这里采用sleep的方式等待前一个jar包启动完毕 #(这样做是有点问题的,无法保证前一个jar包成功启动,不过我没有找到其他方式,暂时先这样处理) cd $JAR_PATH nohup /home/zzjs/jdk1.8/jdk1.8.0_171/bin/java -jar -Xms256m -Xmx256m $EUREKA.jar > eureka.out 2>&1 & echo "waiting for eureka start..." #sleep 15 echo "waiting for api start..." nohup /home/zzjs/jdk1.8/jdk1.8.0_171/bin/java -jar -Xms256m -Xmx256m $API.jar > api.out 2>&1 & #sleep 15 echo "waiting for sso start..." nohup /home/zzjs/jdk1.8/jdk1.8.0_171/bin/java -jar -Xms256m -Xmx256m $SSO.jar > sso.out 2>&1 & #sleep 15 echo "waiting for system start..." nohup /home/zzjs/jdk1.8/jdk1.8.0_171/bin/java -jar -Xms256m -Xmx256m $SYSTEM.jar > system.out 2>&1 & #sleep 15 echo "waiting for user start..." nohup /home/zzjs/jdk1.8/jdk1.8.0_171/bin/java -jar -Xms256m -Xmx256m $USER.jar > user.out 2>&1 & #sleep 15 echo "waiting for web start..." nohup /home/zzjs/jdk1.8/jdk1.8.0_171/bin/java -jar -Xms256m -Xmx256m $WEB.jar > web.out 2>&1 & echo "start demo... end"
2:单个项目打成war 部署到服务器(linux)tomcat中
此次利用tomcat热部署进行:
安装tomcat 然后在tomcat config下tomcat-users.xml 在倒数第二行 写入:
<role rolename="admin"/> <role rolename="admin-gui"/> <role rolename="admin-script"/> <role rolename="manager"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/><user name="admin" password="admin" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status" />
其中 :
<user name="admin" password="admin" 为用户名和密码,访问tomcat用然后在jenkins凭据中添加 tomcat用户名和密码;之前的步骤同上,下面进行tomcat热部署设置
这样就打包完成自动发布到tomcat中了,至此结束。