文章目录
- 一、需求背景及实现流程
- 1. 需求背景
- 2. 实现流程
- 二、软件准备
- 2.1. 公共工具包yum下载
- 2.2. tomcat安装及配置
- 2.3. maven安装及配置
- 2.4. 安装mysql
- 2.5. order项目配置
- 2.6. 脚本制作
- 2.7. 运行脚本
一、需求背景及实现流程
1. 需求背景
order项目代码已经到版本仓库中,执行shell脚本一键部署
2. 实现流程
实现流程 | 实现流程说明 |
---|---|
1. | 远程拉取git远程仓库代码 |
2. | 使用mvn进行编译打包 |
3. | 一键部署项目 |
order项目地址 | https://github.com/gb-heima/order |
二、软件准备
2.1. 公共工具包yum下载
yum install unzip wget git -y
2.2. tomcat安装及配置
Centos7 下载、安装、配置、启动部署
2.3. maven安装及配置
Centos7 安装maven
2.4. 安装mysql
Linux6、7 系列 安装、卸载mysql
2.5. order项目配置
配置数据库、执行sql创建表
2.6. 脚本制作
#
#!/bin/bash
DATE=$(date +%F_%T)TOMCAT_NAME=$1
TOMCAT_DIR=/root/$TOMCAT_NAME
ROOT=$TOMCAT_DIR/webapps/ROOTBACKUP_DIR=/data/backup
WORK_DIR=/tmp
PROJECT_NAME=$2# 拉取代码
cd $WORK_DIR
if [ ! -d $PROJECT_NAME ]; thengit clone $3cd $PROJECT_NAME
elsecd $PROJECT_NAMEgit pull
fi# 构建
mvn clean package -Dmaven.test.skip=true
if [ $? -ne 0 ]; thenecho "maven build failure!"exit 1
fi# 部署
TOMCAT_PID=$(ps -ef |grep "$TOMCAT_NAME" |egrep -v "grep|$$" |awk 'NR==1{print $2}')
[ -n "$TOMCAT_PID" ] && kill -9 $TOMCAT_PID
[ -d $ROOT ] && mv $ROOT $BACKUP_DIR/${TOMCAT_NAME}_ROOT$DATE
unzip $WORK_DIR/$PROJECT_NAME/target/*.war -d $ROOT
$TOMCAT_DIR/bin/startup.sh
运行脚本.
#格式 ./batch_order tomcat名称
./batch_order tomcat9
2.7. 运行脚本
#格式 bash 脚本 tomcat名称 项目链接
[root@ly-01 ~]# bash 12.sh order-tomcat order https://github.com/gb-heima/order -x
Cloning into 'order'...
remote: Enumerating objects: 433, done.
remote: Counting objects: 100% (433/433), done.
remote: Compressing objects: 100% (272/272), done.
remote: Total 433 (delta 136), reused 398 (delta 101), pack-reused 0
Receiving objects: 100% (433/433), 3.18 MiB | 140.00 KiB/s, done.
Resolving deltas: 100% (136/136), done.
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.gblfy:order:war:1.0
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-war-plugin is missing. @ line 127, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] --------------------------< com.gblfy:order >---------------------------
[INFO] Building order 1.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ order ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ order ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ order ---
[INFO] Compiling 9 source files to /tmp/order/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ order ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ order ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ order ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ order ---
[INFO] Packaging webapp
[INFO] Assembling webapp [order] in [/tmp/order/target/order]
[INFO] Processing war project
[INFO] Copying webapp resources [/tmp/order/src/main/webapp]
[INFO] Webapp assembled in [1052 msecs]
[INFO] Building war: /tmp/order/target/order.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.633 s
[INFO] Finished at: 2020-02-25T13:07:16+08:00
[INFO] ------------------------------------------------------------------------
Archive: /tmp/order/target/order.warcreating: /root/order-tomcat/webapps/ROOT/META-INF/inflating: /root/order-tomcat/webapps/ROOT/META-INF/MANIFEST.MF creating: /root/order-tomcat/webapps/ROOT/WEB-INF/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/mybatis/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/spring/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/model/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/controller/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/service/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/service/impl/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/dao/creating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/creating: /root/order-tomcat/webapps/ROOT/assets/creating: /root/order-tomcat/webapps/ROOT/assets/avatars/creating: /root/order-tomcat/webapps/ROOT/assets/css/creating: /root/order-tomcat/webapps/ROOT/assets/css/images/creating: /root/order-tomcat/webapps/ROOT/assets/font/creating: /root/order-tomcat/webapps/ROOT/assets/images/creating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/creating: /root/order-tomcat/webapps/ROOT/assets/js/creating: /root/order-tomcat/webapps/ROOT/assets/js/date-time/creating: /root/order-tomcat/webapps/ROOT/assets/js/flot/creating: /root/order-tomcat/webapps/ROOT/assets/js/fuelux/creating: /root/order-tomcat/webapps/ROOT/assets/js/fuelux/data/creating: /root/order-tomcat/webapps/ROOT/assets/js/jqGrid/creating: /root/order-tomcat/webapps/ROOT/assets/js/jqGrid/i18n/creating: /root/order-tomcat/webapps/ROOT/assets/js/markdown/creating: /root/order-tomcat/webapps/ROOT/assets/js/x-editable/creating: /root/order-tomcat/webapps/ROOT/jsp/creating: /root/order-tomcat/webapps/ROOT/jsp/common/inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/web.xml inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/logback.xml inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/mybatis/jdbc.properties inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/spring/applicationContext.xml inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/spring/context-dispatcher.xml inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/model/Category$CategoryBuilder.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/model/Category.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/model/Menu$MenuBuilder.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/model/Menu.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/controller/OrderEntryControllor.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/service/MenuManager.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/service/CategoryManager.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/service/impl/CategoryManagerImpl.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/service/impl/MenuManagerImpl.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/dao/MenuDAO.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/classes/com/gblfy/order/dao/CategoryDAO.class inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/slf4j-api-1.7.26.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/logback-classic-1.2.3.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/logback-core-1.2.3.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/mybatis-3.1.1.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/mybatis-spring-1.2.3.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/mysql-connector-java-8.0.16.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/protobuf-java-3.6.1.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/spring-webmvc-4.0.0.RELEASE.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/spring-beans-4.0.0.RELEASE.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/spring-context-4.0.0.RELEASE.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/spring-core-4.0.0.RELEASE.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/commons-logging-1.1.1.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/spring-expression-4.0.0.RELEASE.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/spring-web-4.0.0.RELEASE.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/aopalliance-1.0.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/spring-aop-4.0.0.RELEASE.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/spring-tx-4.0.0.RELEASE.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/spring-jdbc-4.0.0.RELEASE.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/jstl-1.2.jar inflating: /root/order-tomcat/webapps/ROOT/WEB-INF/lib/standard-1.1.2.jar inflating: /root/order-tomcat/webapps/ROOT/assets/avatars/Thumbs.db inflating: /root/order-tomcat/webapps/ROOT/assets/avatars/avatar.png inflating: /root/order-tomcat/webapps/ROOT/assets/avatars/avatar1.png inflating: /root/order-tomcat/webapps/ROOT/assets/avatars/avatar2.png inflating: /root/order-tomcat/webapps/ROOT/assets/avatars/avatar3.png inflating: /root/order-tomcat/webapps/ROOT/assets/avatars/avatar4.png inflating: /root/order-tomcat/webapps/ROOT/assets/avatars/avatar5.png inflating: /root/order-tomcat/webapps/ROOT/assets/avatars/profile-pic.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/avatars/user.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/css/ace-ie.min.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/ace-rtl.min.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/ace-skins.min.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/ace.min.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/bootstrap-editable.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/bootstrap-timepicker.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/bootstrap.min.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/chosen.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/colorbox.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/colorpicker.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/datepicker.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/daterangepicker.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/dropzone.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/font-awesome-ie7.min.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/font-awesome.min.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/fullcalendar.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/images/Thumbs.db inflating: /root/order-tomcat/webapps/ROOT/assets/css/images/loading.gif inflating: /root/order-tomcat/webapps/ROOT/assets/css/jquery-ui-1.10.3.custom.min.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/jquery-ui-1.10.3.full.min.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/jquery.gritter.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/select2.css inflating: /root/order-tomcat/webapps/ROOT/assets/css/ui.jqgrid.css inflating: /root/order-tomcat/webapps/ROOT/assets/font/fontawesome-webfont.woff inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/image-1.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/image-2.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/image-3.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/image-4.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/image-5.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/image-6.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/thumb-1.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/thumb-2.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/thumb-3.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/thumb-4.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/thumb-5.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/images/gallery/thumb-6.jpg inflating: /root/order-tomcat/webapps/ROOT/assets/js/ace-elements.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/ace-extra.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/ace.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/additional-methods.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/bootbox.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/bootstrap-colorpicker.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/bootstrap-tag.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/bootstrap-wysiwyg.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/bootstrap.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/chosen.jquery.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/date-time/bootstrap-datepicker.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/date-time/bootstrap-timepicker.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/date-time/daterangepicker.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/date-time/moment.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/dropzone.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/excanvas.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/flot/jquery.flot.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/flot/jquery.flot.pie.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/flot/jquery.flot.resize.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/fuelux/data/fuelux.tree-sampledata.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/fuelux/fuelux.spinner.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/fuelux/fuelux.tree.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/fuelux/fuelux.wizard.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/fullcalendar.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/html5shiv.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jqGrid/i18n/grid.locale-en.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jqGrid/jquery.jqGrid.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery-1.10.2.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery-2.0.3.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery-ui-1.10.3.custom.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery-ui-1.10.3.full.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.autosize.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.colorbox-min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.dataTables.bootstrap.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.dataTables.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.easy-pie-chart.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.gritter.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.hotkeys.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.inputlimiter.1.3.1.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.knob.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.maskedinput.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.mobile.custom.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.nestable.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.slimscroll.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.sparkline.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.ui.touch-punch.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/jquery.validate.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/markdown/bootstrap-markdown.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/markdown/markdown.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/respond.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/select2.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/typeahead-bs2.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/x-editable/ace-editable.min.js inflating: /root/order-tomcat/webapps/ROOT/assets/js/x-editable/bootstrap-editable.min.js inflating: /root/order-tomcat/webapps/ROOT/index.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/categoryAdd.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/categoryEdit.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/categoryList.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/categoryList_blank.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/common/commonStyle.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/common/header.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/common/leftTree.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/menuAdd.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/menuAdd_blank.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/menuEdit.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/menuList.jsp inflating: /root/order-tomcat/webapps/ROOT/jsp/menuList_blank.jsp creating: /root/order-tomcat/webapps/ROOT/META-INF/maven/creating: /root/order-tomcat/webapps/ROOT/META-INF/maven/com.gblfy/creating: /root/order-tomcat/webapps/ROOT/META-INF/maven/com.gblfy/order/inflating: /root/order-tomcat/webapps/ROOT/META-INF/maven/com.gblfy/order/pom.xml inflating: /root/order-tomcat/webapps/ROOT/META-INF/maven/com.gblfy/order/pom.properties
Using CATALINA_BASE: /root/order-tomcat
Using CATALINA_HOME: /root/order-tomcat
Using CATALINA_TMPDIR: /root/order-tomcat/temp
Using JRE_HOME: /app/jdk1.8.0_202
Using CLASSPATH: /root/order-tomcat/bin/bootstrap.jar:/root/order-tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@ly-01 ~]#