02 - 部署架构

部署拓扑 (ASCII 图)

┌─────────────────────────────────────────────────────────────────────┐
│                        校内 GBU 网络环境                              │
│                                                                       │
│  ┌──────────────┐       ┌────────────────┐                           │
│  │ 运维浏览器     │──HTTP─→│  Frontend       │                           │
│  │ (admin role) │  3002 │  Vite dev /     │                           │
│  └──────────────┘       │  Vue 3 SPA      │                           │
│        ↑                └────────┬───────┘                           │
│        │ HMR/static reload       │                                    │
│        │                         │ axios POST /api/v1/log-assistant/* │
│        │                         ↓                                    │
│  ┌─────┴────────────────────────────────────────────────────┐       │
│  │  Backend Flask (port 5000)                                │       │
│  │  ┌────────────────────────────────────────────────────┐  │       │
│  │  │ 51 API routes / log_assistant_api.py 主入口         │  │       │
│  │  │   - /dns/resolver-chain-triage  (A)                │  │       │
│  │  │   - /ai/multiround-triage       (B, D)             │  │       │
│  │  │   - /dhcp/ai-tool-triage        (C)                │  │       │
│  │  │   - /clue/diagnose              (按线索)            │  │       │
│  │  │   - /alerts /feedback /audit / ...                 │  │       │
│  │  └────────────────────────────────────────────────────┘  │       │
│  │  ┌──────────────┐   ┌──────────────┐   ┌──────────────┐ │       │
│  │  │ tool_        │   │ hypothesis_  │   │ business_    │ │       │
│  │  │ orchestrator │──→│ reasoner +   │──→│ impact_      │ │       │
│  │  │ (14 工具)     │   │ dhcp variant │   │ estimator    │ │       │
│  │  └──────┬───────┘   └──────┬───────┘   └──────┬───────┘ │       │
│  │         │                  │                  │          │       │
│  │         ↓                  ↓                  ↓          │       │
│  │  ┌──────────────────────────────────────────────────┐    │       │
│  │  │  invariants / sanitizers / safety guards         │    │       │
│  │  │  - report_status_invariants (15+ 守门)            │    │       │
│  │  │  - sanitize (输出禁敏感字面)                       │    │       │
│  │  │  - safety_flags 三旗物理禁                        │    │       │
│  │  └──────────────────────────────────────────────────┘    │       │
│  └────┬────────────────┬───────────────────────┬───────────┘       │
│       │                │                       │                    │
│       ↓ ES DSL         ↓ HTTP                  ↓ 读 yaml             │
│  ┌─────────┐    ┌──────────────────┐    ┌────────────────────┐     │
│  │ ES 集群  │    │ 本地 LLM (主)     │    │ asset_registry.yaml│     │
│  │ :9200   │    │ Qwen 等 校内部署 │←┐  │ 12 业务系统真值     │     │
│  │ via VPN │    │                  │ │  │ servers.demo.json  │     │
│  │         │    └──────────────────┘ │  │ topology.json       │     │
│  │ index:  │                          │  └────────────────────┘     │
│  │ dns-    │                          │ fallback                    │
│  │ dnstap* │    ┌──────────────────┐ │                              │
│  │ syslog- │    │ DeepSeek API     │─┘                              │
│  │ bras*   │    │ v4-flash/v4-pro  │                                │
│  │ iaaa_*  │    │ (云端 fallback)   │                                │
│  └─────────┘    └──────────────────┘                                │
└─────────────────────────────────────────────────────────────────────┘

组件清单

Backend (Python 3.10+ Flask)

组件 路径 行数 职责
API 入口 workspace/system_monitor/backend/api/log_assistant_api.py 2600+ 51 个 HTTP route + dispatch 各 endpoint
Assistant 业务模块 workspace/system_monitor/backend/assistant/*.py ~60 文件 14 工具 + 2 reasoner + clue_diagnostics + invariants + sanitizers
Tool orchestrator workspace/system_monitor/backend/assistant/tool_orchestrator/ ~10 文件 multiround agent + plan validator + tool registry (DNS/DHCP)
Asset registry workspace/system_monitor/backend/assistant/asset_registry*.py ~3 文件 yaml + ES 多源 merge 出 12 业务系统 + 21 subnet + 21 resolvers
Sanitizer workspace/system_monitor/scripts/sanitize_fixture.py ~250 行 真后端 fixture 入库前脱敏真生产域名/IP/MAC
Plugin (元工程) .claude-plugins/monitor-phase-workflow/ ~180 行 phase-prompt-guard 5 检查 (本项目专用, 不入全局)

Frontend (Node 18+ Vue 3 Vite)

组件 路径 职责
Vue 3 SPA workspace/system_monitor/frontend/ 58 文件 用户 UI, 单页应用
主组件 LogAssistant frontend/src/components/logAssistant/ ~30 .vue 告警队列, 报告卡, 反馈按钮, 按线索输入
API client frontend/src/api/index.js ~1200 行 axios 包装 51 个 backend API
Vite npm run dev (port 3002) dev server HMR
Vite build npm run build 生产打包 (chunk-size warning 已知, 不阻塞)

Database (SQLite, 本地)

DB 路径 真用途
主 DB workspace/system_monitor/backend/diagnose/database/monitor.db 告警队列 / 反馈记录 / audit log / 网络设备表
临时 DB /tmp/claude-1000/tmpXXXX/monitor.db 单测真跑 (mtime 后即清)

真后端 fixture (历史回归基础)

目录 真值 用途
workspace/system_monitor/test_backup/fixtures_real_backend/ 35 个 R29-R37 JSON 主动发现路径回归
workspace/system_monitor/test_backup/fixtures_real_backend_clue/ 10 个 R1-R5 clue JSON 按线索路径回归
raw_* 前缀 gitignored 脱敏前真值, 入库前删

端口表 (生产部署必填)

服务 默认端口 真用 ENV 改 用途
Backend Flask 5000 (硬码, 改要动 backend/app.py) HTTP API
Frontend Vite (dev) 3002 frontend/vite.config.js 开发用 SPA, 生产改 nginx 静态托管
Elasticsearch 9200 OPENCLAW_ES_URL (default http://10.10.1.147:9200) ES DSL 查询
本地 LLM (Qwen 等) [本地部署 url, e.g. http://10.10.x.x:8000] OPENCLAW_LOCAL_URL LLM 主推理
DeepSeek API HTTPS 443 OPENCLAW_DEEPSEEK_URL=https://api.deepseek.com LLM fallback

网络要求

流量方向 端口 协议 必须放通
运维浏览器 → Frontend 3002 HTTP 校内
Frontend → Backend 5000 HTTP 同机 / 校内
Backend → ES 9200 HTTP 跨校内 VPN, 见下文
Backend → 本地 LLM [本地端口] HTTP 校内, 同机房
Backend → DeepSeek API 443 HTTPS 必须出公网 (本地 LLM 挂时 fallback 救命)

ES 跨 VPN 真值: 一些校内部署 ES 在另一个网段, 需 vpn.gbu.edu.cn SSL VPN. 测试时 curl http://10.10.1.147:9200/_cluster/health 真过才证明 backend 能连通.

数据卷 (生产部署必规划)

数据 路径 真大小估 备份周期
Backend SQLite backend/diagnose/database/monitor.db 100 MB+ (告警 + 反馈累积) 每天
Backend logs workspace/system_monitor/logs/backend-verify.log 1 GB+ / 月 (LLM 调用 + tool 调用 trace) 每周 rotate
asset_registry yaml backend/assistant/asset_registry.yaml 100 KB 修改时 commit git
真后端 fixture test_backup/fixtures_real_backend*/ 50 MB+ (35 主 + 5 clue + 试用累积) 入 git, 自动
.env.local (机密) workspace/system_monitor/.env.local <1 KB 绝不入 git, 单独保管

部署模式

当前: 单机演示模式 (试用阶段)

┌──────────────────────────┐
│ 学生 / 助手开发机        │
│ (Linux Ubuntu 22.04)     │
│                          │
│ - Backend Flask :5000    │
│ - Frontend Vite :3002    │
│ - SQLite (本地文件)      │
│ - 通过 SSL VPN 连远端 ES │
│                          │
│ 用户从浏览器访问 :3002  │
└──────────────────────────┘

适合: 试用 / demo / 课程项目.

不适合: 7×24 生产 (Flask dev server 单进程, 没 systemd 守护, 没负载均衡).

推荐生产部署模式 (未来转生产时)

┌──────────┐    ┌─────────────┐    ┌──────────┐
│ 运维浏览器│───→│ nginx :443  │───→│ Flask    │
│          │    │ (静态 SPA + │    │ gunicorn │
└──────────┘    │  反代 :5000)│    │ :5000    │
                └─────────────┘    │ × 4 workers│
                                    └─────┬────┘
                                          │
                                    ┌─────┴────┐
                                    │ systemd  │
                                    │ 守护进程  │
                                    └──────────┘

升级路径:

  1. npm run builddist/, 用 nginx 静态托管 (/var/www/log-assistant/)
  2. Flask 用 gunicorn -w 4 -b 0.0.0.0:5000 app:app 替代 python backend/app.py
  3. systemd unit 文件守护 backend + nginx
  4. SQLite → PostgreSQL (告警量大时)
  5. HTTPS via nginx + Let’s Encrypt

详见 04-deployment.md §生产部署.

安全边界 (物理禁止)

3 旗硬码在每个 API response 顶层:

SAFETY_FLAGS = {
    "raw_log_scan": False,    # 不直读 ES raw 日志, 只看聚合
    "preview_only": True,     # 所有建议只是预览
    "execution_enabled": False, # 物理禁运维变更
}

任何 backend 改不允许动这 3 旗 (feedback_bitter_lessons_r10_r37 红线 2). 单测 + invariant 双守 (test_phase*_safety.py 系列 + report_status_invariants.py 验出口字段).

详见 03-data-flow.md §安全旗位.

跨模块依赖图

clue_diagnostics
  ├─ clue_parser_v2 (LLM 抽时间窗 + 真凶)
  ├─ clue_qa_planner (15 步 deterministic plan)
  ├─ clue_template_planner
  ├─ dns_diagnostics → dns_report_v2 → dns_failure_drilldown
  ├─ dhcp_diagnostics → dhcp_report_v2 → dhcp_failure_drilldown
  └─ live_query_guard (LIVE_MAX_WINDOW + ALLOW_WIDE_WINDOW)

tool_orchestrator
  ├─ multiround_agent (3 round × 8 tool envelope)
  ├─ dns_tool_registry (8 DNS 工具)
  ├─ dhcp_tool_registry (6 DHCP 工具)
  ├─ tool_plan_validator (LLM plan 校验)
  ├─ agent_stop_policy (sufficient_evidence 早停)
  └─ plan_trace (model/deterministic_seed 出处审计)

hypothesis_reasoner (DNS) + dhcp_hypothesis_reasoner
  ├─ asset_registry → asset_registry_builder (yaml + 多 ES 源 merge)
  ├─ business_impact_estimator + dhcp_business_impact_estimator
  └─ hypothesis_reasoner_schema (输出 schema 强校验)

invariants (出口守门)
  ├─ report_status_invariants (15+ 条)
  ├─ cross_protocol_report_builder
  └─ degraded_reason 推断

修任何 backend .py 前先看依赖图. 红线 6: 不动 phase68.A-F / phase69.A-F 已落改动任何字符 (详见 07-extension §改 backend SOP).


下一步: 03-data-flow.md (4 endpoint × 3 段输出详 + LLM 调用链)