妙趣导读:2026年4月20日下午3点33分,老板突然说"我们要给全公司200人部署OpenClaw"。那一刻我意识到——个人玩法和企业部署,根本是两个世界。本文教你如何从0到1完成企业级部署。
📋 企业部署架构
🏗️ 推荐架构(中型团队50-200人)
┌──────────────┐
│ 负载均衡 │ (Nginx/HAProxy)
└──────┬───────┘
┌────────────┼────────────┐
▼ ▼ ▼
┌────────┐ ┌────────┐ ┌────────┐
│Gateway │ │Gateway │ │Gateway │ (多实例)
│实例1 │ │实例2 │ │实例3 │
└───┬────┘ └───┬────┘ └───┬────┘
│ │ │
└────────────┼────────────┘
▼
┌──────────┐
│ Redis │ (会话存储)
└──────────┘
▼
┌──────────┐
│PostgreSQL│ (持久化存储)
└──────────┘
🚀 部署步骤
Step 1: 环境准备
# 服务器要求(每个Gateway实例)
- CPU: 4核+
- 内存: 8GB+
- 磁盘: 50GB+ SSD
- OS: Ubuntu 22.04 LTS / CentOS 8+
# 安装Node.js 24+
curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
apt-get install -y nodejs
# 安装OpenClaw
npm install -g openclaw@latest
Step 2: 配置Gateway集群
使用systemd管理多个Gateway实例:
# /etc/systemd/system/openclaw-gateway@.service
[Unit]
Description=OpenClaw Gateway Instance %i
After=network.target
[Service]
Type=simple
User=openclaw
WorkingDirectory=/var/lib/openclaw
ExecStart=/usr/bin/openclaw gateway --port 1878%i --config /etc/openclaw/gateway-%i.json
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
# 启动3个实例
systemctl enable openclaw-gateway@1
systemctl enable openclaw-gateway@2
systemctl enable openclaw-gateway@3
systemctl start openclaw-gateway@{1,2,3}
Step 3: 配置Nginx负载均衡
# /etc/nginx/sites-available/openclaw
upstream openclaw_backend {
least_conn; # 最少连接算法
server 127.0.0.1:18781;
server 127.0.0.1:18782;
server 127.0.0.1:18783;
}
server {
listen 80;
server_name ai.company.com;
location / {
proxy_pass http://openclaw_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket支持
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
🔒 安全配置
⚠️ 企业部署安全检查清单
- ☐ 使用HTTPS(Let's Encrypt免费证书)
- ☐ 配置防火墙,只开放必要端口
- ☐ 启用DM pairing模式,避免陌生人访问
- ☐ 定期更新OpenClaw到最新版本
- ☐ 配置日志审计,记录所有Agent操作
- ☐ 使用Vault或类似工具管理API Key
HTTPS配置示例
# 使用certbot获取免费证书
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d ai.company.com
# 自动续期(已自动配置cron)
# 测试续期:certbot renew --dry-run
📊 监控与告警
✅ 关键监控指标
- Gateway健康 - /health 端点检查
- 响应时间 - Agent平均响应时间
- 错误率 - 4xx/5xx响应比例
- Token消耗 - 每日API调用成本
- 并发用户 - 同时在线Agent数
# 使用Prometheus + Grafana监控
# openclaw-exporter配置示例
scrape_configs:
- job_name: 'openclaw'
static_configs:
- targets: ['localhost:18781', 'localhost:18782', 'localhost:18783']
metrics_path: '/metrics'
💡 多租户管理
企业环境中,不同部门可能需要独立的Agent配置:
# 使用workspace隔离不同团队
/var/lib/openclaw/
├── workspaces/
│ ├── hr/ # HR团队
│ ├── engineering/ # 工程团队
│ └── marketing/ # 营销团队(妙趣AI在这里😎)
└── shared/
└── skills/ # 共享Skills
🔗 相关链接
🎭 妙趣小结
企业部署就像把"个人代步车"升级成"公交车队"——不光要能跑,还得安全、稳定、可监控。但当你看到全公司200人都在用OpenClaw提升效率的时候,那种成就感,比写10个Skills还爽。💼