6.7 KiB
6.7 KiB
OpenClaw 多机部署指南
🏠 部署架构
当前配置
| 机器 | IP地址 | 角色 | 代号 |
|---|---|---|---|
| 1号机 | 192.168.0.31 | 主机 | 青龙 🐉 |
| 2号机 | 192.168.0.32 | 守护者 | 守护者 🛡️ |
架构图
┌─────────────────────────────────────────────────────────┐
│ 网络环境 │
│ 代理: 192.168.0.66:7890 (HTTP/HTTPS) │
└─────────────────────────────────────────────────────────┘
│
┌───────────────┴───────────────┐
▼ ▼
┌───────────────┐ ┌───────────────┐
│ 1号机 │ │ 2号机 │
│ 主机/青龙 │ │ 守护者 │
│ :18789 │ │ :18789 │
│ 主Telegram │ │ 辅助Telegram │
│ Bot: dctc6788│ │ Bot: dctc_02 │
└───────────────┘ └───────────────┘
🚀 部署步骤
1. SSH 连接配置
# 创建 SSH 别名
cat >> ~/.ssh/config << EOF
Host 1号机
HostName 192.168.0.31
User root
Port 22
Host 2号机
HostName 192.168.0.32
User root
Port 22
EOF
# 测试连接
ssh 1号机
ssh 2号机
2. 2号机初始化
# SSH连接
sshpass -p '3efvVGY&' ssh -o StrictHostKeyChecking=no root@192.168.0.32
# 配置代理
export https_proxy=http://192.168.0.66:7890
export http_proxy=http://192.168.0.66:7890
# 安装 OpenClaw
npm install --global openclaw@latest
# 启动向导
openclaw onboard --install-daemon
3. systemd 服务配置
2号机 systemd service:
# ~/.config/systemd/user/openclaw-gateway.service
[Unit]
Description=OpenClaw Gateway (守护者)
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/openclaw gateway --port 18789
Environment="https_proxy=http://192.168.0.66:7890"
Environment="http_proxy=http://192.168.0.66:7890"
Environment="HTTPS_PROXY=http://192.168.0.66:7890"
Environment="HTTP_PROXY=http://192.168.0.66:7890"
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
应用服务配置:
# 2号机上执行
systemctl --user daemon-reload
systemctl --user enable openclaw-gateway.service
systemctl --user start openclaw-gateway.service
# 验证
systemctl --user status openclaw-gateway.service
📋 配置文件
1号机配置 (主机/青龙)
{
"models": {
"providers": {
"deepseek": {
"baseUrl": "https://api.deepseek.com/v1",
"apiKey": "sk-xxx",
"api": "openai-completions",
"models": [{"id": "deepseek-chat", "name": "DeepSeek"}]
},
"minimax": {
"baseUrl": "https://api.minimaxi.com/v1",
"apiKey": "sk-api-xxx",
"models": [
{"id": "minimax-m2.1"},
{"id": "embo-01"}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "minimax/minimax-m2.1"
}
}
},
"channels": {
"telegram": {
"enabled": true,
"botToken": "8529719199:AAGjLDflvMXAEdgrBTSBEczOoSMybLU4gcs"
}
},
"gateway": {
"port": 18789,
"auth": {
"token": "openclaw-simple-token"
}
}
}
2号机配置 (守护者)
{
"models": {
"providers": {
"deepseek": {
"baseUrl": "https://api.deepseek.com/v1",
"apiKey": "sk-xxx",
"models": [{"id": "deepseek-chat", "name": "DeepSeek"}]
},
"minimax": {
"baseUrl": "https://api.minimaxi.com/v1",
"apiKey": "sk-api-xxx",
"models": [
{"id": "minimax-m2.1"},
{"id": "embo-01"}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "deepseek/deepseek-chat"
}
}
},
"channels": {
"telegram": {
"enabled": true,
"botToken": "8202664888:AAE0UyCFJJBLC8notdmT42XOJRBoWLJ6XOI"
}
},
"gateway": {
"port": 18789,
"auth": {
"token": "openclaw-guardian-token-2nd"
}
}
}
🔧 远程管理
常用命令
# 1号机状态
sshpass -p 'password' ssh root@192.168.0.31 "openclaw status"
# 2号机状态
sshpass -p '3efvVGY&' ssh root@192.168.0.32 "openclaw status"
# 2号机重启Gateway
sshpass -p '3efvVGY&' ssh root@192.168.0.32 "openclaw gateway restart"
# 2号机发送消息
sshpass -p '3efvVGY&' ssh root@192.168.0.32 "openclaw message send --channel telegram --target 5117446326 --message 'test'"
监控脚本
#!/bin/bash
# monitor-2nd-machine.sh
echo "=== 2号机 (守护者) 状态 ==="
echo "时间: $(date)"
echo ""
# 检查Gateway进程
echo "Gateway进程:"
sshpass -p '3efvVGY&' ssh root@192.168.0.32 "ps aux | grep openclaw | grep -v grep"
echo ""
echo "系统资源:"
sshpass -p '3efvVGY&' ssh root@192.168.0.32 "free -h"
echo ""
echo "最近错误:"
sshpass -p '3efvVGY&' ssh root@192.168.0.32 "journalctl --user -u openclaw-gateway.service --since '1 hour ago' --no-pager | grep -i error | tail -5"
📊 性能对比
| 指标 | 1号机 (青龙) | 2号机 (守护者) |
|---|---|---|
| 默认模型 | MiniMax-m2.1 | DeepSeek |
| 代理 | 预配置 | 需手动配置 |
| Telegram | 正常 | 正常 |
| 内存管理器 | 停用 | 待测试 |
| 状态 | 生产就绪 | 生产就绪 |
⚠️ 注意事项
Token 冲突
- 每个实例必须使用独立的 Telegram Bot Token
- Gateway Token 也必须不同
代理配置
- systemd 服务不会自动继承环境变量
- 必须在 service 文件中显式配置
配置文件验证
- OpenClaw 使用严格 JSON Schema 验证
- 未知字段会导致启动失败
- 使用
openclaw doctor --fix修复
🔄 同步策略
配置同步
# 从1号机同步配置到2号机
scp ~/.openclaw/openclaw.json root@192.168.0.32:/root/.openclaw/openclaw.json
# 注意: 同步后需要修改:
# - gateway.auth.token
# - channels.telegram.botToken
日志聚合
# SSH隧道访问2号机日志
ssh -L 18790:localhost:18789 root@192.168.0.32
# 然后本地查看
openclaw logs --follow --port 18790
最后更新: 2026-02-03 21:40 GMT+8 维护者: 青龙 🐉 参考: 2号机部署完整记录 (memory/2026-02-03.md)