Moltbot/Clawdbot从零搭建部署实战攻略

2026-05-31阅读 0热度 0
claw

从零开始搭建部署 Moltbot/Clawdbot 完整攻略

新手入门指南 - 2026年1月版本

从零开始搭建部署 Moltbot/Clawdbot 完整攻略

先说说核心判断:这篇文章的目标很纯粹,就是带你把 Moltbot(或者它的老版本 Clawdbot)从零开始,完整地跑起来。不管你是用 Windows 还是 Mac,只要跟着步骤走,基本不会出大问题。

目录

  • 简介
  • 系统要求
  • Windows 系统安装
  • Mac 系统安装
  • 首次配置向导
  • 常用指令大全
  • 日常维护
  • 故障排除
  • 进阶配置
  • 常见问题

1. 简介

什么是 Moltbot/Clawdbot?

简单来说,它是一个 AI 助手框架,能帮你把各种大模型(MiniMax、Claude、GLM、GPT 这些)集成到不同的聊天平台(WhatsApp、Telegram、Discord 等等)上。而且它自带一套挺强大的工具生态,比如浏览器控制、文件操作、代码生成,还能通过技能系统无限扩展。

版本说明

  • Moltbot:这是官方现在用的名字,也是最新版本的命令。
  • Clawdbot:老版本,不过有些用户可能还在用。
  • 本教程统一用 moltbot 命令,如果你是 Clawdbot 用户,把命令名换一下就行。

2. 系统要求

基础要求

项目要求
操作系统macOS 10.15+ / Windows 10+ / Linux (Ubuntu 20.04+)
Node.js>= 22.x (必需)
内存最低 2GB,推荐 4GB+
磁盘空间最低 1GB,推荐 5GB+
网络需要访问互联网(API 调用),必须用袋里,否则 Gateway 启动不了

Windows 额外要求

  • 推荐用 WSL2。原因很简单:原生 Windows 支持不太完善,工具兼容性也差一些。

macOS 额外要求

  • Xcode Command Line Tools:这个不是必须的,只有在构建应用时才需要。

3. Windows 系统安装

3.1 安装 WSL2 (推荐)

这一步是为后面打基础。如果你对 WSL2 不熟,别担心,按顺序来就行。

步骤 1:启用 WSL2 功能

以管理员身份打开 PowerShell,然后依次执行以下命令:

# 启用 WSL 功能
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# 启用虚拟机平台
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
步骤 2:重启电脑
步骤 3:安装 WSL2 内核更新

下载并安装:wslstorestorage.blob.core.windows.net/wslblob/wsl…

步骤 4:设置 WSL2 为默认
wsl --set-default-version 2
步骤 5:安装 Ubuntu
  1. 打开 Microsoft Store
  2. 搜索 "Ubuntu 22.04 LTS"
  3. 安装并启动
  4. 设置一个用户名和密码

3.2 在 WSL2 中安装 Node.js

打开 WSL2 终端(也就是 Ubuntu 的终端),执行:

# 更新包列表
sudo apt update && sudo apt upgrade -y

# 安装 curl
sudo apt install -y curl

# 安装 Node.js 22.x
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs

# 验证安装
node --version
npm --version

3.3 安装 Moltbot

继续在 WSL2 终端中操作:

# 安装 moltbot
curl -fsSL https://molt.bot/install.sh | bash

# 验证安装
moltbot --version

# 如果命令找不到,就手动添加到 PATH
echo 'export PATH="$PATH:/usr/local/bin"' >> ~/.bashrc
source ~/.bashrc

3.4 安装 Docker (可选,用于沙箱)

# 在 WSL2 中安装 Docker
curl -fsSL https://get.docker.com -y | sudo sh

# 添加当前用户到 docker 组
sudo usermod -aG docker $USER

# 启动 Docker 服务
sudo service docker start

# 验证
docker --version

3.5 遇到问题?

如果 WSL2 实在装不上,还有两个备选方案:

方案 A:使用 Docker Desktop

  • 下载 Docker Desktop for Windows
  • 启用 WSL2 backend
  • 在 WSL2 中使用 docker 命令

方案 B:使用虚拟机

  • 安装 VirtualBox
  • 安装 Ubuntu 22.04 虚拟机
  • 在虚拟机中安装 Moltbot

4. Mac 系统安装

Mac 用户的安装流程要顺畅得多,基本就是 Homebrew 一把梭。

4.1 安装 Homebrew (如果未安装)

# 安装 Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# 验证
brew --version

4.2 安装 Node.js 22.x

有两个方案可选:

方案 A:使用 Homebrew

# 安装 Node.js 22
brew install node@22

# 添加到 PATH
echo 'export PATH="/usr/local/opt/node@22/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# 验证
node --version

方案 B:使用 nvm (推荐)

# 安装 nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# 加载 nvm
source ~/.zshrc

# 安装 Node.js 22
nvm install 22
nvm use 22

# 验证
node --version

4.3 安装 Moltbot

同样有几种方式:

# 推荐方式:直接安装
curl -fsSL https://molt.bot/install.sh | bash

# 验证安装
moltbot --version

# 如果命令找不到,手动添加到 PATH
echo 'export PATH="$PATH:/usr/local/bin"' >> ~/.zshrc
source ~/.zshrc

或者用 npm 安装:

# 全局安装
npm install -g moltbot@latest

# 验证
moltbot --version

或者用 pnpm:

# 安装 pnpm
npm install -g pnpm

# 安装 moltbot
pnpm add -g moltbot@latest

# 验证
moltbot --version

4.4 安装 Docker (可选,用于沙箱)

直接从官网下载 Docker Desktop for Mac 安装即可,然后验证:docker --version

4.5 Xcode Command Line Tools (可选)

# 安装
xcode-select --install

# 验证
xcode-select -p

5. 首次配置向导

安装完成后,接下来就是配置环节。Moltbot 提供了一个交互式向导,跟着走就行。

5.1 启动向导

# 启动交互式配置向导
moltbot onboard

5.2 向导步骤说明

步骤 1:选择模式

? Gateway mode: (Use arrow keys)
❯ Local  # 本地运行(推荐)
  Remote # 连接到远程 Gateway

建议选 Local,省心。

步骤 2:模型/认证配置

? Auth provider: (Use arrow keys)
  Anthropic (API key)  # 推荐
  Anthropic (OAuth)
  OpenAI
  MiniMax              # 如果想用 MiniMax
  GLM                  # 如果想用 GLM
  ...更多选项

Anthropic (API key),然后输入你的 Anthropic API Key。

步骤 3:选择默认模型

? Default model: (Use arrow keys)
❯ claude-sonnet-4-0  # 推荐,速度和智能平衡
  claude-opus-4-5    # 更强智能,但更慢
  claude-haiku-3-5   # 快速响应
  ...更多模型

一般选 claude-sonnet-4-0,平衡性最好。

步骤 4:Workspace 设置

? Workspace directory: (Use arrow keys)
❯ ~/clawd  # 默认工作区
  自定义路径

建议就用默认的 ~/clawd

步骤 5:Gateway 配置

? Gateway port: 18789  # 默认端口
? Gateway bind: (Use arrow keys)
❯ loopback  # 本地回环(推荐)
  lan       # 局域网
  tailnet   # Tailscale 网络

步骤 6:认证设置

? Gateway auth mode: (Use arrow keys)
❯ Token  # 推荐,需要 token
  None   # 不认证(不安全)

Token,安全第一。

步骤 7:Tailscale (可选)

? Expose via Tailscale: (Use arrow keys)
❯ No   # 不暴露到外网
  Yes  # 需要 Tailscale

一般选 No

步骤 8:频道配置

? Configure channels: (y/N)
  y  # 配置频道
  n  # 跳过,稍后配置

如果选 y,系统会让你选择要配置的频道:

? Channels: (Select channels to configure)
❯⬡ WhatsApp   # 需要 QR 登录
  ◉ Telegram  # 需要 bot token
  ◯ Discord   # 需要 bot token
  ◯ Google Chat
  ◯ Mattermost
  ◯ Signal
  ◯ iMessage

步骤 9:后台服务安装

? Install daemon: (y/N)
  y  # 安装后台服务(推荐)
  n  # 手动启动

建议选 y,后台运行省事。

步骤 10:选择运行时

? Runtime: (Use arrow keys)
❯ Node  # 推荐(必需 for WhatsApp/Telegram)
  Bun   # 不推荐

Node

步骤 11:健康检查

向导会自动启动 Gateway 并检查健康状态,等待就行。

步骤 12:技能选择

? Install recommended skills: (y/N)
  y  # 安装推荐技能
  n  # 跳过

5.3 完成配置

看到 "✅ Moltbot 已准备就绪!" 就说明搞定了。

5.4 快速测试

# 查看状态
moltbot status

# 发送测试消息
moltbot message send --target +15555550123 --message "Hello from Moltbot!"

# 查看日志
moltbot logs --follow

6. 常用指令大全

6.1 基础命令

moltbot --version        # 查看版本
moltbot --help           # 查看帮助
moltbot status           # 查看状态概览
moltbot status --all     # 完整诊断(可分享)
moltbot status --deep    # 深度健康检查

6.2 Gateway 管理

moltbot gateway start    # 启动
moltbot gateway stop     # 停止
moltbot gateway restart  # 重启
moltbot gateway status   # 查看状态
moltbot gateway config   # 查看配置
moltbot gateway --verbose # 手动前台运行(调试)
moltbot gateway probe    # 探测连通性

6.3 配置管理

moltbot configure                            # 交互式配置
moltbot config get                           # 查看完整配置
moltbot config get agents.defaults           # 查看特定配置
moltbot config set gateway.port 18789        # 设置单个值
moltbot config unset gateway.port            # 删除配置项

6.4 模型管理

moltbot models list       # 查看可用模型
moltbot models status     # 查看模型状态
moltbot models scan       # 扫描可用模型
moltbot models set anthropic/claude-sonnet-4-0  # 设置默认模型
moltbot models probe               # 测试模型连接

6.5 频道管理

moltbot channels login        # WhatsApp 登录(QR 扫描)
moltbot channels logout       # 退出登录
moltbot channels status       # 查看频道状态
moltbot channels status --probe  # 探测频道

6.6 配对管理

moltbot pairing list whatsapp        # 查看待处理配对
moltbot pairing approve whatsapp   # 批准配对
moltbot pairing deny whatsapp     # 拒绝配对

6.7 消息发送

moltbot message send --target +15555550123 --message "Hello!"
moltbot message send --target +15555550123 --file /path/to/file.txt

6.8 袋里 (Agents)

moltbot agents list             # 查看袋里列表
moltbot agents add work --workspace ~/clawd-work  # 添加新袋里
moltbot agents status work      # 查看袋里状态

6.9 会话管理

moltbot sessions list              # 查看活跃会话
moltbot sessions history   # 查看会话历史
moltbot sessions reset     # 重置会话

6.10 技能管理

moltbot skills list              # 列出已安装技能
moltbot skills install skill-name # 安装技能
moltbot skills config skill-name  # 查看技能配置
moltbot skills update skill-name  # 更新技能

6.11 日志和诊断

moltbot logs --follow        # 实时查看日志
moltbot logs --limit 100     # 查看最近 100 行
moltbot health               # 健康检查
moltbot doctor               # 诊断
moltbot doctor --fix         # 诊断并修复

6.12 目录和工作区

moltbot dashboard       # 打开控制面板
moltbot tui             # 打开控制 UI
moltbot directory       # 查看工作区目录
ls -la ~/clawd/         # 查看文件

6.13 更新和升级

moltbot --version                         # 检查当前版本
curl -fsSL https://molt.bot/install.sh | bash  # 更新 CLI(安装脚本)
# 从源码更新:
git pull origin main
pnpm install
pnpm build
moltbot doctor
moltbot gateway restart

6.14 安全相关

moltbot security audit       # 安全审计
moltbot security audit --deep # 深度审计

7. 日常维护

7.1 定期检查命令

# 每日检查
moltbot status
moltbot health

# 每周检查
moltbot status --all
moltbot logs --limit 500 | grep -i error
moltbot doctor

7.2 日志管理

# 查看实时日志
moltbot logs --follow

# 查找错误
moltbot logs --limit 1000 | grep -i "error|failed"

# 按日期查看
ls -lt /tmp/moltbot/moltbot-*.log | head -5
tail -f /tmp/moltbot/moltbot-$(date +%Y-%m-%d).log

7.3 备份配置

# 备份配置文件
cp ~/.clawdbot/clawdbot.json ~/.clawdbot/clawdbot.json.backup.$(date +%Y%m%d)

# 备份认证文件
cp ~/.clawdbot/agents/main/agent/auth-profiles.json ~/backups/auth-profiles.json.$(date +%Y%m%d)

# 备份工作区
tar -czvf ~/backups/clawd-backup.$(date +%Y%m%d).tar.gz ~/clawd/

7.4 更新流程

# 1. 检查当前版本
moltbot --version

# 2. 停止 Gateway
moltbot gateway stop

# 3. 更新 CLI
curl -fsSL https://molt.bot/install.sh | bash

# 4. 运行健康检查
moltbot doctor

# 5. 重新启动
moltbot gateway start

# 6. 验证状态
moltbot status

7.5 监控告警(可选)

创建一个监控脚本 ~/clawd/monitor.sh

#!/bin/bash
echo "=== $(date) ==="
moltbot status
moltbot health
moltbot logs --limit 100 | grep -i error | tail -5

# 检查 Gateway 是否运行
if ! moltbot gateway status | grep -q "running"; then
    echo "⚠️ Gateway 未运行,尝试重启..."
    moltbot gateway restart
fi

添加执行权限并设置 cron:

chmod +x ~/clawd/monitor.sh
crontab -e
# 添加:0 * * * * ~/clawd/monitor.sh >> ~/clawd/monitor.log 2>&1

7.6 清理和维护

# 清理旧日志(保留最近7天)
find /tmp/moltbot -name "moltbot-*.log" -mtime +7 -delete

# 清理临时文件
rm -rf ~/.clawdbot/tmp/*

# 清理会话缓存
moltbot sessions list | awk '{print $1}' | xargs -I {} moltbot sessions reset {}

8. 故障排除

8.1 快速诊断流程

# 1. 运行完整诊断
moltbot status --all

# 2. 查看实时日志
moltbot logs --follow

# 3. 运行医生检查
moltbot doctor
moltbot doctor --fix

8.2 常见问题

问题 1:命令找不到

症状:zsh: command not found: moltbot

解决方案:

# 检查是否安装
npm list -g --depth=0 | grep moltbot

# 查找安装位置
find /usr -name moltbot -type f 2>/dev/null
find ~/.npm -name moltbot -type f 2>/dev/null

# 手动添加 PATH
echo 'export PATH="$PATH:/usr/local/bin"' >> ~/.zshrc
source ~/.zshrc

问题 2:Gateway 无法启动

解决方案:

# 查看详细错误
moltbot gateway --verbose

# 检查端口占用
lsof -i :18789

# 检查配置
moltbot doctor

# 查看日志
moltbot logs --follow | tail -50

问题 3:无 API Key

症状:No API key found for provider 'anthropic'

解决方案:

# 重新配置
moltbot configure

# 或手动设置
export ANTHROPIC_API_KEY="sk-ant-api03-..."
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-..."' >> ~/.clawdbot/.env

# 验证
moltbot models status

问题 4:频道无响应

解决方案:

# 1. 检查频道状态
moltbot channels status --probe

# 2. 检查配对状态
moltbot pairing list 

# 3. 查看日志
moltbot logs --follow | grep -i "channel|pairing"

# 4. 如果是 WhatsApp,尝试重新登录
moltbot channels logout
moltbot channels login

问题 5:OAuth 失败

解决方案:

# 切换到 API key
moltbot configure
# 选择 Anthropic API key

# 或使用 setup-token
moltbot models auth setup-token --provider anthropic

问题 6:模型不可用

症状:Unknown model: anthropic/claude-haiku-3-5

解决方案:

# 查看可用模型
moltbot models list

# 设置已知模型
moltbot models set anthropic/claude-sonnet-4-0

# 扫描新模型
moltbot models scan

问题 7:内存不足

解决方案:

# 检查内存使用
top -o memory

# 限制历史记录
moltbot config set 'session.historyLimit' 50

# 重启 Gateway 释放内存
moltbot gateway restart

8.3 紧急恢复

# 1. 停止 Gateway
moltbot gateway stop

# 2. 备份当前配置
cp ~/.clawdbot/clawdbot.json ~/.clawdbot/clawdbot.json.emergency

# 3. 重置配置(保留工作区)
moltbot setup --reset config

# 4. 重新配置
moltbot onboard

# 5. 如果仍有问题,恢复配置
cp ~/.clawdbot/clawdbot.json.emergency ~/.clawdbot/clawdbot.json
moltbot gateway start

9. 进阶配置

9.1 多袋里配置

{
  "agents": {
    "list": [
      {
        "id": "main",
        "name": "主助手",
        "workspace": "~/clawd",
        "default": true,
        "model": {
          "primary": "minimax/MiniMax-M2.1",
          "fallbacks": ["glm-4"]
        }
      },
      {
        "id": "work",
        "name": "工作助手",
        "workspace": "~/clawd-work",
        "model": {
          "primary": "anthropic/claude-sonnet-4-0"
        }
      }
    ],
    "bindings": [
      {
        "agentId": "main",
        "match": { "channel": "whatsapp", "accountId": "personal" }
      },
      {
        "agentId": "work",
        "match": { "channel": "whatsapp", "accountId": "biz" }
      }
    ]
  }
}

9.2 模型主备配置

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "minimax/MiniMax-M2.1",
        "fallbacks": [
          "anthropic/claude-sonnet-4-0",
          "glm-4",
          "openai/gpt-4o"
        ]
      }
    }
  }
}

9.3 频道配置示例

{
  "channels": {
    "whatsapp": {
      "dmPolicy": "pairing",
      "allowFrom": ["+15555550123"],
      "groups": {
        "*": { "requireMention": true }
      }
    },
    "telegram": {
      "botToken": "your-bot-token",
      "dmPolicy": "pairing",
      "groups": {
        "*": { "requireMention": true }
      }
    }
  }
}

9.4 沙箱配置

{
  "agents": {
    "defaults": {
      "sandbox": {
        "mode": "all",
        "scope": "agent",
        "workspaceAccess": "rw"
      }
    }
  }
}

9.5 日志配置

{
  "logging": {
    "level": "info",
    "file": "/tmp/moltbot/moltbot.log",
    "consoleLevel": "info",
    "consoleStyle": "pretty",
    "redactSensitive": "tools"
  }
}

9.6 自定义工具配置

{
  "tools": {
    "allow": ["read", "write", "edit", "exec", "browser"],
    "deny": ["process", "gateway"]
  }
}

10. 常见问题

Q1: 需要多少内存?

A: 最低 2GB,推荐 4GB+。如果运行多个袋里或大量并发,需要更多。

Q2: 支持哪些模型?

A: 支持 Anthropic (Claude)、OpenAI (GPT)、MiniMax、GLM、Moonshot 等。具体运行 moltbot models list 查看。

Q3: 如何更改默认模型?

A: 运行 moltbot models set minimax/MiniMax-M2.1 或者 moltbot configure 重新跑一遍向导。

Q4: 支持多平台吗?

A: 支持 WhatsApp、Telegram、Discord、Google Chat、Mattermost、Signal、iMessage 等。

Q5: 如何备份和恢复?

A:

# 备份
cp ~/.clawdbot/clawdbot.json backup/
cp -r ~/clawd backup/

# 恢复
cp backup/clawdbot.json ~/.clawdbot/
cp -r backup/clawd ~/

Q6: 更新后需要重新配置吗?

A: 一般不需要,配置会保留。但如果涉及重大变更,可能需要运行 moltbot doctor 修复。

Q7: Gateway 端口可以更改吗?

A: 可以:moltbot config set gateway.port 18889,然后重启 Gateway。

Q8: 如何实现负载均衡?

A: Moltbot 支持多 Gateway 部署,通过配置 gateway.remote.url 实现,具体参考高级配置文档。

Q9: 是否支持 Docker 部署?

A: 支持,Gateway 可以运行在 Docker 容器中。

Q10: 如何获取帮助?

A: 查看官方文档 docs.clawd.bot/,或者运行 moltbot --help / moltbot --help。也可以去 GitHub Issues 或 Discord 社区提问。

资源链接

快速参考卡

# 日常使用
moltbot status             # 检查状态
moltbot health             # 健康检查
moltbot logs --follow      # 查看日志

# 配置
moltbot configure          # 交互配置
moltbot config get         # 查看配置
moltbot config set    # 设置配置

# 模型
moltbot models list        # 列出模型
moltbot models set  # 切换模型
moltbot models status      # 模型状态

# Gateway
moltbot gateway start      # 启动
moltbot gateway stop       # 停止
moltbot gateway restart    # 重启

# 故障排除
moltbot doctor             # 诊断
moltbot doctor --fix       # 自动修复
moltbot status --all       # 完整诊断

最后更新:2026年1月

版本:1.0

免责声明

本网站新闻资讯均来自公开渠道,力求准确但不保证绝对无误,内容观点仅代表作者本人,与本站无关。若涉及侵权,请联系我们处理。本站保留对声明的修改权,最终解释权归本站所有。

相关阅读

更多
欢迎回来 登录或注册后,可保存提示词和历史记录
登录后可同步收藏、历史记录和常用模板
注册即表示同意服务条款与隐私政策