🚀 OpenClaw 保姆级部署教程:从零开始搭建个人AI助手

作者:锡纸哥 | 更新时间:2026年3月3日

📖 前言

OpenClaw 是 2026 年初爆火的开源个人 AI 助手项目,能够在你的设备上运行并接入 WhatsApp、Telegram、飞书、钉钉等十余种消息平台,提供 7×24 小时的全能 AI Agent 体验。本文将从零开始,带你完成 OpenClaw 的完整部署流程。

🎯 部署方式概览

根据你的需求和环境,可以选择以下部署方式:

部署方式 难度 成本 适用场景
一键脚本安装 免费 + API费用 个人快速体验
npm 全局安装 ⭐⭐ 免费 + API费用 开发者日常使用
Mac Mini 本地部署 ⭐⭐⭐ 硬件投入 零云端费用、隐私优先
Docker 容器化 ⭐⭐⭐ 免费 + API费用 隔离运行、安全优先
云服务器部署 ⭐⭐ 68元/年起 + API 国内用户快速上手

🛠️ 系统要求

  • CPU: 2核及以上
  • 内存: 2GB及以上
  • 磁盘空间: 10GB及以上
  • 操作系统: macOS / Linux / Windows (WSL2)
  • Node.js: >= 22.0.0
  • 核心端口: TCP 18789

📋 部署步骤详解

方式一:一键脚本安装(推荐新手)

# 执行一键安装脚本
curl -fsSL https://openclaw.ai/install.sh | bash

# 运行配置向导
openclaw onboard --install-daemon

配置向导会引导你完成:

  • 选择 AI 模型提供商
  • 配置 API Key
  • 选择消息渠道
  • 安装守护进程

方式二:npm 全局安装

# 安装 Node.js 22+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.bashrc
nvm install 22
nvm use 22

# 安装 OpenClaw
npm install -g openclaw@latest

# 配置向导
openclaw onboard

方式三:Docker 容器化部署(推荐生产环境)

# 克隆仓库
git clone https://github.com/openclaw/openclaw.git
cd openclaw

# 一键部署
./docker-setup.sh

# 或手动 Docker Compose
docker compose up -d openclaw-gateway

🔧 配置消息渠道

Telegram 配置

# 创建 Telegram Bot
1. 在 Telegram 中搜索 @BotFather
2. 发送 /newbot 创建新机器人
3. 获取 Bot Token
4. 在 OpenClaw 配置中添加 Token

QQ 配置(通过 qqbot)

# 安装 qqbot 插件
openclaw plugins install qqbot

# 配置 QQ 机器人
在 openclaw.json 中添加 qqbot 配置

💰 成本控制策略

Token 成本分析

OpenClaw 的真正成本来自 LLM API 调用:

模型 输入成本 输出成本 相对成本
Claude Opus 4.5 15美金/百万 75美金/百万 基线(最贵)
Claude Sonnet 4.5 3美金/百万 15美金/百万 标准
Claude Haiku 4.5 1美金/百万 5美金/百万 ~Sonnet 的 1⁄3
Gemini 3.0 Flash 0.075美金/百万 0.30美金/百万 ~Sonnet 的 1⁄40

成本优化策略

  1. 会话重置:独立任务完成后重置会话,防止上下文膨胀
  2. 智能模型路由:日常任务使用 Haiku,复杂推理使用 Sonnet
  3. 本地模型回退:使用 Ollama + 本地模型处理简单任务
{
  "agent": {
    "sessionReset": "after-task",
    "maxContextTokens": 50000
  }
}

🔒 安全加固

认证配置

{
  "gateway": {
    "auth": "token"
  }
}

沙箱隔离

{
  "agents": {
    "defaults": {
      "sandbox": {
        "mode": "non-main",
        "scope": "agent",
        "workspaceAccess": "none"
      }
    }
  }
}

安全审计

# 基本审计
openclaw security audit

# 深度审计
openclaw security audit --deep

# 自动修复
openclaw security audit --fix

🚀 验证部署

# 检查 Gateway 状态
openclaw gateway status

# 启动 Gateway
openclaw gateway start

# 打开控制面板
openclaw dashboard

# 健康检查
openclaw doctor

📚 故障排除

常见问题

  1. 端口冲突:检查 18789 端口是否被占用
  2. API Key 错误:验证 API Key 是否正确配置
  3. 网络连接:确保能访问外部 API 服务
  4. 权限问题:检查文件读写权限

日志查看

# 查看 Gateway 日志
tail -f /tmp/openclaw/openclaw-*.log

# 查看系统日志
journalctl -u openclaw-gateway.service

🎯 进阶功能

MCP 工具集成

# 安装 mcporter
npm install -g mcporter

# 配置 MCP 服务器
# 详细配置参考:https://docs.openclaw.ai/mcp

自定义技能开发

// 示例技能
module.exports = {
  name: 'my-skill',
  description: '自定义技能示例',
  tools: {
    greet: {
      description: '打招呼',
      execute: async ({ name }) => {
        return `你好,${name}!`
      }
    }
  }
}

💡 最佳实践

  1. 定期更新:保持 OpenClaw 最新版本
  2. 备份配置:定期备份 openclaw.json 文件
  3. 监控成本:设置 API 使用量告警
  4. 安全第一:定期运行安全审计

🔗 参考资源


免责声明:本文基于公开资料整理,仅供学习参考。部署前请充分评估安全性与稳定性,并遵循官方安全指南。

希望这篇教程能帮助你顺利部署 OpenClaw!如有问题,欢迎在评论区留言讨论。