OpenClaw服务器部署保姆级教程

0 阅读7分钟

OpenClaw是什么

OpenClaw不仅仅是一个聊天机器人,更是一个跨平台的个人AI操作系统。OpenClaw提出了一种“自带设备(BYOD)”的运行模式,核心组件运行在用户控制的Mac Mini、Linux服务器或树莓派上,而将推理任务通过API外包给Claude Opus、GPT-4或本地开源模型。这种架构不仅确保了用户对记忆和数据的完全掌控,还赋予了AI深度访问本地文件系统、Shell和浏览器的能力,使其成为真正意义上的“数字副驾驶”。

OpenClaw架构图:

OpenClaw如何运作?

img

关键理解: OpenClaw 不是一个 AI 模型,而是一个「AI 网关」——它负责连接你的聊天软件和 AI 大模型 API,让 AI 能力无缝融入日常沟通工具。

与传统网页版AI(例如ChatGPT 或 Claude)不同,OpenClaw 直接运行在你常用的聊天软件里——你在飞书发消息,它在飞书回复;你在 Discord 提问,它在 Discord 解答;你在飞书提问,他在飞书给出执行结果。

核心架构解析:Gateway和Nodes的协同

OpenClaw采用了以网关为中心(Gateway-Centric)的分布式微服务架构。这种设计不仅解耦了通信通道与智能体逻辑,还实现了对多模态输入输出的统一管理。

img

具体的讲解在飞书文档里,本篇主要介绍如何在服务器上部署

服务器部署:

What you need

  • Node.js — Node 24 recommended (Node 22.16+ also supported)
  • An API key from a model provider (Anthropic, OpenAI, Google, etc.) — onboarding will prompt you
  1. 需要先在服务器上安装node,因为OpenClaw是由ts和js编写的,必须要有node.js环境

使用nvm对node进行版本管理

 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
 ​
 nvm install 24
 nvm use 24

2. 在服务器上安装OpenClaw

官网推荐的下载方式:

 curl -fsSL https://openclaw.ai/install.sh | bash 

但是服务器是国内的,没法翻墙,所以下载速度会非常慢,超时失败。所以可以采用docker或者npm的方式下载,给npm配置国内镜像源。我使用的是淘宝镜像源

 #查看当前使用的镜像源
 npm config get registry
 #输出:https://registry.npmjs.org/(官方默认镜像源)
 ​
 #配置淘宝镜像源
 npm config set registry https://registry.npmmirror.com

下一步:使用npm安装OpenClaw,非常的迅速!

 npm install -g openclaw@latest

3. 根据提示设置安装设置

 openclaw onboard --install-daemon

坑点:

  1. 在安装成功后,提示你可以打开controlUI查看OpenClaw了,地址是http://127.0.0.1:18789/,但是如果是在服务器上安装的可能打不开。因为这是服务器的本地环回地址,在你的电脑上相当于是远程访问服务器,所以必须使用服务器的ip地址,访问http://服务器ip:18789(⚠️:这一步要在云服务器的控制台上配置安全组规则,开放18789端口,否则外部无法访问到)

  2. 现在把端口改好了,但是依旧打不开页面。答案就在飞书文档里:

image-20260323143449133.png 查看一下openclaw的gateway配置

```
 "gateway": {
     "port": 18789,
     "mode": "local",
     "bind": "loopback",
 }
```

果然问题就在这里。gateway默认绑定在本地环回地址,不直接向公网暴露端口,所以你通过公网ip是访问不了的。这时需要把bind改成"lan"(0.0.0.0)绑定所有网卡,这样外部设备就可以和你的服务器建立底层连接,比如飞书服务器就可以通过公网ip访问到你服务器上的openclaw了。

3. 此时应该可以打开页面了,但是当你填入token后连接时又会报错:

`origin not allowed (open the Control UI from the gateway host or allow it in gateway.controlUi.allowedOrigins)`

这是为什么🤔

根据提示找到了问题就是gateway的配置:gateway.controlUi.allowedOrigins

查看~/.openclaw/openclaw.json配置文件就会发现gateway中并没有controlUi的配置,默认的controlUi也是仅限本地地址访问,想要访问必须把当前服务器的公网ip加入到白名单中

 "controlUi": {
       "allowedOrigins": [
         "http://localhost:18789",
         "http://127.0.0.1:18789",
         "http://xx.xx.xx.xx:18789"
       ],

4. 现在终于好了吧!点击connect,报错control ui requires device identity (use HTTPS or [localhost](https://localhost/) secure context)

这个报错说明不让使用http访问,必须用https或者localhost

  • 方案一:用ssh转发

    在本地电脑使用ssh登录远程服务器,进行端口转发,这样把本地的localhost转发到服务器相应端口,最推荐的方式

     ssh -N -L 18789:127.0.0.1:18789 <用户名>@<服务器公网IP>
    

    然后直接访问http://localhost:18789就可以成功!

  • 方案二:用http直接访问

    此方法就是把controlUi的安全验证干掉,在配置里加就好了

    "controlUi": {
          "allowedOrigins": [
            "http://localhost:18789",
            "http://127.0.0.1:18789",
            "http://xx.xx.xx:18789"
          ],
          "allowInsecureAuth": true,
          "dangerouslyDisableDeviceAuth": true
        },
    

    这样配置好后,可以直接访问公网ip:18789,成功连接!

  • 方案三:(正规渠道)Nginx 反向代理 + HTTPS,使用域名访问

好了,这一步结束就可以打开controlUi了!现在可以给你的openclaw发消息试试

然后可以给你的openclaw起一个名字,这样就算是安装成功了

注意: 前面的bindmode和controlUi都遇到了打不开的情况,进行了两次配置,但这两个是不同层面的检测。bindmode是网络层检验,如果没有配好外部服务器和你的服务器上的openclaw是无法连接的,比如无法通过飞书服务器连接到你的服务器。但是controlUi连接不上是应用层管理后台无法打开,但是其他外部服务器可以访问此服务器,两者是不同的。

  1. openclaw安装好之后再来安装飞书插件

    npx -y @larksuite/openclaw-lark install
    
  2. 安装好插件后,需要在飞书开放平台进行配置

飞书开放平台:open.feishu.cn/app?lang=zh…

新建企业自建应用

路径: 创建应用 → 企业自建应用

启用机器人能力

在 添加应用能力 > 机器人 页面:

  1. 开启机器人能力
  2. 配置机器人相关设置

配置应用权限

在 权限管理 页面,点击 批量导入 按钮,粘贴以下 JSON 配置一键导入所需权限。

{
  "scopes": {
    "tenant": [
      "contact:contact.base:readonly",
      "docx:document:readonly",
      "im:chat:read",
      "im:chat:update",
      "im:message.group_at_msg:readonly",
      "im:message.p2p_msg:readonly",
      "im:message.pins:read",
      "im:message.pins:write_only",
      "im:message.reactions:read",
      "im:message.reactions:write_only",
      "im:message:readonly",
      "im:message:recall",
      "im:message:send_as_bot",
      "im:message:send_multi_users",
      "im:message:send_sys_msg",
      "im:message:update",
      "im:resource",
      "application:application:self_manage",
      "cardkit:card:write",
      "cardkit:card:read"
    ],
    "user": [
      "contact:user.employee_id:readonly",
      "offline_access","base:app:copy",
      "base:field:create",
      "base:field:delete",
      "base:field:read",
      "base:field:update",
      "base:record:create",
      "base:record:delete",
      "base:record:retrieve",
      "base:record:update",
      "base:table:create",
      "base:table:delete",
      "base:table:read",
      "base:table:update",
      "base:view:read",
      "base:view:write_only",
      "base:app:create",
      "base:app:update",
      "base:app:read",
      "board:whiteboard:node:create",
      "board:whiteboard:node:read",
      "calendar:calendar:read",
      "calendar:calendar.event:create",
      "calendar:calendar.event:delete",
      "calendar:calendar.event:read",
      "calendar:calendar.event:reply",
      "calendar:calendar.event:update",
      "calendar:calendar.free_busy:read",
      "contact:contact.base:readonly",
      "contact:user.base:readonly",
      "contact:user:search",
      "docs:document.comment:create",
      "docs:document.comment:read",
      "docs:document.comment:update",
      "docs:document.media:download",
      "docs:document:copy",
      "docx:document:create",
      "docx:document:readonly",
      "docx:document:write_only",
      "drive:drive.metadata:readonly",
      "drive:file:download",
      "drive:file:upload",
      "im:chat.members:read",
      "im:chat:read",
      "im:message",
      "im:message.group_msg:get_as_user",
      "im:message.p2p_msg:get_as_user",
      "im:message:readonly",
      "search:docs:read",
      "search:message",
      "space:document:delete",
      "space:document:move",
      "space:document:retrieve",
      "task:comment:read",
      "task:comment:write",
      "task:task:read",
      "task:task:write",
      "task:task:writeonly",
      "task:tasklist:read",
      "task:tasklist:write",
      "wiki:node:copy",
      "wiki:node:create",
      "wiki:node:move",
      "wiki:node:read",
      "wiki:node:retrieve",
      "wiki:space:read",
      "wiki:space:retrieve",
      "wiki:space:write_only"
    ]
  }
}

更新应用 Token

回到 凭证与基础信息 页面,将黄色区域中的 App ID / App Secret / Token 同步更新到 OpenClaw 配置中

openclaw config set channels.feishu.appId "<App_ID>"
openclaw config set channels.feishu.appSecret "<App_Secret>"
openclaw config set channels.feishu.enabled true
openclaw config set channels.feishu.connectionMode websocket
openclaw config set channels.feishu.dmPolicy pairing
openclaw config set channels.feishu.groupPolicy allowlist
openclaw config set channels.feishu.requireMention true

重启生效:

openclaw gateway restart

⚠️设置事件回调(Callback)

这一步至关重要!!!

⚠️ 重要提醒:在配置事件订阅前,请务必确保已完成以下步骤:

  1. 运行 openclaw channels add 添加了 Feishu 渠道
  2. 网关处于启动状态(可通过 openclaw gateway status 检查状态)

在 事件订阅 页面:

  1. 选择 使用长连接接收事件(WebSocket 模式)
  2. ⚠️添加事件:im.message.receive_v1(接收消息) 这一步一定不能忘,否则发送消息不会触发回调

⚠️ 注意:如果网关未启动或渠道未添加,长连接设置将保存失败。 image-20260323153235158.png

发布应用

  1. 在 版本管理与发布 页面创建版本

  2. 提交审核并发布

  3. 等待管理员审批(企业自建应用通常自动通过)

  4. 对飞书插件进行配置:

    可以直接修改配置文件:

    {
      "channels": {
        "feishu": {
          "enabled": true,
          "appId": "cli_你的AppID",
          "appSecret": "你的AppSecret",
          "requireMention": true
          "groupPolicy": "allowlist",
          "groupAllowFrom": ["ou_XXXX"]"groups": { "*": { enabled: true } }
        }
      }
    }
    

    或者通过命令行进行单行修改

    # 设置需要 @ 才回复
    openclaw config set channels.feishu.requireMention true --json
    # 重启生效
    sh /workspace/projects/scripts/restart.sh
    
  5. 现在应该已经成功啦!可以把机器人拉进群@他玩

本文参考资料:

飞书openclaw详解:www.feishu.cn/content/art…

飞书插件使用方法:bytedance.larkoffice.com/docx/MFK7dD…

官方教程:docs.openclaw.ai/start/getti…

参考:zhuanlan.zhihu.com/p/201255799…