Skip to content

多個閘道

大多數安裝應該使用一個閘道,因為單一閘道可以處理多個訊息連線和代理程式。如果您需要更強的隔離或冗餘(例如,救援機器人),請使用獨立的設定檔/連接埠執行分開的閘道。

  • OPENCLAW_CONFIG_PATH — 每個執行個體的設定檔
  • OPENCLAW_STATE_DIR — 每個執行個體的 session、creds、快取
  • agents.defaults.workspace — 每個執行個體的工作區根目錄
  • gateway.port(或 --port) — 每個執行個體唯一
  • 衍生的連接埠(瀏覽器/canvas)不得重疊

如果共用這些項目,您將會遇到設定競爭和連接埠衝突。

設定檔會自動限定 OPENCLAW_STATE_DIR + OPENCLAW_CONFIG_PATH 的範圍並加上服務名稱後綴。

Terminal window
# main
openclaw --profile main setup
openclaw --profile main gateway --port 18789
# rescue
openclaw --profile rescue setup
openclaw --profile rescue gateway --port 19001

每個設定檔的服務:

Terminal window
openclaw --profile main gateway install
openclaw --profile rescue gateway install

在同一主機上執行第二個閘道,並擁有自己的:

  • 設定檔/設定
  • 狀態目錄
  • 工作區
  • 基礎連接埠(加上衍生連接埠)

這能讓救援機器人與主機器人保持隔離,以便在主要機器人停機時進行偵錯或套用設定變更。

連接埠間距:基礎連接埠之間至少保留 20 個連接埠,以免衍生的瀏覽器/canvas/CDP 連接埠發生衝突。

Terminal window
# Main bot (existing or fresh, without --profile param)
# Runs on port 18789 + Chrome CDC/Canvas/... Ports
openclaw onboard
openclaw gateway install
# Rescue bot (isolated profile + ports)
openclaw --profile rescue onboard
# Notes:
# - workspace name will be postfixed with -rescue per default
# - Port should be at least 18789 + 20 Ports,
# better choose completely different base port, like 19789,
# - rest of the onboarding is the same as normal
# To install the service (if not happened automatically during setup)
openclaw --profile rescue gateway install

基礎連接埠 = gateway.port(或 OPENCLAW_GATEWAY_PORT / --port)。

  • 瀏覽器控制服務連接埠 = 基礎連接埠 + 2(僅限 loopback)
  • Canvas 主機由閘道 HTTP 伺服器提供服務(與 gateway.port 的連接埠相同)
  • 瀏覽器設定檔 CDP 連接埠從 browser.controlPort + 9 .. + 108 自動分配

如果您在設定或環境變數中覆寫了這些項目中的任何一個,您必須確保每個執行個體都是唯一的。

瀏覽器/CDP 注意事項(常見陷阱)

Section titled “瀏覽器/CDP 注意事項(常見陷阱)”
  • 將多個執行個體上的 browser.cdpUrl 固定為相同的值。
  • 每個執行個體都需要自己的瀏覽器控制連接埠和 CDP 範圍(由其閘道連接埠衍生)。
  • 如果您需要明確的 CDP 連接埠,請為每個執行個體設定 browser.profiles.<name>.cdpPort
  • 遠端 Chrome:使用 browser.profiles.<name>.cdpUrl(每個設定檔、每個實例各一個)。
Terminal window
OPENCLAW_CONFIG_PATH=~/.openclaw/main.json \
OPENCLAW_STATE_DIR=~/.openclaw-main \
openclaw gateway --port 18789
OPENCLAW_CONFIG_PATH=~/.openclaw/rescue.json \
OPENCLAW_STATE_DIR=~/.openclaw-rescue \
openclaw gateway --port 19001
Terminal window
openclaw --profile main status
openclaw --profile rescue status
openclaw --profile rescue browser status