🚀 OpenClaw 部署与配置记录

日期:2026年5月30日 23:00 — 5月31日 00:15 (CST)

服务器:VM-0-2-ubuntu · Linux 6.8.0-71-generic · 宝塔面板

域名:oc.allinai.uno → Nginx 反代 → OpenClaw Gateway

📋 最终架构

组件配置
Gatewaysystemd user service,端口 19920,loopback 模式
Nginx反代 127.0.0.1:19920,SSL + WebSocket 支持
Control UIhttps://oc.allinai.uno,token 认证
Agent: main模型 zai/glm-5.1(智谱),工作目录 ~/.openclaw/workspace
Agent: STBOT 🤖模型 sensenova/sensenova-6.7-flash-lite(商汤),绑定 Discord「商汤」频道
Discord Bot@虾搞,Guild: 虾搞,Channel: 商汤

🕐 操作时间线

~23:00 — Gateway 未启动

访问 oc.allinai.uno 返回 502 Bad Gateway。排查发现 Nginx 配置正确(反代到 127.0.0.1:19920),但 Gateway 进程未运行,端口无人监听。

~23:10 — 启动 Gateway

首次使用 nohup openclaw gateway & 手动启动,502 消除,页面返回 200。但这种方式重启后会丢失。

~23:13 — 安装 systemd 服务

执行 openclaw gateway install,注册为 systemd user service,实现开机自启。

注意:需要先执行 sudo loginctl enable-linger root 和设置 XDG_RUNTIME_DIR,否则 systemd user session 不可用。
~23:15 — Control UI 来源被拒绝

浏览器访问 oc.allinai.uno 提示「浏览器来源不被允许」。需要在配置中添加 gateway.controlUi.allowedOrigins

~23:16 — 修复 Control UI

在 openclaw.json 中添加:

"controlUi": {
  "allowedOrigins": ["https://oc.allinai.uno"]
}

重启后 Control UI 正常访问。

~23:30 — 配置 SenseNova API Provider

添加商汤 SenseNova 作为模型提供商。在 openclaw.json 和 auth-profiles.json 中配置 provider、模型列表和 API Key。

踩坑:SenseNova 有两套 API 地址。旧文档指向 api.sensenova.cn/compatible-mode/v2,实际 platform.sensenova.cn 的新平台应使用 token.sensenova.cn/v1。用错地址会返回 401/403。
~23:37 — 创建 STBOT Agent

创建 sensenova-agent(后命名为 STBOT 🤖),配置独立的 workspace、auth 和模型。

openclaw agents add sensenova-agent \
  --model "sensenova/sensenova-6.7-flash-lite" \
  --workspace "/bingo2026/.openclaw/workspace-sensenova"

openclaw agents set-identity --agent sensenova-agent --name "STBOT" --emoji "🤖"
~23:40 — Discord 频道绑定问题

最初用 _default 作为 Guild ID,导致频道无法解析。日志显示 channels unresolved

错误:使用了虚拟的 _default guild,Discord 需要真实的服务器 ID。

修改为真实 Guild ID 1510296477338046554 后,频道解析成功:channels resolved: 虾搞/商汤

~23:48 — Discord Bot 不响应频道消息

Bot 在线但跳过所有频道消息,日志:skipping guild message (reason: no-mention)

原因一:频道默认 requireMention: true,需要 @bot 才触发。

设置 requireMention: false 后消息能收到。

原因二:日志持续提示 Message Content Intent is limited,但 Developer Portal 中已开启。实际不影响功能(limited 只是提示,bot <100 服务器可正常使用)。

~23:56 — Agent 路由错误

消息被路由到 main agent(智谱模型)而非 STBOT(商汤模型)。

原因:binding 格式 discord:1510296478214520926 被当成 accountId 而非频道 ID。Discord 的 account 是 bot 自身。

解决:使用 peer match 绑定方式:

"bindings": [
  {
    "agentId": "sensenova-agent",
    "match": {
      "channel": "discord",
      "accountId": "default",
      "peer": { "kind": "group", "id": "1510296478214520926" }
    }
  }
]
~00:00 — SenseNova API 返回 403/401

STBOT 路由正确,但商汤 API 返回 HTTP 401/403 Forbidden

根因一:Base URL 错误,使用了旧地址 api.sensenova.cn/compatible-mode/v2

根因二:API Key 格式问题,聊天中发送的 key 包含省略号占位符。

最终确认正确的 API 地址为 https://token.sensenova.cn/v1,配合完整 API Key 后 curl 测试返回 200。

~00:15 — 全部搞定 ✅

Discord「商汤」频道消息 → STBOT(sensenova-6.7-flash-lite)→ 正常回复。

🔧 关键配置文件

openclaw.json(核心配置摘要)

{
  "gateway": {
    "port": 19920,
    "bind": "loopback",
    "controlUi": {
      "allowedOrigins": ["https://oc.allinai.uno"]
    }
  },
  "models": {
    "providers": {
      "sensenova": {
        "baseUrl": "https://token.sensenova.cn/v1",
        "api": "openai-completions",
        "models": [
          { "id": "sensenova-6.7-flash-lite", ... },
          { "id": "sensenova-u1-fast", ... },
          { "id": "deepseek-v4-flash", ... }
        ]
      }
    }
  },
  "bindings": [
    {
      "agentId": "sensenova-agent",
      "match": {
        "channel": "discord",
        "accountId": "default",
        "peer": { "kind": "group", "id": "频道ID" }
      }
    }
  ],
  "channels": {
    "discord": {
      "groupPolicy": "allowlist",
      "guilds": {
        "服务器ID": {
          "requireMention": false,
          "channels": {
            "频道ID": { "enabled": true, "requireMention": false }
          }
        }
      }
    }
  }
}

📚 经验总结

SenseNova API 地址:新平台用 https://token.sensenova.cn/v1,旧平台用 https://api.sensenova.cn/compatible-mode/v2。以 platform.sensenova.cn 的文档为准。
Discord 多 Agent 路由:使用 bindings 配合 peer match 来绑定特定频道到特定 Agent,不要用频道 ID 作为 accountId。
Discord 频道白名单:guilds 配置必须使用真实的服务器 ID,不能用 _default 占位。
Gateway 持久化:使用 openclaw gateway install 注册 systemd 服务,配合 loginctl enable-linger 确保重启后自动运行。
Discord Message Content Intent:日志提示 "limited" 不代表完全不可用,bot 服务器数 <100 时可正常工作。但建议在 Developer Portal 中开启。
API Key 安全:聊天中发送的 key 可能被截断或脱敏显示。建议直接在服务器上编辑配置文件,或确认复制的 key 完整无误。

📁 文件路径速查

文件路径
主配置~/.openclaw/openclaw.json
main agent 认证~/.openclaw/agents/main/agent/auth-profiles.json
STBOT agent 认证~/.openclaw/agents/sensenova-agent/agent/auth-profiles.json
STBOT workspace/bingo2026/.openclaw/workspace-sensenova/
Nginx 配置/www/server/panel/vhost/nginx/oc.allinai.uno.conf
systemd 服务~/.config/systemd/user/openclaw-gateway.service
日志/tmp/openclaw/openclaw-2026-05-30.log

⚡ 常用命令

操作命令
启动终端对话openclaw chat
重启 Gatewaysystemctl --user restart openclaw-gateway.service
查看状态openclaw status
查看日志journalctl --user -u openclaw-gateway.service -f
查看 Agent 列表openclaw agents list --bindings
频道状态openclaw channels status --probe