【Agent】Ubuntu22.04安装部署Openclaw(养龙虾)图文教程及免费Token攻略

【Agent】Ubuntu22.04安装部署Openclaw(养龙虾)图文教程及免费Token攻略

1.安装Ubuntu22.04系统

安装部署Openclaw所需硬件基本配置如下:

可以参考虚拟机安装Ubuntu22.04系统安装系统。

2.配置网络源

安装好系统后,依次执行以下命令修改网络源:

bash 复制代码
# 1.备份网络源配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 2.修改网络源配置文件
sudo tee /etc/apt/sources.list <<-'EOF'
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
EOF
# 3.导入22.04官方公钥(无弃用警告)
sudo curl -fsSL https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3B4FE6ACC0B21F32 | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/ubuntu-official.gpg
# 4.清理缓存并更新
sudo apt clean && sudo apt update

3.安装ssh服务支持远程部署(可不安装)

依次执行以下命令安装ssh服务:

bash 复制代码
# 1.安装SSH服务(必须装这个才能被其他设备远程连接)
sudo apt install openssh-server -y
# 2.立即启动SSH服务
sudo systemctl start ssh
# 3.设置开机自启(重启电脑也能用)
sudo systemctl enable ssh
# 4.查看SSH状态
sudo systemctl status ssh

4.获取api-key

【AI工具】免费获取各类AI大模型APIKEY的使用教程,以硅基流动+Deepseek为例

我本次用的是OpenRouter的**"openrouter/stepfun/step-3.5-flash:free",、"openrouter/qwen/qwen3-coder:free"、"openrouter/z-ai/glm-4.5-air:free"**等免费模型

5.安装配置Openclaw

执行命令:curl -fsSL https://openclaw.ai/install.sh | bash

这个安装脚本会自动帮你搞定所有依赖(Node.js、Git......),然后直接进入交互式配置向导。

配置选择如下:

剩下的几个配置先跳过

6.安装过程中的问题解决

执行openclaw gateway status检查openclaw状态为未启动

修复步骤如下:

1.解决 Gateway service not installed

1.执行openclaw gateway install安装 OpenClaw 系统服务()

2.执行openclaw gateway start启动网关服务

3.执行openclaw gateway enable设置开机自启

4.执行openclaw gateway status查看网关状态

2.解决RPC probe: failed(Gateway start blocked: set gateway.mode=local (current: unset) or pass --allow-unconfigured.)

根据 openclaw gateway status 输出,服务本身已安装并显示正在运行,但关键的 RPC 连接失败,且端口 18789 并未真正监听。这与官方文档中"Gateway will not start or service installed but not running"一节描述的情况高度吻合。

执行journalctl --user -u openclaw-gateway.service -n 50 --no-pager -f可以看到详细的报错信息:

日志显示 gateway 启动被阻止,原因是 "Gateway start blocked: set gateway.mode=local (current: unset) or pass --allow-unconfigured."。这意味着配置文件中的 gateway.mode 没有设置,导致启动被阻止。这与我们之前的分析一致,服务虽然 systemd 启动,但进程初始化失败退出(status 1),然后 systemd 不断重启(restart counter 增加)。日志中还提到 lsof failed,但这是次要的,核心是 mode 未设置

按以下步骤完成配置:

bash 复制代码
# 1.编辑配置文件
nano ~/.openclaw/openclaw.json
# 2.添加/修改 gateway.mode 字段(注意:记住这里的token配置,后面登录会用到)
{
  "gateway": {
    "port": 18789,
    "mode": "local"
    "auth": {
      // 这里只放认证相关字段,如 "token" 或 "password"
    }
  },
  // 其他配置...
}
# 3.保存文件并退出编辑器(nano 中按 Ctrl+O 保存,Ctrl+X 退出)。
# 4.重启 gateway 服务
systemctl --user restart openclaw-gateway
# 5.检查服务状态
openclaw gateway status

可以看到Openclaw正常启动了。

3.解决unauthorized: gateway token mismatch (open the dashboard URL and paste the token in Control UI settings)

执行openclaw dashboard --no-open生成包含正确令牌的仪表盘 URL

打开url地址,看到以下页面:

连接失败时,执行nano ~/.openclaw/openclaw.json,将其中的token配置项的值复制到网关令牌中即可连接成功

7. 配置模型和apikey

执行nano ~/.openclaw/openclaw.json编辑openclaw配置文件。可以参考以下配置(替换自己想用的模型和apikey)

bash 复制代码
{
  "meta": {
    "lastTouchedVersion": "2026.3.13",
    "lastTouchedAt": "2026-03-18T08:49:59.347Z"
  },
  "wizard": {
    "lastRunAt": "2026-03-18T08:37:25.135Z",
    "lastRunVersion": "2026.3.13",
    "lastRunCommand": "configure",
    "lastRunMode": "local"
  },
  "auth": {
    "profiles": {
      "openrouter:default": {
        "provider": "openrouter",
        "mode": "api_key"
      }
    }
  },
  "env": { 
  	"OPENROUTER_API_KEY": "sk-orxxxxxxxxxxxxxxxxxxxxxxxxxx替换为自己的apikey" 
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "openrouter/auto",
        "fallbacks": [
          "openrouter/stepfun/step-3.5-flash:free",
          "openrouter/qwen/qwen3-coder:free",
          "openrouter/z-ai/glm-4.5-air:free"
        ]
      },
      "models": {
        "openrouter/auto": {
          "alias": "OpenRouter"
        },
        "openrouter/stepfun/step-3.5-flash:free": {},
        "openrouter/qwen/qwen3-coder:free": {},
        "openrouter/z-ai/glm-4.5-air:free": {}
      },
      "compaction": {
        "mode": "safeguard"
      },
      "maxConcurrent": 4,
      "subagents": {
        "maxConcurrent": 8
      }
    },
    "list": [
      {
        "id": "main",
        "model": "openrouter/stepfun/step-3.5-flash:free"
      }
    ]
  },
  "messages": {
    "ackReactionScope": "group-mentions"
  },
  "commands": {
    "native": "auto",
    "nativeSkills": "auto",
    "restart": true,
    "ownerDisplay": "raw"
  },
  "gateway": {
    "port": 18789,
    "mode": "local",
    "auth": {
      "mode": "token",
      "token": "123456"
    }
  }
}

8.打开网页与龙虾交流

配置完成后即可打开网页与龙虾交流:

9.配置skills

未完待续

10.Openclaw实用案例

未完待续

相关推荐
sali-tec2 小时前
C# 基于OpenCv的视觉工作流-章38-BF特征匹配
图像处理·人工智能·opencv·算法·计算机视觉
道一云黑板报2 小时前
技术拆解:AI低代码架构设计与全链路落地实现
人工智能·驱动开发·低代码·ai·企业微信·ai编程·代码规范
段小二2 小时前
Prompt 工程与结构化输出:让 LLM 返回可用的 Java 对象(Java 架构师的 AI 工程笔记 04)
人工智能
火山引擎开发者社区2 小时前
基于多模态数据湖的新一代人工智能应用——Nvidia 工具链落地实践的深度洞察
人工智能
Elastic 中国社区官方博客2 小时前
用于 Elasticsearch 的 Gemini CLI 扩展,包含工具和技能
大数据·开发语言·人工智能·elasticsearch·搜索引擎·全文检索
段小二2 小时前
ChatClient 源码解析:从 HTTP 请求到 AI 响应的全链路拆解(Java 架构师的 AI 工程笔记 02)
人工智能
RuiBo_Qiu2 小时前
【LLM进阶-后训练&部署】2. 常见的全参数微调SFT方法
人工智能·深度学习·机器学习·ai-native
2501_933329552 小时前
媒介宣发技术中台架构实践:基于AI多模态的舆情处置与智能分发系统设计
人工智能·架构·系统架构
_遥远的救世主_3 小时前
OpenCode vs OpenClaw 企业级 AI 平台二开选型深度拆解
人工智能