【OpenClaw 架构解析 09】部署模式:从桌面到 Docker 的全场景覆盖
·
前言
OpenClaw 支持多种部署模式,无论是个人开发者还是企业用户,都能找到适合自己的部署方式。本文将详细介绍各种部署模式及其适用场景。
1. 部署模式概览
┌─────────────────────────────────────────────────────────────────┐
│ OpenClaw 部署模式 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 本地桌面模式 │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────┐ │ │
│ │ │ │ │ │
│ │ │ OpenClaw Desktop App │ │ │
│ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │
│ │ │ │ CLI │ │ Menu │ │ Tray │ │ │ │
│ │ │ │ │ │ Bar │ │ Icon │ │ │ │
│ │ │ └─────────┘ └─────────┘ └─────────┘ │ │ │
│ │ │ │ │ │
│ │ │ ┌───────────────────────────────────────┐ │ │ │
│ │ │ │ Local Gateway │ │ │ │
│ │ │ └───────────────────────────────────────┘ │ │ │
│ │ │ │ │ │
│ │ └─────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ 适用: 个人用户、开箱即用 │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 服务器模式 │ │
│ │ │ │
│ │ ┌─────────────────────────────┐ │ │
│ │ │ Nginx / Caddy │ │ │
│ │ │ (反向代理) │ │ │
│ │ └─────────────┬───────────────┘ │ │
│ │ │ │ │
│ │ ┌─────────────▼───────────────┐ │ │
│ │ │ Gateway │ │ │
│ │ │ (Docker/直接运行) │ │ │
│ │ └─────────────┬───────────────┘ │ │
│ │ │ │ │
│ │ ┌─────────────▼───────────────┐ │ │
│ │ │ Plugin Extensions │ │ │
│ │ └─────────────┬───────────────┘ │ │
│ │ │ │ │
│ │ ┌─────────────▼───────────────┐ │ │
│ │ │ Database │ │ │
│ │ │ SQLite / PostgreSQL │ │ │
│ │ └─────────────────────────────┘ │ │
│ │ │ │
│ │ 适用: 团队协作、企业部署 │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 移动端模式 │ │
│ │ │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ iOS │ │ macOS │ │ Android │ │ │
│ │ │ Swift │ │ Swift │ │ Kotlin │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ │ │
│ │ │ │
│ │ 适用: 移动办公、随身助理 │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
2. 本地桌面模式
2.1 架构
┌─────────────────────────────────────────────────────────────────┐
│ 本地桌面模式架构 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 系统托盘 / 菜单栏 │ │
│ │ │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ 状态 │ │ 快捷菜单 │ │ 消息 │ │ 设置 │ │ │
│ │ │ 指示 │ │ │ │ 通知 │ │ │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ OpenClaw Core │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────┐ │ │
│ │ │ Gateway │ │ │
│ │ │ │ │ │
│ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │
│ │ │ │ Chat │ │ Cron │ │ Control │ │ │ │
│ │ │ │ Server │ │ Server │ │ UI │ │ │ │
│ │ │ └─────────┘ └─────────┘ └─────────┘ │ │ │
│ │ │ │ │ │
│ │ └─────────────────────────────────────────────────┘ │ │
│ │ │ │ │
│ │ ┌──────────────────────────┼──────────────────────┐ │ │
│ │ │ │ │ │ │
│ │ ▼ ▼ ▼ │ │
│ │ ┌───────┐ ┌───────┐ ┌───────┐│ │
│ │ │Agents │ │Channels│ │Plugins││ │
│ │ │(AI大脑)│ │(渠道) │ │(插件) ││ │
│ │ └───────┘ └───────┘ └───────┘│ │
│ │ │ │
│ └──────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 本地存储 │ │
│ │ │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────────────────────┐│ │
│ │ │ Session │ │ Memory │ │ Config ││ │
│ │ │ SQLite │ │ LanceDB │ │ openclaw.yaml ││ │
│ │ └─────────┘ └─────────┘ └─────────────────────────┘│ │
│ │ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
│ 🔒 数据完全存储在本地,不上传任何服务器 │
│ │
└─────────────────────────────────────────────────────────────────┘
3. 服务器模式
3.1 Docker 部署
# docker-compose.yml
version: '3.8'
services:
openclaw:
image: openclaw/openclaw:latest
container_name: openclaw
restart: unless-stopped
ports:
- "18789:18789" # Gateway 端口
- "18790:18790" # Control UI 端口
volumes:
- ./data:/data # 数据目录
- ./config:/config # 配置目录
- ./plugins:/plugins # 插件目录
environment:
- OPENCLAW_CONFIG=/data/config.yaml
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
- OPENAI_API_KEY=${OPENAI_API_KEY}
networks:
- openclaw-network
# 可选: PostgreSQL 数据库
postgres:
image: postgres:15-alpine
container_name: openclaw-db
restart: unless-stopped
environment:
- POSTGRES_DB=openclaw
- POSTGRES_USER=openclaw
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- openclaw-network
networks:
openclaw-network:
driver: bridge
volumes:
pgdata:
3.2 反向代理配置
# Nginx 反向代理配置
upstream openclaw_gateway {
server 127.0.0.1:18789;
}
upstream openclaw_control {
server 127.0.0.1:18790;
}
server {
listen 443 ssl http2;
server_name openclaw.example.com;
ssl_certificate /etc/ssl/certs/openclaw.crt;
ssl_certificate_key /etc/ssl/private/openclaw.key;
# Gateway API
location /api/ {
proxy_pass http://openclaw_gateway;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
}
# Control UI
location / {
proxy_pass http://openclaw_control;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
}
# WebSocket 支持
location /ws {
proxy_pass http://openclaw_gateway;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
4. 移动端部署
4.1 iOS/macOS 应用
┌─────────────────────────────────────────────────────────────────┐
│ iOS/macOS 架构 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Swift UI │ │
│ │ │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ 聊天 │ │ 会话 │ │ 设置 │ │ 技能 │ │ │
│ │ │ 界面 │ │ 列表 │ │ 页面 │ │ 管理 │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ OpenClaw SDK │ │
│ │ │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ 网络层 │ │ 存储 │ │ 安全 │ │ │
│ │ │ Network │ │ Storage │ │ Security│ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ │ │
│ │ │ │
│ │ ┌───────────────────────────────────────────────┐ │ │
│ │ │ ACP Client (Agent Communication) │ │ │
│ │ └───────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 与 Gateway 通信 │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────┐ │ │
│ │ │ WebSocket / HTTPS + Token Auth │ │ │
│ │ └─────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
5. 环境变量配置
# 环境变量配置
# AI 模型
ANTHROPIC_API_KEY=sk-ant-xxxxx
OPENAI_API_KEY=sk-xxxxx
GOOGLE_API_KEY=xxxxx
# 数据库
DATABASE_URL=postgresql://user:pass@host:5432/openclaw
# 安全
OPENCLAW_SECRET=your-secret-key
JWT_SECRET=your-jwt-secret
# 日志
LOG_LEVEL=info
LOG_FORMAT=json
# 端口
GATEWAY_PORT=18789
CONTROL_PORT=18790
# 存储
DATA_DIR=/data
PLUGINS_DIR=/plugins
6. 部署检查清单
┌─────────────────────────────────────────────────────────────────┐
│ 部署检查清单 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ✅ 基础设施 │
│ □ Node.js >= 22.12 已安装 │
│ □ 端口 18789, 18790 可用 │
│ □ 磁盘空间充足 (建议 >= 10GB) │
│ □ 内存充足 (建议 >= 2GB) │
│ │
│ ✅ 安全配置 │
│ □ API Keys 已配置 │
│ □ TLS/SSL 证书已配置 │
│ □ 防火墙规则已设置 │
│ □ 备份策略已配置 │
│ │
│ ✅ 消息平台 │
│ □ Telegram Bot Token 已配置 │
│ □ Discord Bot Token 已配置 │
│ □ 其他平台凭证已配置 │
│ │
│ ✅ 监控运维 │
│ □ 日志收集已配置 │
│ □ 监控告警已配置 │
│ □ 健康检查已配置 │
│ │
└─────────────────────────────────────────────────────────────────┘
7. 本章小结
┌─────────────────────────────────────────────────────────────────┐
│ 本章要点 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 📱 部署模式 │
│ ├── 本地桌面: 开箱即用,数据本地存储 │
│ ├── 服务器模式: Docker + 反向代理,适合企业 │
│ └── 移动端: iOS/macOS/Android,原生体验 │
│ │
│ 🐳 Docker 部署 │
│ ├── docker-compose 一键部署 │
│ ├── 支持 PostgreSQL │
│ └── 反向代理配置示例 │
│ │
│ ✅ 部署检查 │
│ └── 基础设施 → 安全配置 → 消息平台 → 监控运维 │
│ │
└─────────────────────────────────────────────────────────────────┘
系列导航
| 章节 | 标题 | 状态 |
|---|---|---|
| 01 | OpenClaw 是什么? | ✅ 已发布 |
| 02 | 系统架构全景图 | ✅ 已发布 |
| 03 | Gateway 网关层 | ✅ 已发布 |
| 04 | Agents 模块 | ✅ 已发布 |
| 05 | Channels 消息渠道 | ✅ 已发布 |
| 06 | Plugins 插件系统 | ✅ 已发布 |
| 07 | 数据流设计 | ✅ 已发布 |
| 08 | 安全模型 | ✅ 已发布 |
| 09 | 部署模式(本文) | ✅ 已发布 |
| 10 | 扩展机制 | 🔜 下一章 |
| … | … | … |
如有问题欢迎在评论区留言!
更多推荐
所有评论(0)