文章目录
1、概述
#mermaid-svg-MhYgFNGEE2jsSopb {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-MhYgFNGEE2jsSopb .error-icon{fill:#552222;}#mermaid-svg-MhYgFNGEE2jsSopb .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-MhYgFNGEE2jsSopb .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-MhYgFNGEE2jsSopb .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-MhYgFNGEE2jsSopb .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-MhYgFNGEE2jsSopb .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-MhYgFNGEE2jsSopb .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-MhYgFNGEE2jsSopb .marker{fill:#333333;stroke:#333333;}#mermaid-svg-MhYgFNGEE2jsSopb .marker.cross{stroke:#333333;}#mermaid-svg-MhYgFNGEE2jsSopb svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-MhYgFNGEE2jsSopb .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-MhYgFNGEE2jsSopb .cluster-label text{fill:#333;}#mermaid-svg-MhYgFNGEE2jsSopb .cluster-label span{color:#333;}#mermaid-svg-MhYgFNGEE2jsSopb .label text,#mermaid-svg-MhYgFNGEE2jsSopb span{fill:#333;color:#333;}#mermaid-svg-MhYgFNGEE2jsSopb .node rect,#mermaid-svg-MhYgFNGEE2jsSopb .node circle,#mermaid-svg-MhYgFNGEE2jsSopb .node ellipse,#mermaid-svg-MhYgFNGEE2jsSopb .node polygon,#mermaid-svg-MhYgFNGEE2jsSopb .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-MhYgFNGEE2jsSopb .node .label{text-align:center;}#mermaid-svg-MhYgFNGEE2jsSopb .node.clickable{cursor:pointer;}#mermaid-svg-MhYgFNGEE2jsSopb .arrowheadPath{fill:#333333;}#mermaid-svg-MhYgFNGEE2jsSopb .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-MhYgFNGEE2jsSopb .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-MhYgFNGEE2jsSopb .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-MhYgFNGEE2jsSopb .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-MhYgFNGEE2jsSopb .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-MhYgFNGEE2jsSopb .cluster text{fill:#333;}#mermaid-svg-MhYgFNGEE2jsSopb .cluster span{color:#333;}#mermaid-svg-MhYgFNGEE2jsSopb div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-MhYgFNGEE2jsSopb :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}
push
pull
编译 打包 重启
开发环境
Git仓库
服务器
进程
- 代码从开发环境上传到Git仓库
- 服务器从Git仓库拉取代码
- 在服务器上进行编译、打包、重启
2、在服务器上安装Maven
2.1、下载
wget https://archive.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
2.2、解压
tar -zxf apache-maven-3.5.4-bin.tar.gz
mv apache-maven-3.5.4 /opt/module/
/opt/module/apache-maven-3.5.4/bin/mvn -version
2.3、修改配置
vim /opt/module/apache-maven-3.5.4/conf/settings.xml
<!-- 本地仓库存放路径 --><localRepository>/opt/module/mavenRepository</localRepository><!-- 配置国内镜像,使下载更快 --><mirror><id>nexus-aliyun</id><mirrorOf>central</mirrorOf><name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public</url></mirror>
2、在服务器上安装Git
2.1、安装git
yum install -y git
2.2、创建仓库地址的目录
mkdir /opt/module/git_repository
chown -R hjw:hjw /opt/module/git_repository
2.3、创建代码仓库(名为
hello
)
git init --bare /opt/module/git_repository/hello
2.4、免密配置
https://blog.csdn.net/Yellow_python/article/details/127570500
3、Shell脚本
cd /opt/module/projects
touch SpringBootRestart.sh
chmod777 SpringBootRestart.sh
vim SpringBootRestart.sh
#!/bin/sh# artifactIdARTIFACT=hello
# 版本VERSION=-0.0.1-SNAPSHOT
# Maven路径MVN=/opt/module/apache-maven-3.5.4/bin/mvn
# 代码位置LOC=/opt/module/projects/$ARTIFACT# jar名JAR=${ARTIFACT}${VERSION}.jar
pid=`ps -ef|grep ${JAR}|grep -v grep|grep -v kill|awk'{print $2}'`if[${pid}];thenecho'停止进程'kill -15 $pidfisleep3pid=`ps -ef|grep ${JAR}|grep -v grep|grep -v kill|awk'{print $2}'`if[${pid}];thenecho'杀进程'kill -9 $pidelseecho'停止进程成功'fiecho'从Git仓库拉取最新代码'cd$LOCgit pull
echo'打包'output=`$MVN clean package -Dmaven.test.skip=true`echo'启动项目'cd target
nohup java -jar ${JAR}&>${ARTIFACT}.log &# 查看进程状态sleep2echo`ps -ef|grep ${JAR}|grep -v grep`
4、SpringBoot部署测试
4.1、使用IDEA创建工程(下面2种方法)
方法1:先创建SpringBoot工程,再去关联Git仓库
方法2:直接创建关联Git仓库的工程
4.2、服务器从仓库下载代码
mkdir -p /opt/module/projects
cd /opt/module/projects
git clone 用户名@主机地址:/opt/module/git_repository/hello
4.3、执行脚本
/opt/module/projects/SpringBootRestart.sh
版权归原作者 小基基o_O 所有, 如有侵权,请联系我们删除。