OpenClaw 3 机集群(Windows + Linux 混合)一键脚本 + 完整配置
- 集群架构规划(1 主 2 从)
- 统一安装脚本(Windows PowerShell / Linux bash)
- 主节点配置(gateway + 调度)
- 从节点配置(worker + 注册到主)
- 集群通信、端口、令牌、存储
- 一键启停、扩容、状态检查
一、集群规划(3 节点)
- 节点 1(主节点,Linux 推荐):Gateway + Supervisor + 调度器
- IP:
192.168.1.100 - 端口:
20789(gateway)、20790(集群通信)
- IP:
- 节点 2(从,Windows):Worker 节点
- IP:
192.168.1.101
- IP:
- 节点 3(从,Linux):Worker 节点
- IP:
192.168.1.102
- IP:
- 统一要求:Node.js 22.x、OpenClaw 2026.2+、防火墙放行 20789/20790
二、一键安装脚本(Windows + Linux)
1)Windows 一键脚本(install-openclaw-win.ps1)
powershell
# 以管理员身份运行 Set-ExecutionPolicy Bypass -Scope Process -Force # 1. 安装 Node.js 22 winget install OpenJS.NodeJS.LTS -e --source winget refreshenv # 2. 换淘宝源(国内加速) npm config set registry https://registry.npmmirror.com # 3. 安装 PM2 npm install -g pm2 # 4. 安装 OpenClaw npm install -g openclaw@latest # 5. 初始化工作目录 md D:\OpenClaw cd D:\OpenClaw # 6. 生成集群令牌(32位随机) $token = -join ((0..31) | ForEach-Object { "{0:x2}" -f (Get-Random -Maximum 256) }) "GW_TOKEN=$token" | Out-File .env -Encoding utf8 Write-Host "✅ Windows 安装完成,令牌:$token"2)Linux 一键脚本(install-openclaw-linux.sh)
bash
运行
#!/bin/bash set -e # 1. 安装依赖 sudo apt update && sudo apt install -y curl git build-essential # 2. 安装 Node.js 22 curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash - sudo apt install -y nodejs # 3. 换淘宝源 npm config set registry https://registry.npmmirror.com # 4. 安装 PM2 sudo npm install -g pm2 # 5. 安装 OpenClaw sudo npm install -g openclaw@latest # 6. 初始化目录 mkdir -p ~/OpenClaw && cd ~/OpenClaw # 7. 生成集群令牌 TOKEN=$(openssl rand -hex 32) echo "GW_TOKEN=$TOKEN" > .env echo "✅ Linux 安装完成,令牌:$TOKEN"三、主节点配置(Node1:192.168.1.100)
1)配置文件~/.openclaw/config.json
json
{ "meta": { "lastTouchedVersion": "2026.2.1", "lastTouchedAt": "2026-05-21T00:00:00Z" }, "wizard": { "lastRunAt": "2026-05-21T00:00:00Z", "lastRunVersion": "2026.2.1", "lastRunCommand": "onboard", "lastRunMode": "cluster-master" }, "gateway": { "port": 20789, "clusterPort": 20790, "bindHost": "0.0.0.0", "allowInsecureAuth": true, "auth": { "mode": "token", "token": "主节点生成的GW_TOKEN" }, "mode": "cluster-master", "workers": [ "192.168.1.101", "192.168.1.102" ] }, "commands": { "native": "auto", "nativeSkills": "auto" }, "cluster": { "role": "master", "peers": [], "syncInterval": 5000 } }2)主节点启动
bash
运行
# Linux pm2 start "openclaw gateway start" --name openclaw-master # Windows PowerShell Start-Job -ScriptBlock { openclaw gateway start }四、从节点配置(Node2 / Node3)
1)从节点配置文件~/.openclaw/config.json
json
{ "meta": { "lastTouchedVersion": "2026.2.1" }, "wizard": { "lastRunMode": "cluster-worker" }, "gateway": { "port": 20789, "bindHost": "0.0.0.0", "auth": { "mode": "token", "token": "主节点的GW_TOKEN" }, "mode": "cluster-worker", "masterHost": "192.168.1.100", "masterPort": 20789 }, "cluster": { "role": "worker", "master": "192.168.1.100:20789" } }2)从节点启动
bash
运行
# Linux / Windows pm2 start "openclaw gateway start" --name openclaw-worker五、集群验证与常用命令
1)检查集群状态(主节点执行)
bash
运行
openclaw gateway status # 输出应显示 1 master + 2 workers2)查看日志
bash
运行
pm2 logs openclaw-master pm2 logs openclaw-worker3)扩容(新增节点)
- 新节点执行安装脚本
- 复制主节点GW_TOKEN
- 修改配置为
cluster-worker,指向主节点 IP - 启动服务,主节点自动发现
六、防火墙放行(必须)
Linux(ufw)
bash
运行
sudo ufw allow 20789/tcp sudo ufw allow 20790/tcp sudo ufw reloadWindows(PowerShell 管理员)
powershell
New-NetFirewallRule -DisplayName "OpenClaw-Gateway" -Direction Inbound -LocalPort 20789 -Protocol TCP -Action Allow New-NetFirewallRule -DisplayName "OpenClaw-Cluster" -Direction Inbound -LocalPort 20790 -Protocol TCP -Action Allow七、关键注意事项
- 所有节点 Node.js 必须 22.x 统一版本
- GW_TOKEN 必须完全一致,由主节点生成后分发
- 集群通信默认20790,不可被占用
- 数据默认存在
~/.openclaw,建议用共享存储(NFS/MinIO)做持久化
如果你需要,我可以再给你:
- Docker Compose 集群版(3 容器一键启动)
- K8s Helm Chart部署
- 集群自动发现 + 负载均衡配置
