58c9f36a75
Provides curl-friendly manage.sh so production servers can bootstrap without a prior clone, then configure API and risk settings in the browser. Co-authored-by: Cursor <cursoragent@cursor.com>
143 lines
3.6 KiB
Markdown
143 lines
3.6 KiB
Markdown
# 环境一键部署(Ubuntu / root /opt)
|
|
|
|
在 **`/opt/crypto_monitor`** 下以 **root** 部署三所 Flask + 中控 hub/agent,使用 **PM2** 常驻.
|
|
|
|
完整系统要求见 **[docs/ubuntu-server.md](../docs/ubuntu-server.md)**.
|
|
|
|
---
|
|
|
|
## 一键部署管理器(推荐)
|
|
|
|
新服务器**无需先 clone**,一条命令进入菜单:
|
|
|
|
```bash
|
|
curl -fsSL https://git.bz121.com/dekun/crypto_monitor/raw/branch/main/deploy/manage.sh | bash
|
|
```
|
|
|
|
已安装机器:
|
|
|
|
```bash
|
|
bash /opt/crypto_monitor/deploy/manage.sh
|
|
```
|
|
|
|
### 菜单
|
|
|
|
| 选项 | 功能 |
|
|
|------|------|
|
|
| **1) 一键部署** | 装系统依赖 + Node/PM2 + venv + 自动生成密钥 + 启动 7 进程 |
|
|
| **2) 一键卸载** | 备份 `.env` / `hub_settings.json` → 停 PM2 → 移走目录 |
|
|
| **3) 更新** | 快速更新 / 依赖更新 / 深度重装 |
|
|
| **0) 退出** | |
|
|
|
|
### 部署完成后
|
|
|
|
脚本自动验收(PM2 7 进程 + 页面可访问),并提示:
|
|
|
|
- 登录账号: **admin**
|
|
- 登录密码: **admin123**
|
|
- 浏览器配置: 各所 **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 / 24.04**,用户 **root**
|
|
- 能 `git clone` 仓库到 `/opt/crypto_monitor`
|
|
|
|
---
|
|
|
|
## 分步安装(仍可用)
|
|
|
|
若不使用 `manage.sh`,可手动:
|
|
|
|
```bash
|
|
cd /opt
|
|
git clone https://git.bz121.com/dekun/crypto_monitor.git crypto_monitor
|
|
cd /opt/crypto_monitor
|
|
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+** |
|
|
| `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
|
|
GIT_URL=https://git.bz121.com/dekun/crypto_monitor.git
|
|
GIT_BRANCH=main
|
|
BACKUP_ROOT=/root/backups
|
|
```
|
|
|
|
---
|
|
|
|
## 依赖说明
|
|
|
|
- 三个监控子项目共用根目录 **[requirements.txt](../requirements.txt)**.
|
|
- 走 SOCKS 须 **PySocks**(已包含在 requirements 中).
|