适合小白的OpenClaw 完整部署教程

什么是 OpenClaw?

OpenClaw 是一个开源的 AI 助手平台,让你可以在本地运行自己的 AI 助手。它就像你自己的贾维斯,可以:

  • 通过多种渠道聊天(Telegram、Discord、WhatsApp、网页等)
  • 访问你的文件、日历、浏览器等资源
  • 执行自动化任务
  • 扩展各种技能(天气查询、文件管理、网页搜索等)

第一部分:系统准备

1.1 操作系统要求

  • macOS:10.15 或更高
  • Linux:Ubuntu 20.04+、Debian 11+、CentOS 8+
  • Windows:Windows 10/11 + WSL2(推荐)
  • 其他:树莓派、云服务器等

1.2 硬件要求

  • 内存:至少 4GB RAM(推荐 8GB+)
  • 存储:至少 2GB 可用空间
  • CPU:现代双核处理器
  • 网络:稳定的互联网连接

1.3 软件要求

  • Node.js:版本 22 或更高
  • Git:用于某些安装方式
  • 包管理器:npm 或 pnpm

第二部分:安装 OpenClaw(多种方式)

2.1 快速安装(推荐给小白)

macOS/Linux

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

Windows(PowerShell)

iwr -useb https://openclaw.ai/install.ps1 | iex

这个方式会自动:

  • 检测并安装 Node.js(如果需要)
  • 选择最佳安装方式
  • 设置环境变量
  • 运行健康检查

2.2 高级安装选项

方式一:全局 npm 安装(标准方式)

# 安装 Node.js(如果还没有)
# macOS
brew install node@22

# Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs

# 安装 OpenClaw
npm install -g openclaw@latest

# 如果遇到 sharp 包错误
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install -g openclaw@latest

方式二:Git 源码安装(开发者/定制)

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

# 安装依赖
pnpm install
pnpm ui:build
pnpm build

# 运行
pnpm openclaw onboard --install-daemon

方式三:无 root 权限安装

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

这个方式会将 OpenClaw 安装到 ~/.openclaw 目录,不修改系统文件。

方式四:Docker 安装

# 拉取镜像
docker pull ghcr.io/openclaw/openclaw:latest

# 运行
docker run -p 18789:18789 ghcr.io/openclaw/openclaw:latest

2.3 安装参数详解

安装脚本支持多种参数:

# 查看所有参数
curl -fsSL https://openclaw.ai/install.sh | bash -s -- --help

# 常用参数示例
curl -fsSL https://openclaw.ai/install.sh | bash -s -- \
  --install-method git \          # 使用 Git 源码安装
  --git-dir ~/my-openclaw \       # 指定安装目录
  --no-git-update \               # 不更新现有仓库
  --no-prompt \                   # 非交互模式(适合脚本)
  --dry-run                       # 只显示将要执行的操作

环境变量方式(适合自动化):

export OPENCLAW_INSTALL_METHOD=git
export OPENCLAW_GIT_DIR=~/openclaw-custom
export OPENCLAW_NO_PROMPT=1
curl -fsSL https://openclaw.ai/install.sh | bash

第三部分:AI 模型配置(核心!)

3.1 理解 AI 模型

OpenClaw 本身不包含 AI 模型,它需要连接外部的 AI 服务。你有多种选择:

  1. 免费模型:DeepSeek、Qwen 等
  2. 付费模型:OpenAI GPT、Claude、Gemini 等
  3. 本地模型:Ollama、LM Studio 等
  4. 混合使用:根据任务选择不同模型

3.2 查看可用模型

# 查看已配置的模型
openclaw models list

# 查看模型详情
openclaw models describe deepseek/deepseek-chat

3.3 配置免费模型(DeepSeek 示例)

步骤 1:获取 API 密钥

  1. 访问 https://platform.deepseek.com/
  2. 注册账号
  3. 在控制台创建 API 密钥

步骤 2:配置 OpenClaw

# 设置 DeepSeek API 密钥
openclaw config set providers.deepseek.apiKey "你的-api-key"

# 设置为默认模型
openclaw config set agents.defaults.model "deepseek/deepseek-chat"

# 验证配置
openclaw config get agents.defaults.model

3.4 配置付费模型(OpenAI 示例)

步骤 1:获取 API 密钥

  1. 访问 https://platform.openai.com/
  2. 注册账号并充值
  3. 创建 API 密钥

步骤 2:配置 OpenClaw

# 设置 OpenAI API 密钥
openclaw config set providers.openai.apiKey "sk-你的密钥"

# 设置为默认模型
openclaw config set agents.defaults.model "openai/gpt-4o"

# 可选:设置组织 ID
openclaw config set providers.openai.organization "org-你的组织ID"

3.5 配置本地模型(Ollama 示例)

步骤 1:安装 Ollama

# macOS/Linux
curl -fsSL https://ollama.ai/install.sh | sh

# Windows
# 从 https://ollama.com/download 下载安装包

步骤 2:下载模型

# 下载一个轻量级模型
ollama pull llama3.2:3b

# 或者下载更大的模型
ollama pull llama3.1:8b

步骤 3:配置 OpenClaw

# 设置 Ollama 端点
openclaw config set providers.ollama.baseUrl "http://localhost:11434"

# 设置为默认模型
openclaw config set agents.defaults.model "ollama/llama3.2:3b"

3.6 多模型配置

你可以配置多个模型,根据不同场景使用:

# 配置多个模型端点
openclaw config set providers.deepseek.apiKey "deepseek-key"
openclaw config set providers.openai.apiKey "openai-key"
openclaw config set providers.anthropic.apiKey "claude-key"

# 创建模型配置文件
cat > ~/.openclaw/models.json << EOF
{
  "default": "deepseek/deepseek-chat",
  "creative": "openai/gpt-4o",
  "coding": "anthropic/claude-3-5-sonnet",
  "local": "ollama/llama3.2:3b"
}
EOF

# 运行时选择模型
openclaw agent --model "openai/gpt-4o" --message "写一首诗"

3.7 模型选择建议

使用场景推荐模型优点缺点
日常聊天DeepSeek Chat免费、中文好、响应快创意性一般
编程助手Claude 3.5 Sonnet代码能力强、逻辑清晰收费、需要API
创意写作GPT-4o创意丰富、文笔好收费、可能慢
本地使用Llama 3.2 3B完全离线、隐私好能力有限、需要GPU
多语言Qwen 2.5中文优秀、多语言支持需要自己部署

第四部分:初始化配置

4.1 运行初始化向导

openclaw onboard --install-daemon

向导会引导你配置:

  1. 认证设置

    • 创建访问令牌
    • 设置管理员密码
    • 配置安全选项
  2. 网关配置

    # 默认端口:18789
    # 可以修改端口
    openclaw config set gateway.port 18888
    
    # 绑定到所有网络接口(谨慎!)
    openclaw config set gateway.bind "0.0.0.0"
  3. 通道配置(可选)

    • Telegram Bot
    • Discord Bot
    • WhatsApp Web
    • 网页聊天界面
  4. 存储配置

    # 查看当前配置
    openclaw config get gateway.dataDir
    
    # 修改数据目录
    openclaw config set gateway.dataDir "/path/to/your/data"

4.2 手动配置示例

如果你不想用向导,可以手动配置:

# 1. 创建配置文件目录
mkdir -p ~/.openclaw

# 2. 创建基础配置
cat > ~/.openclaw/config.json << EOF
{
  "gateway": {
    "port": 18789,
    "bind": "127.0.0.1",
    "dataDir": "~/.openclaw/data"
  },
  "agents": {
    "defaults": {
      "model": "deepseek/deepseek-chat"
    }
  },
  "providers": {
    "deepseek": {
      "apiKey": "你的-api-key"
    }
  }
}
EOF

# 3. 启动服务
openclaw gateway --install-daemon

第五部分:启动和使用

5.1 启动服务

作为系统服务(推荐)

# 安装为系统服务
openclaw gateway --install-daemon

# 管理服务
openclaw gateway start      # 启动
openclaw gateway stop       # 停止
openclaw gateway restart    # 重启
openclaw gateway status     # 状态

前台运行(调试用)

openclaw gateway --port 18789 --verbose

5.2 访问控制界面

# 打开网页界面
openclaw dashboard

# 或者直接访问
# http://127.0.0.1:18789/

5.3 基础命令

# 健康检查
openclaw doctor

# 查看状态
openclaw status

# 查看日志
openclaw logs --follow

# 发送测试消息
openclaw message send --target +123456789 --message "测试"

# 更新 OpenClaw
openclaw update

5.4 连接聊天通道

# Telegram
openclaw channels login telegram
# 需要 Bot Token:从 @BotFather 获取

# Discord
openclaw channels login discord
# 需要 Bot Token:从 Discord Developer Portal 获取

# WhatsApp
openclaw channels login whatsapp
# 扫描二维码连接

# Slack
openclaw channels login slack
# 需要 Slack App 配置

第六部分:高级配置

6.1 技能管理

# 查看可用技能
openclaw skills list

# 安装技能
openclaw skills install weather
openclaw skills install file-manager
openclaw skills install web-search

# 创建自定义技能
mkdir -p ~/.openclaw/skills/my-skill
# 创建 SKILL.md 和脚本文件

6.2 定时任务

# 添加定时任务
openclaw cron add \
  --name "每日问候" \
  --schedule "0 9 * * *" \
  --command "openclaw message send --target +123456789 --message '早安!'"

# 查看定时任务
openclaw cron list

# 删除定时任务
openclaw cron remove --name "每日问候"

6.3 内存管理

# 查看内存使用
openclaw memory stats

# 清理旧会话
openclaw sessions cleanup --older-than 7d

# 导出记忆
openclaw memory export --format json > memory_backup.json

6.4 安全配置

# 设置访问控制
openclaw config set security.allowedIPs "192.168.1.0/24"

# 启用 HTTPS
openclaw config set gateway.tls.cert "/path/to/cert.pem"
openclaw config set gateway.tls.key "/path/to/key.pem"

# 设置访问令牌
openclaw config set gateway.auth.tokens "你的强密码"

第七部分:故障排除

7.1 常见问题

问题1:端口被占用

# 查看占用进程
lsof -i :18789

# 停止占用进程
kill -9 <PID>

# 或使用其他端口
openclaw gateway --port 18888

问题2:找不到 openclaw 命令

# 检查 PATH
echo $PATH

# 添加 npm 全局路径
export PATH="$(npm prefix -g)/bin:$PATH"
# 添加到 ~/.bashrc 或 ~/.zshrc

问题3:模型连接失败

# 测试模型连接
openclaw models test deepseek/deepseek-chat

# 检查 API 密钥
openclaw config get providers.deepseek.apiKey

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

问题4:内存不足

# 查看内存使用
free -h

# 使用轻量级模型
openclaw config set agents.defaults.model "deepseek/deepseek-chat"

# 增加交换空间
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

7.2 调试命令

# 详细日志
openclaw gateway --log-level debug

# 健康深度检查
openclaw doctor --deep

# 网络测试
openclaw health --timeout 30

# 重置配置(谨慎!)
openclaw reset --keep-data

第八部分:最佳实践

8.1 安全建议

  1. 不要暴露到公网:除非配置了 HTTPS 和强认证
  2. 定期更新openclaw update
  3. 备份配置:定期备份 ~/.openclaw 目录
  4. 使用强密码:访问令牌要足够复杂
  5. 限制访问:只允许信任的 IP 访问

8.2 性能优化

  1. 选择合适的模型:根据任务选择,不要总是用最大的
  2. 清理旧数据:定期清理会话记录
  3. 使用缓存:OpenClaw 会自动缓存模型响应
  4. 监控资源:使用 htop 或 nvidia-smi 监控

8.3 备份与迁移

# 备份配置
tar -czf openclaw_backup_$(date +%Y%m%d).tar.gz ~/.openclaw

# 迁移到新机器
scp openclaw_backup.tar.gz user@new-machine:~/
ssh user@new-machine "tar -xzf openclaw_backup.tar.gz"

第九部分:学习资源

9.1 官方资源

9.2 教程视频

  • 官方 YouTube 频道
  • B 站 UP 主教程
  • 社区分享会录像

9.3 示例项目

  • 个人助理配置
  • 团队协作机器人
  • 智能家居控制
  • 自动化工作流

总结

OpenClaw 是一个功能强大且灵活的平台,关键步骤:

  1. 选择安装方式:一键安装最简单,源码安装最灵活
  2. 配置 AI 模型:根据需求选择免费或付费模型
  3. 初始化配置:使用向导或手动配置
  4. 启动服务:作为系统服务运行
  5. 开始使用:网页界面或连接聊天应用
  6. 扩展功能:添加技能、定时任务等

最重要的是动手尝试!先从简单的配置开始,慢慢探索高级功能。

THE END
喜欢就支持一下吧
赞赏 分享