Files
crypto_monitor_user/deploy/README.md
T
dekun af0fbc3e6f docs: require Python 3.10 for obfuscated lib; prefer Ubuntu 22.04
Reject 3.12+ in setup_env to avoid bad marshal data on new servers.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-18 12:15:21 +08:00

154 lines
4.8 KiB
Markdown
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.
# 环境一键部署(Ubuntu / root /opt)
**`/opt/crypto_monitor_user`** 下以 **root** 部署三所 Flask + 中控 hub/agent,使用 **PM2** 常驻.
完整系统要求见 **[docs/ubuntu-server.md](../docs/ubuntu-server.md)**.
---
## 一键部署管理器(推荐)
新服务器**无需先 clone**,一条命令进入菜单:
```bash
curl -fsSL https://git.bz121.com/dekun/crypto_monitor_user/raw/branch/main/deploy/manage.sh | bash
```
已安装机器:
```bash
bash /opt/crypto_monitor_user/deploy/manage.sh
```
### 菜单
| 选项 | 功能 |
|------|------|
| **1) 一键部署(全套)** | 装系统依赖 + Node/PM2 + venv + 自动生成密钥 + 启动 7 进程(三所+中控) |
| **4) 仅 OKX 实例** | 只部署/启动 `crypto_okx`(不含中控/agent) |
| **5) 仅 Binance 实例** | 只部署/启动 `crypto_binance` |
| **6) 仅 Gate 实例** | 只部署/启动 `crypto_gate` |
| **2) 一键卸载** | 备份 `.env` / `hub_settings.json` → 停 PM2 → 移走目录 |
| **3) 更新** | 快速更新 / 依赖更新 / 深度重装 |
| **0) 退出** | |
单所模式仍 clone 整仓到 `/opt/crypto_monitor_user`(共用 `lib/`),但 `setup_env.sh --only <所>` 只建该所 venv,且 PM2 只起对应 Flask.
### 部署完成后
脚本自动验收(PM2 7 进程 + 页面可访问),并提示:
- 登录账号: **admin**
- 登录密码: **admin123**
- **三所实例与中控均默认需要登录**( `APP_AUTH_DISABLED=false` )
- 浏览器配置: 各所 **env 配置**(API,风控) + 中控 **系统设置**
**无需 SSH 编辑 `.env` 填 API**;密钥由 `bootstrap_deploy_secrets.py` 自动生成.
| 地址 | 端口 |
|------|------|
| 中控 | 5100 |
| Binance | 5001 |
| Gate | 5000 |
| OKX | 5004 |
agent 默认 `127.0.0.1:15200/15201/15202`,由代码内置,一般无需改.
---
## 脚本结构
```
deploy/
├── manage.sh # 入口(自举 + 菜单)
├── lib/
│ ├── common.sh # 公共函数,验收
│ ├── install.sh # 一键部署
│ ├── uninstall.sh # 一键卸载
│ └── update.sh # 更新子菜单
├── setup_env.sh # venv + 依赖(被 install 调用)
├── pm2_start_all.sh # 启动 7 进程
├── pull_and_restart.sh # 快速更新(被 update 调用)
└── reinstall.sh # 深度重装(被 update 调用)
```
---
## 前置条件
- **优先 Ubuntu 22.04**(自带 Python 3.10);24.04 须另装 **python3.10**,不可用系统 3.12
- 用户 **root**
-`git clone` 仓库到 `/opt/crypto_monitor_user`
- 详见 **[docs/ubuntu-server.md](../docs/ubuntu-server.md)**(含 `bad marshal data` 说明)
---
## 分步安装(仍可用)
若不使用 `manage.sh`,可手动:
```bash
cd /opt
git clone https://git.bz121.com/dekun/crypto_monitor_user.git crypto_monitor_user
cd /opt/crypto_monitor_user
bash deploy/setup_env.sh --install-system-deps
bash deploy/pm2_start_all.sh
pm2 save && pm2 startup
```
`setup_env.sh` 常用参数:
```bash
bash deploy/setup_env.sh --only binance,gate # 仅部分子项目
bash deploy/setup_env.sh --recreate-venv # 重建虚拟环境
bash deploy/setup_env.sh --skip-pm2 # 不尝试安装 pm2
bash deploy/setup_env.sh --skip-env-copy # 不复制 .env.example
```
**整目录重装**(保留 `.env`,清库)见 **[reinstall-plan-b.md](./reinstall-plan-b.md)**:
```bash
bash deploy/reinstall.sh --yes
```
若在其它环境编辑过脚本后报 `pipefail` 错误,先转 LF:
```bash
sed -i 's/\r$//' deploy/manage.sh deploy/lib/*.sh
```
---
## setup_env.sh 会做什么
| 步骤 | 说明 |
|------|------|
| 检查 Python | **仅 3.10 / 3.11**(推荐 3.10);优先 `python3.10`;**拒绝 3.12+** |
| `crypto_monitor_*` | 各目录 `.venv` + `pip install -r ../requirements.txt` |
| `manual_trading_hub` | 独立 `requirements.txt` |
| `.env` | 不存在则从 `.env.example` 复制 |
| 部署密钥 | `python3 scripts/bootstrap_deploy_secrets.py`(不覆盖已有值) |
| 目录 | `static/images`,`static/images/order_charts` |
| PM2 | 已装 Node 时 `npm install -g pm2` |
---
## 环境变量(可选)
```bash
INSTALL_ROOT=/opt/crypto_monitor_user
GIT_URL=https://git.bz121.com/dekun/crypto_monitor_user.git
GIT_BRANCH=main
BACKUP_ROOT=/root/backups
```
---
## 依赖说明
- 三个监控子项目共用根目录 **[requirements.txt](../requirements.txt)**.
- 走 SOCKS 须 **PySocks**(已包含在 requirements 中).
- **用户版核心包**`lib/strategy` 等)为加密发行;本地开发若需重新加密,见 `scripts/obfuscate_release.py`
- **加密包与 Python 版本绑定**:当前发行包按 **Python 3.10** 编译。用 3.12 启动会报 `ValueError: bad marshal data (unknown type code)`。新服务器请用 **Ubuntu 22.04**,或在 24.04 上安装 `python3.10` 后再跑 `setup_env.sh`
- **授权**:配置仓库根 `license.env`(见 `license.env.example`),对接 [https://sq.bz121.com/](https://sq.bz121.com/)。