外卖项目部署

项目部署

部署架构

在这里插入图片描述

服务器技术栈架构

1.服务器A:(192.168.138.100)

Nginx:部署前端项目,配置反向代理

MySQL:主从复制结构中的主库

2.服务器B:(192.168.138.101)

jdk:运行java项目

git:版本控制,远程拉取项目

maven:项目构建打包

jar:SpringBoot项目达成jar包基于内置Tomcat运行

MySQL:主从复制结构中的从表

3.服务器C:(172.17.2.94)

Redis:缓存中间件

部署前端项目

1.在服务器A中安装Nginx,将前端打包文件上传到Nginx的html目录下。

2.修改Nginx配置文件nginx.conf

server{
    
    
  listen 80;
  server_name localhost;
  
  location / {
    
    
    #设置html/dist为根目录
  	root html/dist;
  	index index.html;
  }
  
  location ^~ /api/ {
    
    
  	#/api/employee/login被重写为 /employee/login发送给后端服务器
  	rewrite ^/api/(.*)$ /$1 break;
  	proxy_pass http://192.168.138.101:8080;
  }
}

后端项目部署

1.在 /usr/local/javaapp下git从远程仓库将项目克隆下来:

git clone https://......

2.使用下列自动部署脚本进行部署:

reggieStart.sh:

echo ==================
echo   自动化部署脚本启动
echo ==================
echo 停止原来运行中的工程
APP_NAME=reggie_take_out

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`

if [${tpid}]; then
	echo 'Stop Process...'
	kill -15 $tpid
fi
sleep 2
tpid=`ps-ef | grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [${tpid}];then
	echo 'Kill Process!'
	kill -9 $tpid
else
	echo 'Stop Success!'
fi

echo 准备从Git仓库拉取最新代码
cd /usr/local/javaapp/reggie_take_out

echo 开始从Git仓库拉取最新代码
git pull
echo 代码拉取完成

echo 开始打包
output=`mvn clean package -Dmaven.test.skip=true`

cd target

echo 启动项目
nohup java -jar reggie_take_out-1.0-SNAPSHOT.jar &> reggie_take_out.log &
echo 项目启动完成

将上述reggieStart.sh文件上传至服务器B,通过chmod命令设置执行权限。

chmod 777 reggieStart.sh

调用sh脚本即可。

通过↓

ps -ef | grep java # 查看进程信息。

猜你喜欢

转载自blog.csdn.net/qq_55071342/article/details/124808546