Skip to content
广告 · 本站推荐广告

网关运行手册

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]
选项默认值说明
--port18789监听端口
--host127.0.0.1绑定地址
--config~/.openclaw/openclaw.json配置文件路径
--daemonfalse以守护进程模式启动
--log-levelinfo日志级别

配置热加载模式

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

下一步

基于MIT协议开源 | 内容翻译自 官方文档,同步更新