多网关部署(同一主机)
大多数场景一个网关就够了——单个网关可以同时处理多条消息通道和多个 agent。如果你确实需要更强的隔离或冗余(比如跑一个救援 bot),可以用独立的配置文件和端口运行多个网关。
隔离清单(必须逐项确认)
OPENCLAW_CONFIG_PATH— 每个实例一份独立配置OPENCLAW_STATE_DIR— 每个实例独立的会话、凭证、缓存目录agents.defaults.workspace— 每个实例独立的工作区根路径gateway.port(或--port)— 每个实例唯一- 派生端口(浏览器/canvas)不能重叠
如果共用了上述任何一项,你会遇到配置竞争和端口冲突。
推荐方式:--profile
Profile 会自动隔离 OPENCLAW_STATE_DIR + OPENCLAW_CONFIG_PATH,并给服务名加上后缀。
# main
openclaw --profile main setup
openclaw --profile main gateway --port 18789
# rescue
openclaw --profile rescue setup
openclaw --profile rescue gateway --port 19001
按 profile 安装服务:
openclaw --profile main gateway install
openclaw --profile rescue gateway install
救援 bot 指南
在同一主机上运行第二个网关,需要独立的:
- profile/配置
- 状态目录
- 工作区
- 基础端口(以及派生端口)
这样救援 bot 和主 bot 完全隔离,主 bot 出问题时,救援 bot 可以用来排查或修改配置。
端口间距建议:基础端口之间至少留 20 个端口的间隔,避免派生的浏览器/canvas/CDP 端口冲突。
安装步骤(救援 bot)
# 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 onboarding)
openclaw --profile rescue gateway install
端口映射(派生端口)
基础端口 = gateway.port(或 OPENCLAW_GATEWAY_PORT / --port)。
- 浏览器控制服务端口 = 基础端口 + 2(仅监听回环地址)
- canvas 服务在网关 HTTP 服务器上(与
gateway.port同端口) - 浏览器 profile 的 CDP 端口从
browser.controlPort + 9 .. + 108自动分配
如果你在配置或环境变量中手动覆盖了这些端口,必须确保每个实例的值不重复。
浏览器/CDP 注意事项(常见坑)
- 不要在多个实例上把
browser.cdpUrl指向同一个地址。 - 每个实例需要自己的浏览器控制端口和 CDP 端口范围(从各自的网关端口派生)。
- 如果需要显式指定 CDP 端口,按实例设置
browser.profiles.<name>.cdpPort。 - 远程 Chrome:按实例按 profile 设置
browser.profiles.<name>.cdpUrl。
手动环境变量示例
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
快速检查
openclaw --profile main status
openclaw --profile rescue status
openclaw --profile rescue browser status