OpenClaw 部署与调试

📝 OpenClaw 部署与调试笔记

📅 日期: 2026-02-06
💻 环境: Ubuntu 24.04 (远程服务器) + Windows (本地 Xshell)
🔧 核心软件: OpenClaw CLI (v2026.1.30)


1. 📂 关键路径与配置

  • 安装目录: ~/.openclaw (隐藏目录,需使用 ls -a 查看)
  • 配置文件: ~/.openclaw/openclaw.json
  • 关键参数:
    • Port: 18789
    • Bind: loopback (默认值,仅允许本地访问,勿改)
    • Token: Web 后台登录凭证 (位于 json 文件 auth.token 字段)

2. 🚫 错误排查记录 (Error Log)

❌ 错误 1: gateway.bind: Invalid input

  • 原因: 尝试使用 Vim 手动将配置文件中的 bind 修改为 "0.0.0.0""any"
  • 分析: 新版 OpenClaw 对配置校验严格,不支持手动修改该字段为非枚举值,导致程序启动失败并反复重启。
  • 解决: 使用 openclaw doctor --fix 自动将配置重置为默认合法状态。

❌ 错误 2: 无法通过公网 IP 访问

  • 原因: 程序默认绑定 127.0.0.1,且云服务器防火墙/安全组可能未开放端口。
  • 解决: 放弃修改服务器配置,改用 SSH 隧道 (Tunneling) 将服务器端口映射到本地。

❌ 错误 3: Connection closed / 网页无法访问

  • 原因: Xshell 窗口被关闭,或者因长时间无操作导致 SSH 会话断开,导致前台运行的 dashboard 进程终止。
  • 解决: 保持 Xshell 窗口开启,并开启“保持活动状态 (Keep Alive)”。

3. ✅ 最终解决方案 (标准操作流程)

第一步:环境修复

如果配置文件损坏或报错,先执行:

openclaw doctor --fix

第二步:配置 SSH 隧道 (Xshell 设置)

  1. 右键点击会话 -> 属性 (Properties) -> 连接 (Connection) -> SSH -> 隧道 (Tunneling)

  2. 点击 添加 (Add),填写如下规则:

    • 类型 (Type): Local (Outgoing) / 本地(拨出)

    • 源主机 (Source Host): localhost

    • 侦听端口 (Listen Port): 18789

    • 目标主机 (Destination Host): 127.0.0.1

    • 目标端口 (Destination Port): 18789

  3. 重要: 保存后必须断开并重新连接服务器才能生效。

第三步:启动服务

连接成功后,在终端执行:

Bash

openclaw dashboard

注意: 命令执行后会显示 Dashboard URL,请勿关闭此终端窗口

第四步:浏览器登录

在本地 Windows 电脑浏览器访问:

  • 地址: http://127.0.0.1:18789

  • 密码: 使用配置文件或终端显示的 Token 登录。


4. 🛠️ 常用命令速查 (Cheatsheet)

命令 描述
openclaw dashboard 启动 Web 管理面板 (需保持前台运行)
openclaw doctor --fix 急救命令:自动检测并修复配置错误
openclaw configure 交互式配置向导 (设置密码、设备等)
openclaw logs 查看网关运行日志
ls -a 列出所有文件 (包含 .openclaw 等隐藏文件)
cat ~/.openclaw/openclaw.json 查看配置文件内容 (获取 Token)

可执行文件丢失

🚀 第一步:安装 cnpm

先执行:

npm install -g cnpm --registry=https://registry.npmmirror.com

等它装完。


🚀 第二步:用 cnpm 安装 openclaw

cnpm 方案,在国内环境一般会明显快很多

cnpm install -g openclaw

🚀 第三步:验证

which openclaw openclaw --version

如果能输出路径和版本号,就说明恢复成功

注意事项和日常命令

配置环境变量(避免API Key泄露)

为降低泄露风险,将API Key配置到系统环境变量,而非直接写入文件:

  1. 确认Shell类型:终端输入echo $SHELL,判断为zsh或bash;
  2. zsh用户配置:
    • 输入命令(替换“YOUR_DASHSCOPE_API_KEY”为实际API Key):echo "export DASHSCOPE_API_KEY='YOUR_DASHSCOPE_API_KEY'" >> ~/.zshrc
    • 执行source ~/.zshrc使配置生效;
    • 验证:重新打开终端,输入echo $DASHSCOPE_API_KEY,输出API Key即成功;
  3. bash用户配置:
    • 输入命令(替换实际API Key):echo "export DASHSCOPE_API_KEY='YOUR_DASHSCOPE_API_KEY'" >> ~/.bash_profile
    • 执行source ~/.bash_profile生效;
    • 验证:重新打开终端,输入echo $DASHSCOPE_API_KEY,输出API Key即成功。

编辑OpenClaw配置文件

OpenClaw模型配置需按指定格式写入~/.clawdbot/clawdbot.json,字段严格校验,写错可能导致Gateway启动失败,提供两种模型配置模板:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
{

  "meta": {

    "lastTouchedVersion": "2026.1.30",

    "lastTouchedAt": "2026-02-06T20:07:20.472Z"

  },

  "wizard": {

    "lastRunAt": "2026-02-06T20:07:20.451Z",

    "lastRunVersion": "2026.1.30",

    "lastRunCommand": "onboard",

    "lastRunMode": "local"

  },

  "auth": {

    "profiles": {

      "qwen-portal:default": {

        "provider": "qwen-portal",

        "mode": "oauth"

      }

    }

  },

  "models": {

    "mode": "merge",

    "providers": {

      "qwen-portal": {

        "baseUrl": "https://portal.qwen.ai/v1",

        "apiKey": "qwen-oauth",

        "api": "openai-completions",

        "models": [

          {

            "id": "qwen-portal/coder-model",

            "name": "Qwen Coder",

            "reasoning": false,

            "input": [

              "text"

            ],

            "cost": {

              "input": 0,

              "output": 0,

              "cacheRead": 0,

              "cacheWrite": 0

            },

            "contextWindow": 128000,

            "maxTokens": 8192

          },

          {

            "id": "qwen-portal/vision-model",

            "name": "Qwen Vision",

            "reasoning": false,

            "input": [

              "text",

              "image"

            ],

            "cost": {

              "input": 0,

              "output": 0,

              "cacheRead": 0,

              "cacheWrite": 0

            },

            "contextWindow": 128000,

            "maxTokens": 8192

          }

        ]

      },

      "nvidia": {

        "baseUrl": "https://integrate.api.nvidia.com/v1",

        "apiKey": "nvapi-AAA",

        "api": "openai-completions",

        "models": [

          {

            "id": "nvidia/minimaxai/minimax-m2.1",

            "name": "minimax-m2.1",

            "reasoning": false,

            "input": [

              "text"

            ],

            "cost": {

              "input": 0.0025,

              "output": 0.01,

              "cacheRead": 0,

              "cacheWrite": 0

            },

            "contextWindow": 262144,

            "maxTokens": 65536

          }

        ]

      }

    }

  },

  "agents": {

    "defaults": {

      "model": {

        "primary": "nvidia/minimaxai/minimax-m2.1"

      },

      "models": {

        "qwen-portal/coder-model": {

          "alias": "qwen"

        },

        "qwen-portal/vision-model": {},

        "nvidia/minimaxai/minimax-m2.1": {

          "alias": "minimax"

        }

      },

      "workspace": "/root/.openclaw/workspace",

      "compaction": {

        "mode": "safeguard"

      },

      "maxConcurrent": 4,

      "subagents": {

        "maxConcurrent": 8

      }

    }

  },

  "messages": {

    "ackReactionScope": "group-mentions"

  },

  "commands": {

    "native": "auto",

    "nativeSkills": "auto"

  },

  "hooks": {

    "internal": {

      "enabled": true,

      "entries": {

        "boot-md": {

          "enabled": true

        },

        "command-logger": {

          "enabled": true

        },

        "session-memory": {

          "enabled": true

        }

      }

    }

  },

  "channels": {

    "qqbot": {

      "enabled": true,

      "appId": "123",

      "clientSecret": "AAA"

    }

  },

  "gateway": {

    "port": 18789,

    "mode": "local",

    "bind": "loopback",

    "auth": {

      "mode": "token",

      "token": "AAA"

    },

    "tailscale": {

      "mode": "off",

      "resetOnExit": false

    }

  },

  "skills": {

    "install": {

      "nodeManager": "npm"

    }

  },

  "plugins": {

    "entries": {

      "qwen-portal-auth": {

        "enabled": true

      },

      "qqbot": {

        "enabled": true

      }

    }

  }

}

注册模型:

Run openclaw configure or set an API key env var.

模型连通探测(真实请求验证)

输入openclaw models status –probe`(会产生模型调用费用),若“Status”显示“ok”,说明模型调用正常;若失败,检查API Key有效性、环境变量配置或网络连接。

重启OpenClaw Gateway

终端输入openclaw gateway restart`,阿里云部署可通过“命令助手”远程执行,重启成功会显示“Restarted LaunchAgent”提示。

日志抓取

1
openclaw logs --follow
作者

K.S.J

发布于

2026-02-01

更新于

2026-02-28

许可协议