跳转到内容

多网关

大多数设置应使用一个 Gateway(网关) 网关,因为单个 Gateway(网关) 网关 可以处理多个消息连接和代理。如果您需要更强的隔离性或冗余(例如,救援机器人),请使用隔离的配置文件/端口运行单独的 Gateway(网关) 网关。

  • OPENCLAW_CONFIG_PATH — 每个实例的配置文件
  • OPENCLAW_STATE_DIR — 每个实例的会话、凭据、缓存
  • 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

在同一主机上运行第二个 Gateway(网关) 网关,并使用其自己的:

  • 配置文件/配置
  • 状态目录
  • 工作区
  • 基础端口(加上派生端口)

这使得救援机器人与主机器人隔离,以便在主机器人停机时它可以进行调试或应用配置更改。

端口间距:基础端口之间至少保留 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(仅限环回)
  • canvas 主机由 Gateway(网关) 网关 HTTP 服务器提供服务(端口与 gateway.port 相同)
  • 浏览器配置文件 CDP 端口从 browser.controlPort + 9 .. + 108 自动分配

如果您在配置或环境变量中覆盖了其中任何一项,则必须为每个实例保持它们唯一。

  • 不要在多个实例中将 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