文章概要
本文提供了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:修改配置文件后生效
-
编辑配置:
vi ~/.openclaw/openclaw.json -
重启服务:
systemctl --user restart openclaw-gateway -
确认状态:
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
-
停止并禁用服务:
bashsystemctl --user stop openclaw-gateway systemctl --user disable openclaw-gateway -
删除Node模块:
bashnpm uninstall -g openclaw # 或手动删除 rm -rf /usr/lib/node_modules/openclaw rm /usr/bin/openclaw -
删除配置和日志:
bashrm -rf ~/.openclaw rm -rf /tmp/openclaw rm ~/.config/systemd/user/openclaw-gateway.service systemctl --user daemon-reload