多个 Gateway(同一主机)
大多数场景应使用一个 Gateway,因为单个 Gateway 可以处理多个消息连接和代理。如果需要更强的隔离或冗余(例如救援机器人),可以使用隔离的配置文件/端口运行单独的 Gateway。
隔离检查清单(必需)
OPENCLAW_CONFIG_PATH— 每个实例的配置文件OPENCLAW_STATE_DIR— 每个实例的会话、凭证、缓存agents.defaults.workspace— 每个实例的工作空间根目录gateway.port(或--port)— 每个实例唯一- 派生端口(浏览器/画布)不能重叠
如果这些共享,将会遇到配置竞争和端口冲突。
推荐:配置文件(--profile)
配置文件自动限定 OPENCLAW_STATE_DIR + OPENCLAW_CONFIG_PATH 的范围,并为服务名称添加后缀。
bash
# main
openclaw --profile main setup
openclaw --profile main gateway --port 18789
# rescue
openclaw --profile rescue setup
openclaw --profile rescue gateway --port 19001每个配置文件的服务:
bash
openclaw --profile main gateway install
openclaw --profile rescue gateway install救援机器人指南
在同一主机上运行第二个 Gateway,配置独立的:
- 配置文件/配置
- 状态目录
- 工作空间
- 基础端口(加上派生端口)
这使救援机器人与主机器人隔离,以便在主机器人宕机时进行调试或应用配置更改。
端口间距:在基础端口之间至少留出 20 个端口,这样派生的浏览器/画布/CDP 端口永远不会冲突。
如何安装(救援机器人)
bash
# 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(仅本地回环)
canvasHost.port = base + 4- 浏览器配置文件 CDP 端口从
browser.controlPort + 9 .. + 108自动分配
如果在配置或环境变量中覆盖这些值,必须确保每个实例保持唯一。
浏览器/CDP 注意事项(常见陷阱)
- 不要在多个实例上将
browser.cdpUrl固定为相同的值。 - 每个实例需要自己的浏览器控制端口和 CDP 范围(从其 gateway 端口派生)。
- 如果需要明确的 CDP 端口,为每个实例设置
browser.profiles.<name>.cdpPort。 - 远程 Chrome:使用
browser.profiles.<name>.cdpUrl(每个配置文件、每个实例)。
手动环境变量示例
bash
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快速检查
bash
openclaw --profile main status
openclaw --profile rescue status
openclaw --profile rescue browser status