Initial commit

This commit is contained in:
freedakgmail
2026-07-17 18:49:07 +08:00
commit 9c7d7abdd4
100 changed files with 41337 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
# 股票投资分析系统 - 远程服务器部署情况
> 最后更新:2026-03-17
## 一、服务器概览
| 服务器 | IP | 域名 | 用途 | 状态 |
|--------|-----|------|------|------|
| **主服务器(原有)** | 43.135.128.39 | - | 腾讯云,IP直连 | 运行中 |
| **新服务器** | 152.136.182.184 | stock.allbyai.cn | 腾讯云,HTTPS域名 | 已配置 |
---
## 二、新服务器 (stock.allbyai.cn) 部署架构
### 2.1 访问方式
- **HTTPS(推荐)**https://stock.allbyai.cn
- **IP直连**http://152.136.182.184:3333
### 2.2 技术栈
- **Web 应用**Flask (Python) 端口 3333
- **反向代理**Nginx + HTTPS (acme.sh 证书)
- **数据库**PostgreSQL (stock_app)
- **数据采集**stock-data-service (systemd 后台服务)
### 2.3 部署路径
- 应用目录:`/opt/stock-app`
- Nginx 配置:`/etc/nginx/sites-available/stock.allbyai.cn`
- SSL 证书:`/etc/nginx/ssl/stock.allbyai.cn.crt` / `.key`
---
## 三、部署脚本清单
| 脚本 | 用途 | 执行位置 |
|------|------|----------|
| `deploy/deploy-to-new-server.sh` | 一键完整部署(同步+初始化+Nginx+重启) | 本地 |
| `deploy/sync-to-new-server.sh` | 快速同步代码并重启(日常更新) | 本地 |
| `deploy/setup-server.sh` | 服务器环境初始化(首次部署) | 服务器 |
| `deploy/setup-ssl.sh` | SSL 证书申请/安装(acme.sh | 服务器 |
| `setup_cron_scan.sh` | 配置全景扫描定时任务 | 本地→服务器 |
---
## 四、部署流程
### 4.1 首次部署新服务器
```bash
cd /Users/freedak/Documents/go-new/stock/stock-html
# 1. 执行一键部署(会同步代码、配置 Nginx、重启服务)
./deploy/deploy-to-new-server.sh
# 2. 首次部署需取消 deploy-to-new-server.sh 第43行注释,执行服务器初始化
# ssh ubuntu@152.136.182.184 "${APP_DIR}/deploy/setup-server.sh"
# 3. 若需 SSL,在服务器上执行
# ssh ubuntu@152.136.182.184
# 先配置 acme.sh + DNS TXT 记录,再运行:
# /opt/stock-app/deploy/setup-ssl.sh
# 4. 配置定时任务(全景扫描、K线采集、资金流向)
./setup_cron_scan.sh
# 或手动指定:STOCK_SERVER=ubuntu@152.136.182.184 STOCK_APP_DIR=/opt/stock-app ./setup_cron_scan.sh
```
### 4.2 日常代码更新
```bash
cd /Users/freedak/Documents/go-new/stock/stock-html
./deploy/sync-to-new-server.sh
```
---
## 五、服务管理命令
### 5.1 新服务器 (152.136.182.184)
```bash
# Web 应用
ssh ubuntu@152.136.182.184 "systemctl start stock-app"
ssh ubuntu@152.136.182.184 "systemctl stop stock-app"
ssh ubuntu@152.136.182.184 "systemctl restart stock-app"
ssh ubuntu@152.136.182.184 "systemctl status stock-app"
# 数据采集服务
ssh ubuntu@152.136.182.184 "systemctl start stock-data-service"
ssh ubuntu@152.136.182.184 "systemctl restart stock-data-service"
ssh ubuntu@152.136.182.184 "systemctl status stock-data-service"
# 查看日志
ssh ubuntu@152.136.182.184 "journalctl -u stock-app -f"
ssh ubuntu@152.136.182.184 "journalctl -u stock-data-service -f"
```
### 5.2 SSL 证书续期
- **自动**acme.sh 已配置 cron 自动续期
- **手动**`/home/ubuntu/.acme.sh/acme.sh --renew -d stock.allbyai.cn --ecc --force`
---
## 六、注意事项与待办
### 6.1 已知差异
- `sync-to-new-server.sh` 仅重启 `stock-app`,不重启 `stock-data-service`
- 完整部署时 `deploy-to-new-server.sh` 会重启两个服务
### 6.2 同步排除项
部署时排除:`.git``venv``__pycache__``stock_data_cache``*.pyc``.DS_Store``stock_names.json``alerts_cache.json``trades.json``watchlist.json``*.log``.playwright-mcp`、根目录 `/app.js``/index.html``/main.css``/css``/js``.windsurfrules`
### 6.3 定时任务(新服务器需单独配置)
- 11:50 午休扫描
- 16:30 收盘扫描
- 17:30 5分钟K线采集
- 18:00 资金流向采集
使用 `setup_cron_scan.sh` 或按 `run.md` 手动配置 crontab。
---
## 七、快速参考
| 操作 | 命令 |
|------|------|
| 同步并重启新服务器 | `./deploy/sync-to-new-server.sh` |
| 完整部署新服务器 | `./deploy/deploy-to-new-server.sh` |
| 查看服务状态 | `ssh ubuntu@152.136.182.184 "systemctl status stock-app stock-data-service"` |
| 访问地址 | https://stock.allbyai.cn |