Gateway 网关服务运行手册

最后更新:2025-12-09

是什么

如何运行(本地)

openclaw gateway --port 18789
# 在 stdio 中获取完整的调试/追踪日志:
openclaw gateway --port 18789 --verbose
# 如果端口被占用,终止监听器然后启动:
openclaw gateway --force
# 开发循环(TS 更改时自动重载):
pnpm gateway:watch

远程访问

多个 Gateway 网关(同一主机)

通常不需要:一个 Gateway 网关可以服务多个消息渠道和智能体。仅在需要冗余或严格隔离(例如:救援机器人)时使用多个 Gateway 网关。

如果你隔离状态 + 配置并使用唯一端口,则支持。完整指南:多个 Gateway 网关

服务名称是配置文件感知的:

安装元数据嵌入在服务配置中:

救援机器人模式:保持第二个 Gateway 网关隔离,使用自己的配置文件、状态目录、工作区和基础端口间隔。完整指南:救援机器人指南

Dev 配置文件(--dev

快速路径:运行完全隔离的 dev 实例(配置/状态/工作区)而不触及你的主设置。

openclaw --dev setup
openclaw --dev gateway --allow-unconfigured
# 然后定位到 dev 实例:
openclaw --dev status
openclaw --dev health

默认值(可通过 env/flags/config 覆盖):

派生端口(经验法则):

每个实例的检查清单:

按配置文件安装服务:

openclaw --profile main gateway install
openclaw --profile rescue gateway install

示例:

OPENCLAW_CONFIG_PATH=~/.openclaw/a.json OPENCLAW_STATE_DIR=~/.openclaw-a openclaw gateway --port 19001
OPENCLAW_CONFIG_PATH=~/.openclaw/b.json OPENCLAW_STATE_DIR=~/.openclaw-b openclaw gateway --port 19002

协议(运维视角)

方法(初始集)

另见:Presence 了解 presence 如何产生/去重以及为什么稳定的 client.instanceId 很重要。

事件

WebChat 集成

类型和验证

连接快照

错误码(res.error 形状)

保活行为

重放 / 间隙

监管(macOS 示例)

Gateway 网关服务管理(CLI)

使用 Gateway 网关 CLI 进行 install/start/stop/restart/status:

openclaw gateway status
openclaw gateway install
openclaw gateway stop
openclaw gateway restart
openclaw logs --follow

注意事项:

捆绑的 mac 应用:

监管(systemd 用户单元)

OpenClaw 在 Linux/WSL2 上默认安装 systemd 用户服务。我们 建议单用户机器使用用户服务(更简单的 env,按用户配置)。 对于多用户或常驻服务器使用系统服务(无需 lingering, 共享监管)。

openclaw gateway install 写入用户单元。openclaw doctor 审计 单元并可以将其更新以匹配当前推荐的默认值。

创建 ~/.config/systemd/user/openclaw-gateway[-<profile>].service

[Unit]
Description=OpenClaw Gateway (profile: <profile>, v<version>)
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/bin/openclaw gateway --port 18789
Restart=always
RestartSec=5
Environment=OPENCLAW_GATEWAY_TOKEN=
WorkingDirectory=/home/youruser

[Install]
WantedBy=default.target

启用 lingering(必需,以便用户服务在登出/空闲后继续存活):

sudo loginctl enable-linger youruser

新手引导在 Linux/WSL2 上运行此命令(可能提示输入 sudo;写入 /var/lib/systemd/linger)。 然后启用服务:

systemctl --user enable --now openclaw-gateway[-<profile>].service

替代方案(系统服务) - 对于常驻或多用户服务器,你可以 安装 systemd 系统单元而不是用户单元(无需 lingering)。 创建 /etc/systemd/system/openclaw-gateway[-<profile>].service(复制上面的单元, 切换 WantedBy=multi-user.target,设置 User= + WorkingDirectory=),然后:

sudo systemctl daemon-reload
sudo systemctl enable --now openclaw-gateway[-<profile>].service

Windows(WSL2)

Windows 安装应使用 WSL2 并遵循上面的 Linux systemd 部分。

运维检查

安全保证

CLI 辅助工具

迁移指南