ETest-Vue-FastAPI/deploy-manual.sh

127 lines
3.3 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
# ETest-LIMS 手动部署脚本(非 Docker 方式)
# 适用于:前端用系统 Nginx后端用 Docker
set -e
echo "========================================"
echo "ETest-LIMS 手动部署脚本"
echo "========================================"
echo ""
# 配置
BACKEND_DIR="/opt/ETest-Vue-FastAPI/ruoyi-fastapi-backend"
FRONTEND_DIR="/opt/ETest-Vue-FastAPI/ruoyi-fastapi-frontend"
NGINX_ROOT="/var/www/etest-lims"
# 检查是否为 root
if [ "$EUID" -ne 0 ]; then
echo "[!] 请使用 root 权限运行: sudo ./deploy-manual.sh"
exit 1
fi
echo "[*] 开始部署..."
echo ""
# 步骤 1安装依赖
echo "========================================"
echo "Step 1: 安装系统依赖"
echo "========================================"
apt-get update
apt-get install -y nginx docker.io docker-compose nodejs npm
echo "[OK] 依赖安装完成"
echo ""
# 步骤 2构建前端
echo "========================================"
echo "Step 2: 构建前端"
echo "========================================"
cd $FRONTEND_DIR
# 安装依赖
npm install
# 构建生产包
npm run build
# 复制到 Nginx 目录
mkdir -p $NGINX_ROOT
cp -r dist/* $NGINX_ROOT/
echo "[OK] 前端构建完成"
echo ""
# 步骤 3配置 Nginx
echo "========================================"
echo "Step 3: 配置 Nginx"
echo "========================================"
# 备份原配置
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak 2>/dev/null || true
# 复制新配置
cp /opt/ETest-Vue-FastAPI/nginx-manual.conf /etc/nginx/sites-available/etest-lims
# 启用配置
ln -sf /etc/nginx/sites-available/etest-lims /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-enabled/default 2>/dev/null || true
# 测试配置
nginx -t
# 重启 Nginx
systemctl restart nginx
systemctl enable nginx
echo "[OK] Nginx 配置完成"
echo ""
# 步骤 4启动后端Docker
echo "========================================"
echo "Step 4: 启动后端服务"
echo "========================================"
cd /opt/ETest-Vue-FastAPI
# 只启动 MySQL、Redis 和后端
docker-compose -f docker-compose-aliyun.yml up -d mysql redis backend
echo "[OK] 后端服务启动完成"
echo ""
# 步骤 5验证部署
echo "========================================"
echo "Step 5: 验证部署"
echo "========================================"
sleep 5
# 检查服务状态
echo "[*] Docker 容器状态:"
docker-compose -f docker-compose-aliyun.yml ps
echo ""
echo "[*] Nginx 状态:"
systemctl status nginx --no-pager | head -5
echo ""
echo "========================================"
echo "部署完成!"
echo "========================================"
echo ""
echo "访问地址:"
echo " - 前端: http://$(curl -s ifconfig.me)"
echo " - 后端 API: http://$(curl -s ifconfig.me):9099"
echo " - API 文档: http://$(curl -s ifconfig.me):9099/docs"
echo ""
echo "文件位置:"
echo " - 前端文件: $NGINX_ROOT"
echo " - Nginx 配置: /etc/nginx/sites-available/etest-lims"
echo " - 后端代码: $BACKEND_DIR"
echo ""
echo "常用命令:"
echo " - 查看后端日志: docker-compose -f docker-compose-aliyun.yml logs -f backend"
echo " - 重启后端: docker-compose -f docker-compose-aliyun.yml restart backend"
echo " - 重启 Nginx: systemctl restart nginx"
echo " - 查看 Nginx 日志: tail -f /var/log/nginx/access.log"
echo ""