Files
stock/stock-html/deploy/deploy-to-new-server.sh
T
freedakgmail 9c7d7abdd4 Initial commit
2026-07-17 18:49:35 +08:00

74 lines
2.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 一键部署脚本 - 从本地部署到新服务器 152.136.182.184 (stock.allbyai.cn)
# 在本地执行此脚本
set -e
# 配置
NEW_SERVER="ubuntu@152.136.182.184"
APP_DIR="/opt/stock-app"
LOCAL_DIR="/Users/freedak/Documents/go-new/stock/stock-html"
echo "=========================================="
echo "部署到新服务器: 152.136.182.184"
echo "域名: stock.allbyai.cn"
echo "=========================================="
# 1. 同步代码(使用 sudo 写入 /opt/stock-app
echo "[1/5] 同步代码到服务器..."
rsync -avz --progress --rsync-path="sudo rsync" ${LOCAL_DIR}/ ${NEW_SERVER}:${APP_DIR}/ \
--exclude='.git' \
--exclude='venv' \
--exclude='__pycache__' \
--exclude='stock_data_cache' \
--exclude='*.pyc' \
--exclude='.DS_Store' \
--exclude='stock_names.json' \
--exclude='alerts_cache.json' \
--exclude='trades.json' \
--exclude='watchlist.json' \
--exclude='*.log' \
--exclude='.playwright-mcp' \
--exclude='/app.js' \
--exclude='/index.html' \
--exclude='/main.css' \
--exclude='/css' \
--exclude='/js' \
--exclude='/.windsurfrules'
# 2. 在服务器上执行初始化(首次部署时需要)
echo "[2/5] 执行服务器初始化..."
ssh ${NEW_SERVER} "sudo chmod +x ${APP_DIR}/deploy/setup-server.sh"
# 如果是首次部署,取消下行注释
# ssh ${NEW_SERVER} "sudo ${APP_DIR}/deploy/setup-server.sh"
# 3. 配置Nginx
echo "[3/5] 配置Nginx..."
ssh ${NEW_SERVER} "sudo cp ${APP_DIR}/deploy/nginx-stock.conf /etc/nginx/sites-available/stock.allbyai.cn"
ssh ${NEW_SERVER} "sudo ln -sf /etc/nginx/sites-available/stock.allbyai.cn /etc/nginx/sites-enabled/"
ssh ${NEW_SERVER} "sudo nginx -t && sudo systemctl reload nginx"
# 4. 重启服务
echo "[4/5] 重启应用服务..."
ssh ${NEW_SERVER} "sudo systemctl restart stock-app"
ssh ${NEW_SERVER} "sudo systemctl restart stock-data-service"
# 5. 检查状态
echo "[5/5] 检查服务状态..."
ssh ${NEW_SERVER} "sudo systemctl status stock-app --no-pager"
echo ""
echo "=========================================="
echo "部署完成!"
echo ""
echo "访问地址:"
echo " - IP直连: http://152.136.182.184:3333"
echo " - HTTPS访问: https://stock.allbyai.cn"
echo ""
echo "SSL证书信息:"
echo " - 证书路径: /etc/nginx/ssl/stock.allbyai.cn.crt"
echo " - 密钥路径: /etc/nginx/ssl/stock.allbyai.cn.key"
echo " - 自动续期: 已配置 (acme.sh cron)"
echo " - 手动续期: /home/ubuntu/.acme.sh/acme.sh --renew -d stock.allbyai.cn --ecc --force"
echo "=========================================="