Linux系统下部署项目
手工部署
- 在idea打包项目为jar包
- 将jar包上传到 Linux服务器 mkdir /usr/local/app --创建app目录存放jar包
- 启动 Springboot程序 java -jar xxxxxm.jar
- 检查防火墙,确保端口8080对外开放,访问springboot项目 firewall-cmd --zone=public --list-ports
- 把springboot程序改为后台运行,并将日志输出到日志文件
- 使用 nohup 命令: 英文全称 no hang up 不挂起,用于不管断地运行指定命令,退出终端不会影响程序的运行
- 语法格式;
- 举例:nohup java -jar boot工程.jar &> hello.log & -----后台运行 java -jar 命令,并将日志输出到hello.log文件
- 使用 nohup 命令: 英文全称 no hang up 不挂起,用于不管断地运行指定命令,退出终端不会影响程序的运行
- 停止SpringBoot程序
- 查找: ps -ef | grep 'java -jar'
- kill - 9 xxxx xxxx为后台运行jar线程id
Shell脚本自动部署
基于git远程仓库pull到Linux服务安装部署
本地开发环境----push----> git仓库-----pull----->Linux服务器
操作步骤:
- 在Linux中安装Git
- 在Linux中安装Maven
- 编写shell脚本(拉取代码,编译,打包,启动)
- 为用户授予执行shell脚本的权限
- 执行shell脚本
- 在Linux中安装Git
yum list git 列出git安装包
yum install git 在线安装git
- 使用Git代码克隆代码
cd /usr/local git clone https://xxxxxxxxx.git
- 将Maven安装包上传到Linux,在Linux中安装Maven
tar -zxvf xxxxxxx.tar.gz -C /usr/local vim /etc/profile 修改配置文件 export MAVEN_HOME=/usr/local/apache-maven-3.8.6 export PATH=$PATH:$MAVEN_HOME/bin
source /etc/profile 更新配置文件
mvn -version 查看maven是否安装成功
vim /usr/local/apache-maven-x.x.x/conf/settings.xml 修改配置内容:
<localRepository>/usr/local/repo</localRepository> <!-- 指定maven仓库位置为repo -->
<!-- 配置阿里云的仓库:-->
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>
- 将编译好的shell脚本文件复制到Linux中
mkdir sh 在/usr/local/文件夹下创建sh文件夹存放shell脚本
用xftp或其他工具把脚本文件上传到 sh 文件夹
- 为用户授权----使用 chmod 命令 ,详解参考https://www.runoob.com/linux/linux-comm-chmod.html
chmod 755 xxxx.sh xxxx.sh为需要执行的脚本文件 为文件拥有者授予读、写、执行 权限,同组用户和其他用户授予读、执行权限
- 执行shell脚本文件
sh xxxx.sh 或者 ./xxxx.sh