OpenClaw 入门教程 🦞

1. 基本介绍

OpenClaw 是一个多通道网关,用于连接各种聊天应用(Discord、Telegram、WhatsApp、Signal等)到AI代理。它是一个自托管的解决方案,让您可以在自己的设备上运行AI助手。

2. 安装与设置

2.1 安装OpenClaw

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

# 或使用npx(无需全局安装)
npx openclaw@latest onboard

2.2 初始化配置

# 引导式安装
openclaw onboard --install-daemon

# 基础配置(无引导)
openclaw setup --baseline

2.3 启动控制面板

openclaw dashboard
# 默认地址: http://127.0.0.1:18789/

3. 常用命令

3.1 系统管理

# 查看状态
openclaw status

# 健康检查
openclaw health

# 网关管理
openclaw gateway start|stop|restart|status

# 日志查看
openclaw logs --follow

# 系统信息
openclaw system event

3.2 配置管理

# 查看配置
openclaw config get

# 设置配置值
openclaw config set key.value "new value"

# 验证配置
openclaw config validate

# 获取配置文件路径
openclaw config file

3.3 通道管理

# 列出已配置的通道
openclaw channels list

# 添加新通道
openclaw channels add telegram

# 通道状态
openclaw channels status

# 通道日志
openclaw channels logs

3.4 插件管理

# 搜索插件
openclaw plugins search "keyword"

# 安装插件
openclaw plugins install clawhub:plugin-name
openclaw plugins install npm:package-name
openclaw plugins install git:github.com/user/repo

# 列出插件
openclaw plugins list

# 启用/禁用插件
openclaw plugins enable plugin-id
openclaw plugins disable plugin-id

# 检查插件
openclaw plugins inspect plugin-id --runtime --json

3.5 模型管理

# 列出可用模型
openclaw models list

# 设置模型
openclaw models set provider.model

# 模型状态
openclaw models status

# 认证管理
openclaw models auth list|add|login

3.6 会话管理

# 列出会话
openclaw sessions list

# 清理会话
openclaw sessions cleanup

# 审计会话
openclaw audit

3.7 技能管理

# 搜索技能
openclaw skills search "skill-name"

# 安装技能
openclaw skills install clawhub:skill-name

# 列出技能
openclaw skills list

# 检查技能
openclaw skills check

3.8 任务与自动化

# Cron任务管理
openclaw cron list|add|edit|rm

# 任务管理
openclaw tasks list|show|cancel

# Webhooks
openclaw webhooks setup

3.9 节点管理

# 节点状态
openclaw nodes status

# 列出节点
openclaw nodes list

# 设备管理
openclaw devices list|approve|reject

4. 配置文件

4.1 配置文件位置

~/.openclaw/openclaw.json

4.2 常用配置项

{
  "channels": {
    "telegram": {
      "allowFrom": ["+1234567890"],
      "groups": { "*": { "requireMention": true } }
    },
    "whatsapp": {
      "allowFrom": ["+1234567890"]
    }
  },
  
  "messages": {
    "groupChat": {
      "mentionPatterns": ["@openclaw"]
    }
  },
  
  "plugins": {
    "enabled": true,
    "allow": ["voice-call", "web-search"],
    "entries": {
      "voice-call": { "enabled": true, "config": { "provider": "twilio" } }
    }
  },
  
  "models": {
    "default": {
      "provider": "openai",
      "model": "gpt-4"
    }
  }
}

4.3 环境变量

# 开发模式
OPENCLAW_DEV=1

# 配置文件路径
OPENCLAW_CONFIG_PATH="/path/to/config.json"

# 状态目录
OPENCLAW_STATE_DIR="/path/to/state"

# 日志级别
OPENCLAW_LOG_LEVEL=info

# 容器模式
OPENCLAW_CONTAINER=name

5. 插件系统

5.1 插件类型

  • 通道插件: 添加新的聊天通道支持
  • 模型插件: 支持新的AI模型提供商
  • 技能插件: 添加新的工具和功能
  • 语音插件: 语音识别和合成
  • 媒体插件: 图像、音频、视频处理

5.2 插件安装源

# ClawHub(官方市场)
openclaw plugins install clawhub:plugin-name

# npm registry
openclaw plugins install npm:package-name

# Git仓库
openclaw plugins install git:github.com/user/repo@tag

# 本地开发
openclaw plugins install --link ./my-plugin

5.3 常用插件

# 语音通话
openclaw plugins install clawhub:voice-call

# 网页搜索
openclaw plugins install clawhub:web-search

# 图像生成
openclaw plugins install clawhub:image-generation

# 语音转录
openclaw plugins install clawhub:voice-transcription

# 网页抓取
openclaw plugins install clawhub:web-fetch

6. 常用工具

6.1 Web控制面板

  • 地址: http://127.0.0.1:18789/
  • 功能: 聊天、配置、会话管理、节点控制

6.2 CLI工具

# 发送消息
openclaw message send channel "Hello World"

# 聊天界面
openclaw chat

# 终端界面
openclaw terminal

# 浏览器自动化
openclaw browser open https://example.com

6.3 调试工具

# 诊断工具
openclaw doctor

# 配置修复
openclaw doctor --fix

# 网关诊断
openclaw gateway diagnostics export

# 网络检查
openclaw dns setup

7. 高级功能

7.1 多代理路由

{
  "agents": {
    "main": {
      "model": "openai/gpt-4"
    },
    "coding": {
      "model": "anthropic/claude-3",
      "runtime": "codex"
    }
  }
}

7.2 安全设置

# 安全审计
openclaw security audit

# 密钥管理
openclaw secrets reload

# 批准管理
openclaw approvals get|set

7.3 远程访问

# Tailscale配置
openclaw gateway remote

# SSH访问
openclaw gateway remote --ssh

# 仪表板远程访问
openclaw dashboard --remote

8. 故障排除

8.1 常见问题

# 检查网关状态
openclaw gateway status --deep

# 查看详细日志
openclaw logs --follow --level debug

# 运行诊断
openclaw doctor

8.2 性能优化

# 调整日志级别
openclaw config set logging.level warn

# 优化模型加载
openclaw models set-image provider.model

# 清理缓存
openclaw memory index --clean

9. 更新与维护

9.1 更新OpenClaw

# 检查更新
openclaw update status

# 执行更新
openclaw update wizard

# 修复更新
openclaw update repair

9.2 备份与迁移

# 创建备份
openclaw backup create

# 验证备份
openclaw backup verify

# 迁移配置
openclaw migrate apply provider

9.3 卸载

# 卸载OpenClaw
openclaw uninstall

# 重置配置
openclaw reset

10. 最佳实践

  1. 定期备份: 使用 openclaw backup create 定期备份配置
  2. 监控日志: 使用 openclaw logs --follow 监控系统状态
  3. 安全配置: 限制通道访问,设置 allowFrom 列表
  4. 插件管理: 只安装信任的插件,定期检查插件状态
  5. 性能优化: 根据使用情况调整日志级别和模型配置
  6. 更新维护: 定期检查更新,及时应用安全补丁

文档版本: 2026年7月
来源: OpenClaw官方文档
最后更新: 2026-07-13

标签: none

添加新评论