OpenClaw 群控模式:一人操控多台 AI Agent [完整配置]

206 阅读5分钟

OpenClaw 群控模式:一人操控多台 AI Agent [完整配置]

封面图

家里有台 Mac Mini 跑着 Claude Max,公司服务器上跑着 Gemini,云上还有台专门跑长任务的机器。

每次切换都要改配置?太蠢了。

现在我用一条命令,想调哪台调哪台 👇

适用范围:Mac、Linux 服务器、云主机、任何能跑 OpenClaw 的设备都适用。


前置阅读01-远程模式配置 — 本文假设你已掌握单个 Gateway 的远程连接


📌 划重点

方案适用场景切换方式
多 Agent一个 Gateway,多种任务分工--agent xxx 参数
多 Gateway + Profile多台服务器,分别有不同 AI 资源--profile xxx 参数
环境变量切换临时切换,不改配置OPENCLAW_GATEWAY_URL=xxx

核心原则:Gateway 保持 loopback + SSH 隧道 + Auth Token = 最安全


🎬 背景

场景:你有多台机器跑 OpenClaw


工作电脑(主力开发机)
    │
    ├── 家里的 Mac Mini(Claude Max 订阅)
    ├── 公司的服务器(Gemini API)
    └── 云服务器(专门跑长任务)

需求:在工作电脑上用一条命令,选择发给哪个 Gateway 执行。


🔧 方案一:多 Agent(单 Gateway)

适合:一个 Gateway 上跑多种任务

原理


工作电脑 ──→ Gateway
               
               ├── Agent: main(日常对话)
               ├── Agent: coding(写代码)
               ├── Agent: research(搜索研究)
               └── Agent: ops(运维任务)

使用方式

# 日常对话
openclaw agent --agent main -m "今天天气怎么样"

# 写代码
openclaw agent --agent coding -m "写一个 Python 爬虫"

# 搜索研究
openclaw agent --agent research -m "2026 年 AI 趋势"

创建新 Agent

# 在 Gateway 机器上运行
openclaw agents create --id coding --model claude-opus-4-6

# 或者编辑配置文件
cat >> ~/.openclaw/openclaw.json << 'EOF'
{
  "agents": {
    "list": [
      { "id": "main", "model": "claude-sonnet-4-5" },
      { "id": "coding", "model": "claude-opus-4-6" },
      { "id": "research", "model": "gemini-3-pro-preview" }
    ]
  }
}
EOF

查看已有 Agent

openclaw agents list


🔧 方案二:多 Gateway + Profile 隔离(官方推荐)

适合:多台服务器,各有不同 AI 资源

原理


工作电脑
    
    ├── Profile: default ──SSH──→ 家里 Mac (Claude Max)
    ├── Profile: office ──SSH──→ 公司服务器 (Gemini)
    └── Profile: cloud ──SSH──→ 云服务器 (长任务)

每个 Profile 有独立的配置目录

  • ~/.openclaw/(默认)
  • ~/.openclaw-office/
  • ~/.openclaw-cloud/

Step 1: 配置 SSH 隧道

# ~/.ssh/config

# 家里 Mac(默认)
Host openclaw-home
    HostName 192.168.31.106
    User botdev
    LocalForward 28789 127.0.0.1:18789
    ServerAliveInterval 60

# 公司服务器
Host openclaw-office
    HostName office.example.com
    User deploy
    LocalForward 28790 127.0.0.1:18789
    IdentityFile ~/.ssh/office_key

# 云服务器
Host openclaw-cloud
    HostName cloud.example.com
    User ubuntu
    LocalForward 28791 127.0.0.1:18789
    IdentityFile ~/.ssh/cloud_key

Step 2: 创建 Profile 配置

# 公司服务器 Profile
mkdir -p ~/.openclaw-office
cat > ~/.openclaw-office/openclaw.json << 'EOF'
{
  "gateway": {
    "mode": "remote",
    "remote": {
      "url": "ws://127.0.0.1:28790",
      "token": "office-gateway-token-here",
      "sshTarget": "openclaw-office"
    }
  }
}
EOF

# 云服务器 Profile
mkdir -p ~/.openclaw-cloud
cat > ~/.openclaw-cloud/openclaw.json << 'EOF'
{
  "gateway": {
    "mode": "remote",
    "remote": {
      "url": "ws://127.0.0.1:28791",
      "token": "cloud-gateway-token-here",
      "sshTarget": "openclaw-cloud"
    }
  }
}
EOF

Step 3: 启动 SSH 隧道

# 启动所有隧道(后台运行)
ssh -fN openclaw-home
ssh -fN openclaw-office
ssh -fN openclaw-cloud

# 验证隧道
lsof -i :28789  # 家里
lsof -i :28790  # 公司
lsof -i :28791  # 云

Step 4: 使用不同 Profile

# 默认(家里 Mac)
openclaw status
openclaw agent --agent main -m "日常任务"

# 公司服务器
openclaw --profile office status
openclaw --profile office agent --agent main -m "公司任务"

# 云服务器
openclaw --profile cloud status
openclaw --profile cloud agent --agent main -m "长时间任务"


⚡ 快捷方式:Alias 配置

# ~/.zshrc 或 ~/.bashrc

# 方式 1:Profile 切换
alias oc="openclaw"
alias oc-home="openclaw"
alias oc-office="openclaw --profile office"
alias oc-cloud="openclaw --profile cloud"

# 方式 2:环境变量切换(不用 Profile)
alias oc-home="OPENCLAW_GATEWAY_URL=ws://127.0.0.1:28789 openclaw"
alias oc-office="OPENCLAW_GATEWAY_URL=ws://127.0.0.1:28790 openclaw"
alias oc-cloud="OPENCLAW_GATEWAY_URL=ws://127.0.0.1:28791 openclaw"

使用:

oc-home agent --agent main -m "家里的 AI"
oc-office agent --agent main -m "公司的 AI"
oc-cloud agent --agent main -m "云上的 AI"


🔒 安全性:远程服务器注意事项

安全三原则

原则配置说明
Gateway loopback"bind": "loopback"只监听 127.0.0.1,不暴露端口
SSH 隧道LocalForward传输加密
Auth Token"auth.token": "xxx"身份认证

远程服务器 Gateway 配置

// 远程服务器上的 ~/.openclaw/openclaw.json
{
  "gateway": {
    "port": 18789,
    "bind": "loopback",  // 关键:只监听本地
    "auth": {
      "mode": "token",
      "token": "your-secret-token-here"  // 关键:必须设置
    }
  }
}

安全检查清单

检查项状态
Gateway bind: loopback✅ 必须
Gateway auth.token 已配置✅ 必须
服务器防火墙不开放 18789✅ 必须
SSH 使用密钥认证✅ 推荐
SSH 禁用密码登录⭐ 加强

⚠️ 绝对不要

# ❌ 错误:直接暴露 Gateway 端口
"bind": "0.0.0.0"  # 危险!

# ❌ 错误:不设置 token
"auth": { "mode": "none" }  # 危险!

# ❌ 错误:防火墙开放 18789
ufw allow 18789  # 危险!


🔄 自动化:SSH 隧道自启动

macOS LaunchAgent

# 创建 LaunchAgent
cat > ~/Library/LaunchAgents/com.openclaw.tunnels.plist << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.openclaw.tunnels</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>-c</string>
        <string>ssh -fN openclaw-home; ssh -fN openclaw-office; ssh -fN openclaw-cloud</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
</dict>
</plist>
EOF

# 加载
launchctl load ~/Library/LaunchAgents/com.openclaw.tunnels.plist

手动管理脚本

# ~/bin/oc-tunnels

#!/bin/bash
case "$1" in
    start)
        ssh -fN openclaw-home 2>/dev/null && echo "✅ home tunnel started"
        ssh -fN openclaw-office 2>/dev/null && echo "✅ office tunnel started"
        ssh -fN openclaw-cloud 2>/dev/null && echo "✅ cloud tunnel started"
        ;;
    stop)
        pkill -f "ssh -fN openclaw"
        echo "✅ All tunnels stopped"
        ;;
    status)
        pgrep -f "ssh -fN openclaw" > /dev/null && echo "✅ Tunnels running" || echo "❌ Tunnels not running"
        lsof -i :28789,:28790,:28791 2>/dev/null
        ;;
    *)
        echo "Usage: oc-tunnels {start|stop|status}"
        ;;
esac

使用:

chmod +x ~/bin/oc-tunnels
oc-tunnels start   # 启动所有隧道
oc-tunnels status  # 查看状态
oc-tunnels stop    # 停止所有隧道


📋 配置清单模板

工作电脑完整配置

~/.ssh/config

# 家里 Mac
Host openclaw-home
    HostName 192.168.31.106
    User botdev
    LocalForward 28789 127.0.0.1:18789

# 公司服务器
Host openclaw-office
    HostName office.example.com
    User deploy
    LocalForward 28790 127.0.0.1:18789
    IdentityFile ~/.ssh/office_key

# 云服务器
Host openclaw-cloud
    HostName cloud.example.com
    User ubuntu
    LocalForward 28791 127.0.0.1:18789
    IdentityFile ~/.ssh/cloud_key

~/.openclaw/openclaw.json(默认,连家里 Mac):

{
  "gateway": {
    "mode": "remote",
    "remote": {
      "url": "ws://127.0.0.1:28789",
      "token": "home-token",
      "sshTarget": "openclaw-home"
    }
  }
}

~/.zshrc

alias oc="openclaw"
alias oc-office="openclaw --profile office"
alias oc-cloud="openclaw --profile cloud"
alias oc-tunnels="~/bin/oc-tunnels"


💡 方案对比

方案切换方式配置复杂度适用场景
多 Agent--agent xxx一个 Gateway,多种任务
多 Profile--profile xxx多台服务器,配置隔离
环境变量OPENCLAW_GATEWAY_URL=xxx临时切换,脚本调用
Aliasoc-xxx日常使用,快捷切换

🔗 参考资料


📝 一句话总结

Profile 隔离配置 + SSH 隧道转发 + Auth Token 认证 = 安全群控多台 AI 主机


💬 你的多机场景是什么?

  • 家里 + 公司两台机器?
  • 本地 + 云服务器混合部署?
  • 还是想用不同模型做 A/B 测试?

评论区聊聊你的使用场景!下一篇讲「全自动化:Telegram 广播 + AI 内容工厂」— 推代码就能触发 Agent 干活 👇