手把手实战:从零到一轻松部署 Moltbot/Clawdbot 完全指南

教程2小时前更新 admin
16 0 0
网心云广告也精彩

1. 简介

什么是 Moltbot/Clawdbot

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 Subsystem for Linux 2)
  • 原因: 原生 Windows 支持不完善,工具兼容性较差

macOS 额外要求

  • Xcode Command Line Tools: 可选(仅构建应用时需要)

3. Windows 系统安装

3.1 安装 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

  1. 下载 Docker Desktop for Windows
  2. 启用 WSL2 backend
  3. 在 WSL2 中使用 docker 命令

方案 B:使用虚拟机

  1. 安装 VirtualBox
  2. 安装 Ubuntu 22.04 虚拟机
  3. 在虚拟机中安装 Moltbot

4. Mac 系统安装

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

# 安装 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
# 下载地址: https://www.docker.com/products/docker-desktop/

# 验证
docker --version

4.5 Xcode Command Line Tools (可选)

# 安装
xcode-select --install

# 验证
xcode-select -p

5. 首次配置向导

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            # 快速响应
  ...更多模型
步骤 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                        # 不认证(不安全)
步骤 7:Tailscale (可选)
? Expose via Tailscale: (Use arrow keys)
 No                         # 不暴露到外网
  Yes                         # 需要 Tailscale
步骤 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  # 手动启动
步骤 10:选择运行时
? Runtime: (Use arrow keys)
❯ Node                        # 推荐(必需 for WhatsApp/Telegram)
  Bun                         # 不推荐
步骤 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 管理

# 启动 Gateway
moltbot gateway start

# 停止 Gateway
moltbot gateway stop

# 重启 Gateway
moltbot gateway restart

# 查看 Gateway 状态
moltbot gateway status

# 查看 Gateway 配置
moltbot gateway config

# 手动前台运行(调试)
moltbot gateway --verbose

# 探测 Gateway 连通性
moltbot gateway probe

6.3 配置管理

# 打开交互式配置
moltbot configure

# 查看完整配置
moltbot config get

# 查看特定配置
moltbot config get agents.defaults
moltbot config get models
moltbot config get channels.telegram

# 设置单个值
moltbot config set gateway.port 18789
moltbot config set agents.defaults.workspace ~/clawd

# 删除配置项
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 set minimax/MiniMax-M2.1
moltbot models set glm-4

# 测试模型连接
moltbot models probe <model-name>

6.5 频道管理

# WhatsApp 登录(QR 扫描)
moltbot channels login

# 退出登录
moltbot channels logout

# 查看频道状态
moltbot channels status

# 探测频道
moltbot channels status --probe

6.6 配对管理

# 查看待处理配对
moltbot pairing list whatsapp
moltbot pairing list telegram

# 批准配对
moltbot pairing approve whatsapp <code>

# 拒绝配对
moltbot pairing deny whatsapp <code>

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 <session-key>

# 重置会话
moltbot sessions reset <session-key>

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

# 查看最近 N 行
moltbot logs --limit 100

# 健康检查
moltbot health

# 诊断和修复
moltbot doctor
moltbot doctor --fix  # 自动修复

6.12 目录和工作区

# 打开控制面板
moltbot dashboard

# 打开控制 UI
moltbot tui

# 查看工作区目录
moltbot directory

# 查看文件
ls -la ~/clawd/

6.13 更新和升级

# 检查更新
moltbot --version

# 更新 CLI(安装脚本)
curl -fsSL https://molt.bot/install.sh | bash

# 从源码更新
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 监控告警(可选)

创建监控脚本:

cat > ~/clawd/monitor.sh << 'EOF'
#!/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
EOF

chmod +x ~/clawd/monitor.sh

添加 cron 任务:

# 每小时运行监控
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 无法启动

症状: 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 <channel>

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

# 4. 如果是 WhatsApp,尝试重新登录
moltbot channels logout
moltbot channels login
问题 5:OAuth 失败

症状: OAuth token 刷新失败

解决方案:

# 切换到 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:内存不足

症状: Gateway 运行缓慢或崩溃

解决方案:

# 检查内存使用
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
moltbot gateway restart

Q8: 如何实现负载均衡?

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

Q9: 是否支持 Docker 部署?

A: 支持。Gateway 可以运行在 Docker 容器中。具体参考 Docker 部署文档。

Q10: 如何获取帮助?

A:


📚 资源链接


✅ 快速参考卡

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

# 配置
moltbot configure                 # 交互配置
moltbot config get                # 查看配置
moltbot config set <key> <value>  # 设置配置

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

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

# 故障排除
moltbot doctor                    # 诊断
moltbot doctor --fix              # 自动修复
moltbot status --all              # 完整诊断
© 版权声明
广告也精彩

相关文章

暂无评论

暂无评论...