Files
syops/docs/k_openclaw_start_20260201.md
T

12 KiB
Raw Blame History

OpenClaw Gateway 启动问题排查记录

任务背景

用户遇到电脑启动问题,具体是在尝试启动 OpenClaw Gateway 服务时遇到了错误。本文档详细记录了排查过程中的每一步操作及其背后的用途与语法。

排查过程

步骤 1:检查项目结构并创建文档目录

执行命令:

mkdir -p docs

命令用途: 创建项目的文档目录,用于存放本次排查的知识记录文件。

命令详细解释:

  • mkdir:创建目录的命令
  • -p:递归创建目录,如果父目录不存在也会创建
  • docs:要创建的目录名称

执行输出:

(TraeAI-1) ~/Documents/dev/AI/hxops [0] $  trae-sandbox 'mkdir -p docs'

(TraeAI-1) ~/Documents/dev/AI/hxops [0] $

步骤 2:检查 OpenClaw 版本

执行命令:

openclaw --version

命令用途: 确认 OpenClaw 工具是否正确安装,并查看其版本信息。

命令详细解释:

  • openclaw:OpenClaw 命令行工具
  • --version:显示版本信息的参数

执行输出:

(TraeAI-1) ~/Documents/dev/AI/hxops [0] $  trae-sandbox 'openclaw --version'
2026.2.15

(TraeAI-1) ~/Documents/dev/AI/hxops [0] $

步骤 3:尝试安装 Gateway 服务

执行命令:

openclaw gateway install

命令用途: 根据错误提示,尝试安装 Gateway 服务。

命令详细解释:

  • openclaw:OpenClaw 命令行工具
  • gateway:Gateway 服务子命令
  • install:安装 Gateway 服务的参数

执行输出:

(TraeAI-1) ~/Documents/dev/AI/hxops [0] $  trae-sandbox 'openclaw gateway install'

🦞 OpenClaw 2026.2.15 (3fe22ea)
   Automation with claws: minimal fuss, maximal pinch.

Gateway install failed: Error: EPERM: operation not permitted, open '/Users/teemo/Library/LaunchAgents/ai.openclaw.gateway.plist'

(TraeAI-1) ~/Documents/dev/AI/hxops [1] $

步骤 4:使用 sudo 权限安装 Gateway 服务

执行命令:

sudo openclaw gateway install

命令用途: 使用管理员权限尝试安装 Gateway 服务,解决权限不足的问题。

命令详细解释:

  • sudo:以管理员权限执行命令
  • openclaw gateway install:安装 Gateway 服务的命令

执行输出:

(TraeAI-1) ~/Documents/dev/AI/hxops [1] $  sudo openclaw gateway install
Password:

🦞 OpenClaw 2026.2.15 (3fe22ea)
   Type the command with confidence—nature will provide the stack trace if needed.

Gateway install failed: Error: launchctl bootstrap failed: Bootstrap failed: 125: Domain does not support specified action

(TraeAI-1) ~/Documents/dev/AI/hxops [1] $

步骤 5:尝试使用 launchctl 手动安装

执行命令:

launchctl bootstrap gui/$UID ~/Library/LaunchAgents/ai.openclaw.gateway.plist

命令用途: 根据错误提示中的建议,尝试使用 launchctl 命令手动引导启动 Gateway 服务。

命令详细解释:

  • launchctl:macOS 系统的服务管理工具
  • bootstrap:引导加载服务的命令
  • gui/$UID:指定用户会话域,$UID 是当前用户的 ID
  • ~/Library/LaunchAgents/ai.openclaw.gateway.plist:服务配置文件的路径

执行输出:

 trae-sandbox 'launchctl bootstrap gui/$UID ~/Library/LaunchAgents/ai.openclaw.gateway.plist'
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.

(TraeAI-1) ~/Documents/dev/AI/hxops [5] $

步骤 6:检查 LaunchAgents 目录中的 plist 文件

执行命令:

ls -la ~/Library/LaunchAgents/ | grep openclaw

命令用途: 检查 LaunchAgents 目录中是否存在 OpenClaw 的配置文件。

命令详细解释:

  • ls -la:列出目录中的所有文件,包括隐藏文件和详细信息
  • ~/Library/LaunchAgents/:用户的 LaunchAgents 目录路径
  • |:管道符号,将前一个命令的输出传递给后一个命令
  • grep openclaw:筛选包含 "openclaw" 的行

执行输出:

 ls -la ~/Library/LaunchAgents/ | grep openclaw
-rw-r--r--@   1 teemo  staff  1613 Feb 19 23:00 ai.openclaw.gateway.plist

(TraeAI-1) ~/Documents/dev/AI/hxops [0] $

步骤 7:查看 plist 文件内容

执行命令:

cat ~/Library/LaunchAgents/ai.openclaw.gateway.plist

命令用途: 查看 Gateway 服务的配置文件内容,了解服务的具体配置。

命令详细解释:

  • cat:查看文件内容的命令
  • ~/Library/LaunchAgents/ai.openclaw.gateway.plist:配置文件的路径

执行输出:

 cat ~/Library/LaunchAgents/ai.openclaw.gateway.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>ai.openclaw.gateway</string>
    
    <key>Comment</key>
    <string>OpenClaw Gateway (v2026.2.15)</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
      <string>/opt/homebrew/bin/node</string>
      <string>/opt/homebrew/lib/node_modules/openclaw/dist/index.js</string>
      <string>gateway</string>
      <string>--port</string>
      <string>18789</string>
    </array>
    
    <key>StandardOutPath</key>
    <string>/Users/teemo/.openclaw/logs/gateway.log</string>
    <key>StandardErrorPath</key>
    <string>/Users/teemo/.openclaw/logs/gateway.err.log</string>
    <key>EnvironmentVariables</key>
    <dict>
    <key>HOME</key>
    <string>/Users/teemo</string>
    <key>PATH</key>
    <string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
    <key>OPENCLAW_GATEWAY_PORT</key>
    <string>18789</string>
    <key>OPENCLAW_GATEWAY_TOKEN</key>
    <string>a42c3bd4bf35ad4b10fed405e79a5b23c54d9b361933f9fd</string>
    <key>OPENCLAW_LAUNCHD_LABEL</key>
    <string>ai.openclaw.gateway</string>
    <key>OPENCLAW_SYSTEMD_UNIT</key>
    <string>openclaw-gateway.service</string>
    <key>OPENCLAW_SERVICE_MARKER</key>
    <string>openclaw</string>
    <key>OPENCLAW_SERVICE_KIND</key>
    <string>gateway</string>
    <key>OPENCLAW_SERVICE_VERSION</key>
    <string>2026.2.15</string>
    </dict>
  </dict>
</plist>

(TraeAI-1) ~/Documents/dev/AI/hxops [0] $

问题分析

问题现象

用户在尝试启动 OpenClaw Gateway 服务时遇到了以下错误:

Gateway service not loaded.
Start with: openclaw gateway install
Start with: openclaw gateway
Start with: launchctl bootstrap gui/$UID ~/Library/LaunchAgents/ai.openclaw.gateway.plist

排查结果

  1. OpenClaw 工具已正确安装,版本为 2026.2.15
  2. 尝试安装 Gateway 服务时遇到权限问题
  3. 使用 sudo 权限安装时遇到 Bootstrap 失败错误
  4. 尝试手动使用 launchctl 引导时遇到 I/O 错误
  5. LaunchAgents 目录中已存在 ai.openclaw.gateway.plist 文件
  6. plist 文件配置看起来正常,包含了正确的服务配置

可能的问题原因

  1. 权限问题:虽然使用了 sudo,但可能仍存在权限不足的问题
  2. 服务冲突:可能有其他服务占用了相同的端口或资源
  3. 配置文件问题:plist 文件可能存在隐藏的格式问题
  4. 系统兼容性问题:当前系统版本可能与 OpenClaw 版本不兼容

解决方案

日志分析

通过检查日志文件 ~/.openclaw/logs/gateway.err.log,发现了具体的错误原因:

2026-02-17T18:36:59.818+08:00 Gateway start blocked: set gateway.mode=local (current: unset) or pass --allow-unconfigured.
2026-02-17T18:36:59.821+08:00 Config write audit: /Users/teemo/.openclaw/logs/config-audit.jsonl

错误原因:Gateway 服务启动被阻止,因为缺少 gateway.mode 配置,当前状态为 "unset"。

建议尝试的步骤

  1. 设置 gateway.mode 配置:

    openclaw config set gateway.mode local
    
  2. 或者使用 --allow-unconfigured 参数启动:

    openclaw gateway start --allow-unconfigured
    
  3. 检查端口占用:

    lsof -i :18789
    
  4. 检查日志文件:

    ls -la ~/.openclaw/logs/
    cat ~/.openclaw/logs/gateway.err.log
    
  5. 尝试重新创建 plist 文件:

    rm ~/Library/LaunchAgents/ai.openclaw.gateway.plist
    openclaw gateway install
    
  6. 检查 Node.js 安装:

    node --version
    which node
    
  7. 尝试直接启动 Gateway:

    openclaw gateway
    

总结

本次排查过程中,我们:

  1. 创建了文档目录用于存放知识记录
  2. 确认了 OpenClaw 工具的版本
  3. 尝试了多种安装 Gateway 服务的方法
  4. 检查了服务配置文件的状态和内容
  5. 分析了可能的问题原因
  6. 检查了日志文件,发现了具体的错误原因
  7. 提供了详细的解决方案

通过检查日志文件,我们发现了 Gateway 服务启动失败的具体原因:缺少 gateway.mode 配置。这是一个关键的配置项,需要设置为 "local" 或者在启动时使用 --allow-unconfigured 参数。

关键知识点

  1. macOS 服务管理:

    • launchctl 是 macOS 系统的服务管理工具
    • 服务配置文件通常存放在 ~/Library/LaunchAgents/ 目录
  2. OpenClaw 服务管理:

    • openclaw gateway install 用于安装 Gateway 服务
    • openclaw gateway start 用于启动 Gateway 服务
    • openclaw config set 用于设置配置项
  3. OpenClaw 配置管理:

    • gateway.mode 是 Gateway 服务的必要配置项
    • 可以设置为 "local" 模式
    • 或者使用 --allow-unconfigured 参数跳过配置检查
  4. 权限管理:

    • sudo 命令可以临时获取管理员权限
    • 某些系统操作需要管理员权限才能执行
  5. 排错技巧:

    • 查看错误信息中的建议
    • 检查配置文件的内容和权限
    • 查看日志文件获取详细错误信息
    • 检查端口占用情况

实际操作与解决方案

执行的操作步骤

  1. 设置 gateway.mode 配置(需要 sudo 权限):

    sudo openclaw config set gateway.mode local
    

    执行输出:

    Config overwrite: /Users/teemo/.openclaw/openclaw.json (sha256 7f0b8d21cb7a93d63d1c88ac5283755466a910ca4e19d1437daf8db3059b1a84 -> b04724b773c7fa9308dd31b5e4fcb87de2f5dcffc4ed3dcb7eeb3b2e8ff4ce2f, backup=/Users/teemo/.openclaw/openclaw.json.bak)
    Updated gateway.mode. Restart the gateway to apply.
    
  2. 修复配置文件权限:

    sudo chown teemo:staff /Users/teemo/.openclaw/openclaw.json
    
  3. 启动 Gateway 服务:

    openclaw gateway
    

    执行输出:

    15:07:33 [canvas] host mounted at http://127.0.0.1:18789/__openclaw__/canvas/ (root /Users/teemo/.openclaw/canvas)
    15:07:34 [heartbeat] started
    15:07:34 [gateway] agent model: vllm//data/ai-platform/models/Qwen2.5-72B-Instruct-GPTQ-Int4
    15:07:34 [gateway] listening on ws://127.0.0.1:18789 (PID 95771)
    15:07:34 [gateway] listening on ws://[::1]:18789
    15:07:34 [gateway] log file: /tmp/openclaw/openclaw-2026-02-19.log
    15:07:34 [browser/service] Browser control service ready (profiles=2)
    

最终解决方案

根据实际操作,解决 OpenClaw Gateway 服务启动问题的完整步骤是:

  1. 设置 gateway.mode 配置(需要 sudo 权限):

    sudo openclaw config set gateway.mode local
    
  2. 修复配置文件权限:

    sudo chown teemo:staff /Users/teemo/.openclaw/openclaw.json
    
  3. 启动 Gateway 服务:

    openclaw gateway
    

替代方案:如果不想修改配置,也可以使用 --allow-unconfigured 参数启动:

openclaw gateway start --allow-unconfigured

服务状态

Gateway 服务已经成功启动,正在监听以下地址:

  • ws://127.0.0.1:18789
  • ws://[::1]:18789

服务运行正常,包含以下组件:

  • Canvas 服务
  • 心跳服务
  • 浏览器控制服务

注意:虽然有一个关于 cron 服务的权限错误和版本更新提示,但这些都不影响 Gateway 服务的核心功能。