OpenClaw常用命令速查与操作指南

文章概要

本文提供了OpenClaw系统的常用命令速查手册,涵盖核心状态与诊断命令、服务管理命令、配置与文件路径速查,以及常见运维场景实操。通过本手册,用户可以快速掌握OpenClaw系统的日常运维和操作技巧,实现高效的系统部署、设备管理和实时监控。


1. 核心状态与诊断命令

1.1 核心状态解读

使用openclaw gateway status命令查看网关状态,示例输出如下:

bash
🦞 OpenClaw 2026.2.3-1 (d84eb46) — If it works, it's automation; if it breaks, it's a "learning opportunity."
│◇ Service: systemd (enabled)
File logs: /tmp/openclaw/openclaw-2026-03-02.log
Command: /usr/bin/node /usr/lib/node_modules/openclaw/dist/index.js gateway --port 18789
Service file: ~/.config/systemd/user/openclaw-gateway.service
Service env: OPENCLAW_GATEWAY_PORT=18789
Config (cli): ~/.openclaw/openclaw.json
Config (service): ~/.openclaw/openclaw.json
Gateway: bind=lan (0.0.0.0), port=18789 (service args)
Probe target: ws://127.0.0.1:18789
Dashboard: http://127.0.0.1:18789/
Probe note: Local probe uses loopback (127.0.0.1). bind=lan listens on 0.0.0.0 (all interfaces); use a LAN IP for remote clients.
Runtime: running (pid 1090355, state active, sub running, last exit 0, reason 0)
RPC probe: ok
Troubles: run openclaw status
Troubleshooting: https://docs.openclaw.ai/troubleshooting

关键信息解读

  • 运行状态Runtime: running (PID 1090355)表示服务正在运行。

  • 启动方式Service: systemd (enabled)表示服务以用户级systemd服务运行。

  • 监听地址Gateway: bind=lan (0.0.0.0), port=18789表示服务监听所有网络接口,局域网内其他机器可直接访问。

  • 配置文件位置~/.openclaw/openclaw.json

  • 日志文件位置/tmp/openclaw/openclaw-2026-03-02.log

1.2 常用诊断命令

  • openclaw probe status:检查OpenClaw是否能成功连接到后端的AI模型或工具。

  • openclaw status:运行全面的自我诊断,报告潜在问题。

  • openclaw --version:查看当前安装的版本号。

  • openclaw --help:查看所有可用命令列表。

  • openclaw gateway --help:查看gateway子命令的具体用法。


2. 服务管理命令 (Systemd User Mode)

由于服务文件位于~/.config/systemd/user/,不需要sudo权限,但必须使用--user标志。

常用命令

  • 重启服务systemctl --user restart openclaw-gateway

  • 停止服务systemctl --user stop openclaw-gateway

  • 启动服务systemctl --user start openclaw-gateway

  • 查看实时日志journalctl --user -u openclaw-gateway -f

  • 查看最近日志journalctl --user -u openclaw-gateway -n 50

  • 开机自启

    • 启用:systemctl --user enable openclaw-gateway

    • 配合loginctl enable-linger root确保root用户注销SSH后服务依然运行。

  • 取消自启systemctl --user disable openclaw-gateway

  • 重载配置systemctl --user daemon-reload(修改service文件后需运行)


3. 配置与文件路径速查

根据状态输出,关键文件位置如下:

  • 主配置文件~/.openclaw/openclaw.json(修改端口、绑定IP、API Key等核心参数,修改后需重启服务)

  • 日志文件/tmp/openclaw/openclaw-YYYY-MM-DD.log(重要日志建议备份)

  • 服务定义文件~/.config/systemd/user/openclaw-gateway.service(一般不需要手动修改)

  • 程序源码/usr/lib/node_modules/openclaw(一般无需触碰)

  • 启动命令/usr/bin/node ...(实际运行的底层命令)


4. 常见运维场景实操

场景A:修改配置文件后生效

  1. 编辑配置:vi ~/.openclaw/openclaw.json

  2. 重启服务:systemctl --user restart openclaw-gateway

  3. 确认状态:openclaw gateway status

场景B:服务启动失败查看报错

  • 实时查看报错日志:journalctl --user -u openclaw-gateway -f

  • 查看具体日志文件:tail -f /tmp/openclaw/openclaw-$(date +%Y-%m-%d).log

场景C:忘记Token重新获取

  • 在日志中搜索token:grep "token" /tmp/openclaw/openclaw-$(date +%Y-%m-%d).log

  • 或使用journalctl:journalctl --user -u openclaw-gateway | grep "token"

场景D:彻底卸载OpenClaw

  1. 停止并禁用服务:

    bash
    
    systemctl --user stop openclaw-gateway
    systemctl --user disable openclaw-gateway
    
    
  2. 删除Node模块:

    bash
    
    npm uninstall -g openclaw
    # 或手动删除
    rm -rf /usr/lib/node_modules/openclaw
    rm /usr/bin/openclaw
    
    
  3. 删除配置和日志:

    bash
    
    rm -rf ~/.openclaw
    rm -rf /tmp/openclaw
    rm ~/.config/systemd/user/openclaw-gateway.service
    systemctl --user daemon-reload
    
    

太真实了!上周刚折腾完部署,兴奋了半小时后发现不知道用来干啥,最后沦为了套壳的翻译器:joy:。crontab那个思路刚好救大命,晚上回去就把定时任务跑起来,感谢楼主分享!

常用命令一目了然

命令速查手册收藏了

速查表太实用了,打印出来贴工位上随时看,比翻文档快多了

命令速查建议加上常见错误码和对应解决方案,这样更完整

终于有人整理命令大全了!以前每次都要去翻官方文档特别麻烦

建议做成交互式的命令手册,支持搜索和筛选,比静态文档好用

@qvace 错误码对应方案这个需求大 最常见的几个:E001是API Key无效、E002是模型不支持、E003是Token超限、E004是网络超时 每个都有不同的解决方法

@bxdev 交互式命令手册可以用docusaurus搭一个 支持搜索和分类 比markdown文件方便多了 社区有人做过类似的 可以参考

常用命令速查很实用