网关管理
Gateway 是 OpenClaw 的核心守护进程——它在后台持续运行,连接你所有的聊天平台和 AI 模型。所有消息的收发、工具的调用、定时任务的执行,都经过 Gateway 调度。
理解 Gateway
Gateway 启动后会做三件事:
- 建立连接:与所有已配置的频道(Telegram、微信等)建立长连接
- 监听消息:实时接收用户消息,路由给对应 Agent
- 保持心跳:自动检测连接断开并重连,无需人工干预
一台机器只需运行一个 Gateway 实例,即可同时管理数十个频道和多个 Agent。
常用命令
bash
# 查看网关运行状态(最常用)
openclaw status
# 启动网关(后台模式)
openclaw start
# 重启网关(修改配置后执行)
openclaw gateway restart
# 停止网关
openclaw stop
# 实时查看日志
openclaw logs --follow
# 查看最近 100 行日志
openclaw logs -n 100
# 打开 Web 控制面板
openclaw dashboard
# 一键智能诊断(排查问题时用)
openclaw doctor网关状态说明
执行 openclaw status 后,你会看到类似这样的输出:
Gateway: ● running (PID: 12345, uptime: 2d 4h)
Channels: 3 connected, 0 error
✓ telegram:my_bot
✓ feishu:work_bot
✓ discord:server
Sessions: 2 active
Memory: 234 MB / 1024 MB| 字段 | 含义 |
|---|---|
| running / stopped | 网关是否在运行 |
| Channels | 已连接的频道数量和错误数 |
| Sessions | 当前活跃的对话会话数 |
| Memory | 进程内存占用 |
配置变更后的操作
修改 openclaw.json 后,需要重启 Gateway 让配置生效:
bash
# 编辑配置
openclaw config set model.default "claude-haiku-4-5"
# 重启以应用
openclaw gateway restart热重载
修改 系统提示词(SOUL.md)不需要重启,Gateway 会在下一条消息时自动加载新版本。
Web 控制台
Gateway 内置 Web 界面,浏览器访问 http://127.0.0.1:18789/ 即可:
- 实时状态:频道连接状态、活跃会话、Token 消耗
- 消息日志:查看每条消息的完整处理链路
- 配置编辑:在线修改配置,无需命令行
- WebChat:直接与 Agent 对话,无需配置任何外部平台
生产环境建议
开机自启
bash
# macOS(使用 launchd)
openclaw service install
openclaw service start
# Linux(使用 systemd)
openclaw systemd install
sudo systemctl enable openclaw
sudo systemctl start openclaw内存限制
长时间运行后,内存可能增长。配置自动重启阈值:
json
{
"gateway": {
"maxMemoryMB": 1024,
"autoRestartOnOOM": true
}
}日志轮转
json
{
"logging": {
"level": "info",
"maxFileSizeMB": 50,
"maxFiles": 7
}
}