Files
crypto_key/DEPLOY.md
T
dekun 83fd9c1fd9 feat: image lightbox and curl|bash Ubuntu deploy
Add click-to-zoom for uploaded images, move manage.sh to deploy/ for
curl|bash bootstrap, and remove Windows docs and PowerShell scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 20:43:54 +08:00

212 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.
# 部署文档 — crypto_keyUbuntu
> 仓库:[https://git.bz121.com/dekun/crypto_key](https://git.bz121.com/dekun/crypto_key.git)
> 部署路径:**`/opt/crypto_key`**
> 进程守护:**PM2** · 端口:**5200**
> **代码更新一律使用 `git pull`,严禁 scp**
---
## 一、架构说明
```
浏览器(本机 / 局域网)
→ http://<IP>:5200
→ PM2 (api-key-manager)
→ venv/python app.py (Flask)
→ .env / data.json / settings.json / uploads/
→ /root/crypto_key_backups/ (每日自动备份)
```
| 文件 | 说明 | 是否提交 Git |
|------|------|----------------|
| `.env` | 登录账号 + 加密主密钥 | 否 |
| `data.json` | 加密凭证库 | 否 |
| `settings.json` | 自定义类型 | 否 |
| `uploads/` | 上传图片 | 否 |
| `venv/` | Python 虚拟环境 | 否 |
---
## 二、环境要求
| 项目 | 要求 |
|------|------|
| 系统 | Ubuntu 20.04 / 22.04 / 24.04 LTS |
| Python | 3.8+ |
| Node.js | 16+PM2 |
| 权限 | root |
| 磁盘 | ≥ 200MB |
---
## 三、一键部署(推荐)
**无需预先 clone**,在 Ubuntu 服务器上执行:
```bash
curl -fsSL https://git.bz121.com/dekun/crypto_key/raw/branch/main/deploy/manage.sh | bash
```
交互菜单:
```
1) 一键部署
2) 更新(git pull,严禁 scp
3) 一键卸载
0) 退出
```
也可传参直接执行:
```bash
curl -fsSL https://git.bz121.com/dekun/crypto_key/raw/branch/main/deploy/manage.sh | bash -s -- deploy
curl -fsSL https://git.bz121.com/dekun/crypto_key/raw/branch/main/deploy/manage.sh | bash -s -- update
```
已安装后本地调用:
```bash
bash /opt/crypto_key/deploy/manage.sh
```
### 部署脚本会做什么
1. 安装 python3 / venv / git / Node / PM2
2. `git clone`**`git pull`** 到 `/opt/crypto_key`
3. 创建 venv、安装依赖
4. 配置每日 03:00 cron 备份到 `/root/crypto_key_backups/`
5. PM2 启动 `api-key-manager`
### 验证
```bash
pm2 status
curl -s http://127.0.0.1:5200/api/auth/status
# {"logged_in":false}
```
浏览器:`http://127.0.0.1:5200``http://<服务器IP>:5200`
默认可能是 `admin` / `admin123`,请尽快修改。
---
## 四、更新升级(仅 git pull
```bash
curl -fsSL https://git.bz121.com/dekun/crypto_key/raw/branch/main/deploy/manage.sh | bash
# 选择 2) 更新
```
或:
```bash
bash /opt/crypto_key/deploy/manage.sh
# 选择 2
```
流程:更新前自动备份 → `git pull` → 安装依赖 → 刷新 cron → 重启 PM2。
**禁止** 使用 scp / rsync 覆盖代码目录。
---
## 五、一键卸载
```bash
bash /opt/crypto_key/deploy/manage.sh
# 选择 3,输入 yes 确认
```
会停止 PM2、移除 cron、删除 `/opt/crypto_key`;卸载前尽量再打一份包到 `/root/crypto_key_backups/`**保留备份目录**。
---
## 六、PM2 运维
| 命令 | 说明 |
|------|------|
| `pm2 status` | 查看状态 |
| `pm2 logs api-key-manager` | 查看日志 |
| `pm2 restart api-key-manager` | 重启 |
| `./pm2-start.sh` | 启动 |
| `./pm2-stop.sh` | 停止 |
---
## 七、备份与恢复
### 自动备份
- 应用内守护线程:每天 **03:00**
- cron:每天 **03:00**
- 目录:`/root/crypto_key_backups/`
- 约保留 30 天
### 前端备份恢复
系统设置 → **备份恢复**:下载备份 / 立即备份 / 上传恢复。
备份内容:`.env``data.json``settings.json``uploads/`
**`.env``DATA_ENCRYPTION_KEY` 必须与备份一致。**
---
## 八、防火墙
```bash
sudo ufw allow from 192.168.0.0/16 to any port 5200 proto tcp
```
切勿将 5200 直接暴露公网。
---
## 九、故障排查
| 现象 | 处理 |
|------|------|
| PM2 `errored` | `pm2 logs api-key-manager --err` |
| 无法登录 | 检查 `.env``AUTH_*` |
| 数据无法解密 | `DATA_ENCRYPTION_KEY` 是否与备份一致 |
| 局域网无法访问 | `ss -tlnp \| grep 5200`;检查 ufw |
| 图片 404 | 确认 `uploads/` 存在 |
---
## 十、目录结构
```
/opt/crypto_key/
├── app.py
├── storage.py
├── backup.py
├── env_config.py
├── index.html
├── requirements.txt
├── ecosystem.config.cjs
├── deploy/
│ └── manage.sh # curl | bash 入口
├── scripts/ # 兼容旧入口
├── uploads/
├── logs/
└── venv/
```
---
## 十一、命令速查
```bash
# 一键(推荐)
curl -fsSL https://git.bz121.com/dekun/crypto_key/raw/branch/main/deploy/manage.sh | bash
# 日常
bash /opt/crypto_key/deploy/manage.sh
pm2 status
pm2 logs api-key-manager --lines 50
```
使用细节请参阅 **[USAGE.md](./USAGE.md)**。