本文介绍使用Jenkins一键将SpringBoot应用打包并上传到生产环境服务器运行,这里使用的是直接在服务器上运行FagJar的方式,首先确保服务器环境配置好,安装必须的JDK运行时环境,运行目录,日志存放目录等。
网站设计制作过程拒绝使用模板建站;使用PHP+MYSQL原生开发可交付网站源代码;符合网站优化排名的后台管理系统;成都网站建设、做网站收费合理;免费进行网站备案等企业网站建设一条龙服务.我们是一家持续稳定运营了10余年的创新互联公司网站建设公司。
关于JDK的选择,自1.8版本收费之后,我们大多数选择openjdk作为生产环境的运行时环境,和大多数软件安装包一样,在CentOS服务器上,我们可以选择yum方式和下载压缩包的方式进行安装。大多数情况下使用yum方式比较简单方便。也有特殊情况,一些安全要求高单位或系统,只允许在局域网内运行,此时就需要选择压缩包的方式进行安装了。
yum search java | grep -i --color openjdk
[root@localhost ~]# yum search java | grep -i --color openjdk
openjdk-asmtools-javadoc.noarch : Javadoc for openjdk-asmtools
icedtea-web.x86_64 : Additional Java components for OpenJDK - Java browser
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment 8
java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment
java-1.8.0-openjdk-accessibility.i686 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-demo.i686 : OpenJDK Demos 8
java-1.8.0-openjdk-demo.x86_64 : OpenJDK 8 Demos
java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment 8
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 8
java-1.8.0-openjdk-headless.x86_64 : OpenJDK 8 Headless Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed
java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle 8
java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle
java-11-openjdk.i686 : OpenJDK Runtime Environment 11
java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk-demo.i686 : OpenJDK Demos 11
java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos
java-11-openjdk-devel.i686 : OpenJDK Development Environment 11
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 11
java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime Environment
java-11-openjdk-javadoc.i686 : OpenJDK 11 API documentation
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.i686 : OpenJDK 11 API documentation compressed in a
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in
java-11-openjdk-jmods.i686 : JMods for OpenJDK 11
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.i686 : OpenJDK Source Bundle 11
java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle
java-11-openjdk-static-libs.i686 : OpenJDK libraries for static linking 11
java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static linking
openjdk-asmtools.noarch : To develop tools create proper & improper Java
openprops.noarch : An improved java.util.Properties from OpenJDK
sudo yum install java-11-openjdk.x86_64 -y
[root@localhost /]# java -version
openjdk version "11.0.20" 2023-07-18 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.20.0.8-1.el7_9) (build 11.0.20+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.20.0.8-1.el7_9) (build 11.0.20+8-LTS, mixed mode, sharing)
[root@localhost /]# which java
/usr/bin/java
[root@localhost /]# dirname $(readlink $(readlink $(which java)))
/usr/lib/jvm/java-11-openjdk-11.0.20.0.8-1.el7_9.x86_64/bin
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.20.0.8-1.el7_9.x86_64
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME
[root@localhost /]# source /etc/profile
[root@localhost /]# echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-11.0.20.0.8-1.el7_9.x86_64
执行完以上操作之后,Java运行时环境就安装配置好了,但是一定要注意:PATH在配置的时候,一定要把$JAVA_HOME/bin放在前面,不然系统中安装有多个版本的JDK,那么在使用java命令时,系统会找到其他版本的Java。还有以前很多教程配置中的CLASSPATH和tools.jar在JDK1.5以后就不需要配置了。
mkdir -p /opt/tmp /opt/bak /opt/script /data/container/server
chmod -R 777 /opt/tmp /opt/bak /opt/script /data/container/server
echo "param validate"
if [ $# -lt 1 ]; then
echo "you must use like this : ./publish_gitegg_server.sh [projectname] [server port] [server home dir]"
exit
fi
if [ "$1" != "" ]; then
project_name="$1"
fi
if [ "$2" != "" ]; then
server_port="$2"
fi
if [ "$3" != "" ]; then
server_path="$3"
fi
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.20.0.8-1.el7_9.x86_64
#check server process
server_pid=`/usr/sbin/lsof -n -P -t -i :$server_port`
echo "current :" $server_pid
#shutdown server
kill -9 $server_pid
echo "server shutting down"
while [ -n "$server_pid" ]
do
sleep 5
server_pid=`/usr/sbin/lsof -n -P -t -i :$server_port`
echo "scan server pid :" $server_pid
done
echo "server shutt down"
#publish project
echo "scan no server pid,$project_name publishing"
rm -rf "$server_path"/$project_name*.jar
cp /opt/tmp/$project_name*.jar "$server_path"/$project_name.jar
#bak project
BAK_DIR=/opt/bak/$project_name/`date +%Y%m%d`
mkdir -p "$BAK_DIR"
cp "$server_path"/$project_name.jar "$BAK_DIR"/"$project_name"_`date +%H%M%S`.jar
#remove tmp
rm -rf /opt/tmp/$project_name*.jar
cd "$server_path"
source /etc/profile
nohup java -jar -Xms4096m -Xmx4096m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m "$project_name".jar --server.port="$server_port" > log.file 2>&1 &
echo "Server is starting,please try to access $container_name conslone url"
project_name=gitegg-server
server_port=8080
server_path="/data/container/server"
#param validate
if [ $# -lt 1 ]; then
echo "you must use like this : ./publish_qxq_server.sh [projectname] [server port] [server home dir]"
exit
fi
if [ "$1" != "" ]; then
project_name="$1"
fi
if [ "$2" != "" ]; then
server_port="$2"
fi
if [ "$3" != "" ]; then
server_path="$3"
fi
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.20.0.8-1.el7_9.x86_64
#check server process
server_pid=`/usr/sbin/lsof -n -P -t -i :$server_port`
echo "current :" $server_pid
#shutdown server
kill -9 $server_pid
echo "server shutting down"
while [ -n "$server_pid" ]
do
sleep 5
server_pid=`/usr/sbin/lsof -n -P -t -i :$server_port`
echo "scan server pid :" $server_pid
done
echo "server shutt down"
#publish project
echo "scan no server pid,$project_name publishing"
rm -rf "$server_path"/$project_name*.jar
cp /opt/tmp/$project_name*.jar "$server_path"/$project_name.jar
#bak project
BAK_DIR=/opt/bak/$project_name/`date +%Y%m%d`
mkdir -p "$BAK_DIR"
cp "$server_path"/$project_name.jar "$BAK_DIR"/"$project_name"_`date +%H%M%S`.jar
#remove tmp
rm -rf /opt/tmp/$project_name*.jar
#start server
cd "$server_path"
source /etc/profile
nohup java -jar -Xms4096m -Xmx4096m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m "$project_name".jar --server.port="$server_port" > log.file 2>&1 &
echo "Server is starting,please try to access $project_name conslone url"
chmod 755 publish_server.sh
/opt/script/publish_server.sh gitegg-application 8182 /data/container/server
举报
评论 1
本文标题:Jenkins一键打包部署SpringBoot应用步骤详解
URL地址:http://www.mswzjz.cn/qtweb/news9/297659.html
攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能