网关运行手册
Gateway(网关)是 OpenClaw 的唯一常驻守护进程。它承担路由、控制面(Control Plane)、Channel 连接管理等核心职责,并通过单一多路复用端口对外提供 WebSocket、HTTP API 和管理界面。
核心概念
| 特性 | 说明 |
|---|---|
| 单进程架构 | 一个 always-on 进程处理所有功能 |
| 多路复用端口 | WebSocket、HTTP API、UI 共享同一端口 |
| 默认绑定 | 127.0.0.1:18789(仅本地回环) |
| 认证方式 | Token 认证 或 密码认证 |
| 配置热加载 | 支持 off / hot / restart / hybrid 四种模式 |
快速启动
启动网关
bash
openclaw gateway --port 18789端口说明
默认端口为 18789,绑定到 loopback(回环地址)127.0.0.1,仅接受本机连接。如需远程访问,请参阅 远程访问。
查看状态
bash
openclaw status输出示例:
text
OpenClaw Gateway
Status: running
PID: 42187
Port: 18789
Uptime: 2h 34m
Channels: 3 connected
Sessions: 1 active停止网关
bash
openclaw gateway stop优雅停机
stop 命令会等待当前活跃会话完成后再终止进程。如需强制停止,使用 --force 标志。
启动选项
bash
openclaw gateway [OPTIONS]| 选项 | 默认值 | 说明 |
|---|---|---|
--port | 18789 | 监听端口 |
--host | 127.0.0.1 | 绑定地址 |
--config | ~/.openclaw/openclaw.json | 配置文件路径 |
--daemon | false | 以守护进程模式启动 |
--log-level | info | 日志级别 |
配置热加载模式
Gateway 支持四种配置重载(Config Reload)模式:
| 模式 | 行为 |
|---|---|
off | 修改配置后需手动重启 |
hot | 检测到变更后自动应用,不中断连接 |
restart | 检测到变更后自动重启进程 |
hybrid | 部分配置项热加载,其余触发重启 |
bash
# 设置热加载模式
openclaw config set gateway.reloadMode hot单进程设计
Gateway 采用单进程设计,所有服务共享同一端口:
text
┌─────────────────────────────────┐
│ Gateway Process │
│ │
│ ┌───────────┐ ┌─────────────┐ │
│ │ WebSocket │ │ HTTP API │ │
│ │ Server │ │ Server │ │
│ └─────┬─────┘ └──────┬──────┘ │
│ │ │ │
│ ┌─────┴───────────────┴──────┐ │
│ │ Multiplexed Port :18789 │ │
│ └────────────────────────────┘ │
└─────────────────────────────────┘为什么是单进程?
单进程架构简化了部署和运维。所有状态保存在同一进程内存中,无需进程间通信(IPC),降低了系统复杂度。
常用运维命令
bash
# 启动(前台模式)
openclaw gateway
# 启动(守护进程模式)
openclaw gateway --daemon
# 查看状态
openclaw status
# 查看日志
openclaw logs --follow
# 停止
openclaw gateway stop
# 诊断
openclaw doctor