需求:
jdk 1.8
Maven 3.3.0+
MySql 5.7.11+
tomcat 8
环境Linux 7.5
软件包下载地址:
jdk-8u181-linux-x64.tar.gz
百度云链接:https://pan.baidu.com/s/16BpipO0eVTe8a0A43-Y9fA 密码:1s8l
apache-maven-3.5.3-bin.tar.gz
百度云链接:https://pan.baidu.com/s/1p8K1vejoP4FtGIuex-_QUg 密码:t71e
mysql-5.7.11-1.el7.x86_64.rpm-bundle.tar
百度云链接:https://pan.baidu.com/s/1zKoDH-zLNJJuOSmBqMkdXA 密码:gsl3
apache-tomcat-8.0.30.tar.gz
百度云链接:https://pan.baidu.com/s/10qkqR_HMwV4xnpOLQEHF9Q 密码:rnmy
步骤:
解压jdk1.8
tar xf jdk-8u181-linux-x64.tar.gz -C /usr/local/
解压maven
tar xf apache-maven-3.5.3-bin.tar.gz -C /usr/local/
解压tomcat8
tar xf apache-tomcat-8.0.30.tar.gz -C /usr/local/
设置环境变量:
vim /etc/profile
#JAVA_HOME
export JAVA_HOME=/usr/local/jdk1.8.0_181
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
#MAVEN
export MAVEN_HOME=/usr/local/apache-maven-3.5.3
export PATH=$MAVEN_HOME/bin:$PATH
保存退出
source /etc/profile (刷新加载配置文件)
验证是否生效:
java -version
mvn -v
启动tomcat:
/usr/local/apache-tomcat-8.0.30/bin/startup.sh
打开网页: IP:8080 (tomcat是否成功)(如云服务器,记得开启安全组端口)
安装数据库:
https://blog.csdn.net/qq_33663251/article/details/54693201
导入JeeSite 4.0源码:
git clone https://gitee.com/thinkgem/jeesite4.git
修改mysql连接配置文件。(因这环境都在一个机器上,使用默认即可)
jeesite4/web/src/main/resources/config(配置文件位置)
执行打war包:
cd jeesite4/web/bin/
chmod +x package.sh
./package.sh
查看打包
将war包放进tomcat8里
验证 ip:8080/web
自己写的自动更新拉取代码的脚本(利用crontab,某个时间检测代码。或用jenkins也可实现)
#!/bin/bash
#自动更新war包脚本
#git ssh协议获取代码
#/teachLab_server项目git路径文件夹
#/web_backup,war包备份路径
#teachLab_server项目分支,拉取代码,存在则跳过
cd /teachLab_server/
if [ ! -d /teachLab_server/teachLab_server/ ];then
/usr/bin/git clone git@xxxxxx项目地址
#执行打war包命令
cd /teachLab_server/teachLab_server/jeesite4/web/bin
/usr/bin/chmod +x ./package.sh
./package.sh
#关闭tomcat
/usr/bin/killall -9 java
/usr/bin/killall -9 java
/usr/bin/killall -9 java
#打包旧的web项目文件,备份
if [ -d /usr/local/tomcat8/webapps/web ];then
cd /usr/local/tomcat8/webapps/
/usr/bin/tar -cvf /web_backup/`date +%F_%Hh_%Mm`.tar.gz ./web
#删除4天前的备份
find /web_backup/ -mtime +3 -exec rm -rf {} \;
fi
#删除旧的项目代码
rm -rf /usr/local/tomcat8/webapps/web/META-INF/
rm -rf /usr/local/tomcat8/webapps/web/org
rm -rf /usr/local/tomcat8/webapps/web/WEB-INF
#将新的war包解压
cd /teachLab_server/teachLab_server/jeesite4/web/target/
/usr/local/jdk1.8.0_181/bin/jar xf web.war
#将新代码mv到tomcat上
mv ./META-INF ./org ./WEB-INF /usr/local/tomcat8/webapps/web/
#启动tomcat
/usr/local/tomcat8/bin/startup.sh
cd /usr/local/tomcat8/bin
./startup.sh
#重启tomcat
/jiaoben/tomcatstart.sh
#删除打包后的文件夹
rm -rf /teachLab_server/teachLab_server/jeesite4/web/target
fi
#git更新代码,如没有更新则跳过
cd /teachLab_server/teachLab_server/
A=`git pull | awk '{print $1}'`
if [ "$A" = Already ];then
echo '没有新的代码更新'
else
#更新代码
/usr/bin/git pull
#执行打war包命令
cd /teachLab_server/teachLab_server/jeesite4/web/bin
/usr/bin/chmod +x ./package.sh
./package.sh
#关闭tomcat
/usr/bin/killall -9 java
/usr/bin/killall -9 java
/usr/bin/killall -9 java
#打包旧的web项目文件,备份
if [ -d /usr/local/tomcat8/webapps/web ];then
cd /usr/local/tomcat8/webapps/
/usr/bin/tar -cvf /web_backup/`date +%F_%Hh_%Mm`.tar.gz ./web
#删除4天前的备份
find /web_backup/ -mtime +3 -exec rm -rf {} \;
fi
#删除旧的项目代码
rm -rf /usr/local/tomcat8/webapps/web/META-INF/
rm -rf /usr/local/tomcat8/webapps/web/org
rm -rf /usr/local/tomcat8/webapps/web/WEB-INF
#将新的war包解压
cd /teachLab_server/teachLab_server/jeesite4/web/target/
/usr/local/jdk1.8.0_181/bin/jar xf web.war
#将新代码mv到tomcat上
mv ./META-INF ./org ./WEB-INF /usr/local/tomcat8/webapps/web/
#启动tomcat
/usr/local/tomcat8/bin/startup.sh
cd /usr/local/tomcat8/bin
./startup.sh
#重启tomcat
/jiaoben/tomcatstart.sh
#删除打包后的文件夹
rm -rf /teachLab_server/teachLab_server/jeesite4/web/target
fi
(脚本是更新代码,打包war包,将war包里的代码解压,换成tomcat里新的代码。)
(避免直接删除web文件,导致项目里的本地数据消失)