Add interactive deploy manager with install, uninstall, and update menus.
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>
This commit is contained in:
+90
-31
@@ -1,51 +1,117 @@
|
||||
# 环境一键部署(Ubuntu / root /opt)
|
||||
|
||||
在 **`/opt/crypto_monitor`** 下以 **root** 为各子项目创建 Python **`.venv`**,安装依赖,从 `.env.example` 生成 `.env`(不覆盖已有),并可选安装 **PM2**.
|
||||
在 **`/opt/crypto_monitor`** 下以 **root** 部署三所 Flask + 中控 hub/agent,使用 **PM2** 常驻.
|
||||
|
||||
完整系统要求(Python / Node / PM2 版本,启动顺序)见 **[docs/ubuntu-server.md](../docs/ubuntu-server.md)**.
|
||||
完整系统要求见 **[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**,仓库位于 **`/opt/crypto_monitor`**
|
||||
|
||||
```bash
|
||||
apt update
|
||||
apt install -y python3 python3-pip python3-venv curl git ca-certificates
|
||||
# Node 20 + PM2 见 docs/ubuntu-server.md §3
|
||||
```
|
||||
- 能 `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
|
||||
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`,清库,去脏 PM2)见 **[reinstall-plan-b.md](./reinstall-plan-b.md)**,执行 `bash deploy/reinstall.sh`.与 `setup_env.sh` 独立,不影响首次一键安装.
|
||||
**整目录重装**(保留 `.env`,清库)见 **[reinstall-plan-b.md](./reinstall-plan-b.md)**:
|
||||
|
||||
```bash
|
||||
bash deploy/reinstall.sh --yes
|
||||
```
|
||||
|
||||
若在其它环境编辑过脚本后报 `pipefail` 错误,先转 LF:
|
||||
|
||||
```bash
|
||||
sed -i 's/\r$//' deploy/setup_env.sh
|
||||
sed -i 's/\r$//' deploy/manage.sh deploy/lib/*.sh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 脚本会做什么
|
||||
## setup_env.sh 会做什么
|
||||
|
||||
| 步骤 | 说明 |
|
||||
|------|------|
|
||||
@@ -59,21 +125,14 @@ sed -i 's/\r$//' deploy/setup_env.sh
|
||||
|
||||
---
|
||||
|
||||
## 部署之后
|
||||
## 环境变量(可选)
|
||||
|
||||
1. 编辑各子目录 **`.env`**(交易所 API,企业微信等;**AI 请在中控系统设置 → AI 配置**).
|
||||
2. **仅用 PM2 常驻**(见 [docs/ubuntu-server.md](../docs/ubuntu-server.md) §3):
|
||||
|
||||
```bash
|
||||
cd /opt/crypto_monitor/crypto_monitor_binance && pm2 start ecosystem.config.cjs
|
||||
# … 其余三所 …
|
||||
cd /opt/crypto_monitor/manual_trading_hub && pm2 start ecosystem.config.cjs
|
||||
pm2 save
|
||||
```
|
||||
|
||||
或一条命令:`bash deploy/pm2_start_all.sh`
|
||||
|
||||
3. 三所 `.env` 同步脚本见 **[docs/env-sync-scripts.md](../docs/env-sync-scripts.md)**.
|
||||
```bash
|
||||
INSTALL_ROOT=/opt/crypto_monitor
|
||||
GIT_URL=https://git.bz121.com/dekun/crypto_monitor.git
|
||||
GIT_BRANCH=main
|
||||
BACKUP_ROOT=/root/backups
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user