OpenClaw 部署完全指南:从零搭建个人 AI 助手
推荐:使用 Coding Plan 套餐更省钱!本文包含手动部署和阿里云服务器部署教程。
什么是 OpenClaw?
OpenClaw 是一款开源的个人 AI 助手,你可以在自己的设备上运行它。它支持多种消息渠道(WhatsApp、Telegram、Slack、Discord、微信等),能够执行浏览器自动化、定时任务、文件管理等操作,真正实现”你的数据,你的控制”。
为什么选择 OpenClaw?
- 🔒 隐私优先 :数据完全本地存储,不上传云端
- 🤖 多模型支持 :OpenAI、Claude、Gemini 等主流模型
- 📱 多平台接入 :支持 20+ 种消息渠道
- 🛠️ 丰富工具集 :浏览器控制、定时任务、Canvas 可视化
- 💰 成本可控:相比订阅制服务,自托管更经济
准备工作
系统要求
- Node.js: ≥ 22
- 操作系统 : macOS、Linux 或 Windows
- 内存 : 至少 2GB(Docker 部署建议 4GB)
- 磁盘: 至少 5GB 可用空间
推荐服务器配置
| 用途 | 配置 | 月费参考 |
|---|---|---|
| 个人使用 | 2 核 4G | ¥50-80 |
| 多人共享 | 4 核 8G | ¥100-150 |
💡 省钱提示:使用 Coding Plan 套餐(如阿里云 / 腾讯云的开发者套餐)通常更划算!
方法一:手动部署(推荐)
Linux/macOS 部署
1. 安装 Node.js
# 使用 nvm 安装(推荐)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 22
nvm use 22
# 验证安装
node --version # 应显示 v22.x.x
2. 安装 OpenClaw
# 使用 npm 全局安装
npm install -g openclaw@latest
# 或使用 pnpm(更快)
pnpm add -g openclaw@latest
3. 运行引导向导
# 启动安装向导并安装守护进程
openclaw onboard --install-daemon
向导会引导你完成:
- 配置工作目录
- 设置消息渠道(WhatsApp/Telegram 等)
- 配置 AI 模型(OpenAI/Claude API Key)
- 安装系统服务(systemd/launchd)
4. 启动 Gateway
# 前台启动(调试用)
openclaw gateway --port 18789 --verbose
# 或使用 systemd 服务(已安装守护进程)
systemctl --user start openclaw-gateway
5. 验证安装
# 检查网关状态
openclaw gateway status
# 发送测试消息
openclaw agent --message " 你好,OpenClaw!"
Windows 部署(原生支持)
OpenClaw 官方支持 Windows 原生部署,无需 WSL2。
1. 安装 Node.js
方式一:使用官方安装包(推荐)
- 访问 Node.js 官网 下载 Windows 安装包
- 选择 LTS 版本 (当前推荐 v22.x)
- 运行安装程序,按向导完成安装
方式二:使用 nvm-windows
# 使用 PowerShell 安装 nvm-windows
# 下载地址:https://github.com/coreybutler/nvm-windows/releases
# 安装 Node.js 22
nvm install 22.0.0
nvm use 22.0.0
# 验证安装
node --version
npm --version
2. 安装 OpenClaw
# 使用 npm 全局安装(管理员权限)
npm install -g openclaw@latest
# 或使用 pnpm(更快)
pnpm add -g openclaw@latest
3. 运行引导向导
# 启动安装向导
openclaw onboard
# 安装为 Windows 服务(可选,需要管理员权限)
openclaw onboard --install-daemon
向导会引导你完成:
- 配置工作目录
- 设置消息渠道(WhatsApp/Telegram 等)
- 配置 AI 模型(OpenAI/Claude API Key)
4. 启动 Gateway
# 前台启动(调试用)
openclaw gateway --port 18789 --verbose
# 或使用 Windows 服务(如果已安装)
net start openclaw-gateway
5. 验证安装
# 检查网关状态
openclaw gateway status
# 发送测试消息
openclaw agent --message " 你好,OpenClaw!"
6. 防火墙配置
如果无法从其他设备访问,需要配置 Windows 防火墙:
# 以管理员身份运行 PowerShell
# 添加入站规则
netsh advfirewall firewall add rule name="OpenClaw Gateway" dir=in action=allow protocol=tcp localport=18789
# 查看规则
netsh advfirewall firewall show rule name="OpenClaw Gateway"
Windows 常见问题
Q: 安装时提示权限不足?
# 以管理员身份运行 PowerShell 或 CMD
# 右键点击 PowerShell -> 以管理员身份运行
Q: 如何设置开机自启?
# 使用 --install-daemon 参数安装时会自动创建 Windows 服务
# 手动启动服务
net start openclaw-gateway
# 停止服务
net stop openclaw-gateway
Q: 配置文件在哪里?
# 默认配置目录
%USERPROFILE%\.openclaw\
# 例如:
C:\Users\YourName\.openclaw\Q: 如何卸载 OpenClaw?
# 卸载全局包
npm uninstall -g openclaw
# 删除配置目录(可选)
Remove-Item -Recurse -Force "$env:USERPROFILE\.openclaw"
方法二:Docker 部署
适合需要隔离环境或在服务器上快速部署的场景。
1. 克隆仓库
git clone https://github.com/openclaw/openclaw.git
cd openclaw
2. 运行 Docker 安装脚本
# 一键安装
./docker-setup.sh
脚本会自动:
- 构建 Gateway 镜像
- 运行配置向导
- 生成访问令牌
- 启动 Docker Compose 服务
3. 访问 Control UI
# 获取访问地址
openclaw dashboard
# 或手动打开
open http://127.0.0.1:18789
4. Docker 常用命令
# 查看日志
docker compose logs -f openclaw-gateway
# 重启服务
docker compose restart openclaw-gateway
# 更新到最新版本
docker compose pull && docker compose up -d
方法三:阿里云服务器部署
1. 选购服务器
推荐配置:
- 实例类型 :ECS 共享型 s6 / 突发性能 t6
- 配置 :2 核 4G 或 2 核 2G(个人使用)
- 系统 :Ubuntu 22.04 LTS 或 CentOS 8
- 带宽:1-3Mbps(足够)
💰 Coding Plan 省钱攻略:
- 阿里云「云服务器 ECS」新用户首年 ¥99
- 腾讯云「轻量应用服务器」新用户 ¥50/ 年
- 华为云「云耀云服务器」开发者套餐
2. 安全组配置
在阿里云控制台配置安全组规则:
| 类型 | 端口 | 来源 | 用途 |
|---|---|---|---|
| 自定义 TCP | 18789 | 0.0.0.0/0 | OpenClaw Gateway |
| 自定义 TCP | 3000 | 0.0.0.0/0 | Web UI(可选) |
| SSH | 22 | 你的 IP | 远程管理 |
3. 服务器初始化
# 更新系统
sudo apt update && sudo apt upgrade -y
# 安装必要工具
sudo apt install -y curl git vim
# 安装 Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs
# 验证
node --version
npm --version
4. 安装并配置 OpenClaw
# 安装 OpenClaw
sudo npm install -g openclaw@latest
# 创建专用用户(推荐)
sudo useradd -m -s /bin/bash openclaw
sudo su - openclaw
# 运行向导
openclaw onboard --install-daemon
5. 配置公网访问
编辑配置文件:
openclaw config edit
修改 Gateway 绑定设置:
{
"gateway": {
"bind": "lan",
"port": 18789,
"controlUi": {"allowedOrigins": ["http:// 你的服务器 IP:18789"]
}
}
}
6. 配置 systemd 服务
# 重新加载配置
systemctl --user daemon-reload
systemctl --user enable openclaw-gateway
systemctl --user start openclaw-gateway
# 查看状态
systemctl --user status openclaw-gateway
7. 配置反向代理(可选但推荐)
使用 Nginx 配置 HTTPS:
# 安装 Nginx
sudo apt install -y nginx
# 配置站点
sudo tee /etc/nginx/sites-available/openclaw << EOF
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://127.0.0.1:18789;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
EOF
# 启用配置
sudo ln -s /etc/nginx/sites-available/openclaw /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
配置消息渠道
Telegram 机器人配置
# 1. 在 Telegram 搜索 @BotFather,创建新机器人
# 2. 获取 Bot Token
# 3. 配置 OpenClaw
openclaw channels telegram configure --token " 你的 BotToken"
# 4. 启动渠道
openclaw channels telegram start
微信配置(通过企业微信)
# 配置企业微信
openclaw channels wecom configure \
--corp-id " 你的 CorpID" \
--corp-secret " 你的 Secret" \
--agent-id " 你的 AgentID"
openclaw channels wecom start
配置 AI 模型
OpenAI 配置
openclaw models configure openai --api-key "sk- 你的 API 密钥 "
Claude 配置
openclaw models configure anthropic --api-key "sk-ant- 你的 API 密钥 "
阿里云百炼(国内推荐)
openclaw models configure dashscope --api-key " 你的 DashScope 密钥 "
常用命令速查
# 网关管理
openclaw gateway status # 查看状态
openclaw gateway start # 启动网关
openclaw gateway stop # 停止网关
openclaw gateway restart # 重启网关
# 与 AI 对话
openclaw agent --message " 你好 "
openclaw agent --message " 总结这个文件 " --attach document.pdf
# 定时任务
openclaw cron list # 列出任务
openclaw cron create --name " 每日早报 " --cron "0 8 * * *" --message " 生成今日早报 "
# 浏览器自动化
openclaw browser open https://example.com
openclaw browser snapshot
# 更新
openclaw update # 更新到最新版
openclaw doctor # 诊断问题
故障排查
1. 网关无法启动
# 检查端口占用
lsof -i :18789
# 查看日志
openclaw gateway --verbose
2. 消息渠道连接失败
# 检查配置
openclaw config get channels
# 重置渠道
openclaw channels telegram reset
3. 模型调用失败
# 检查模型配置
openclaw models list
# 测试模型连接
openclaw agent --message "test" --model openai/gpt-4
进阶配置
1. 启用定时任务
# 创建每日任务
openclaw cron create \
--name " 每日新闻 " \
--cron "0 9 * * *" \
--message " 获取今日科技新闻并总结 "
2. 配置多工作区
# 创建工作区
mkdir -p ~/workspaces/project-a
openclaw workspace use ~/workspaces/project-a
3. 安装技能
# 搜索可用技能
openclaw skills search weather
# 安装技能
openclaw skills install weather
总结
OpenClaw 是一款功能强大的个人 AI 助手,通过本文的教程,你可以:
- ✅ 在本地快速部署 OpenClaw(Linux/macOS/Windows)
- ✅ 在阿里云等云服务器上部署
- ✅ 配置消息渠道和 AI 模型
- ✅ 使用 Coding Plan 套餐节省成本
推荐部署方式:
- 个人使用 :手动部署 + Coding Plan 套餐
- 团队共享:Docker 部署 + 阿里云 ECS
开始享受你的私有化 AI 助手吧!
参考资源
本文创建于 2026-03-12,基于 OpenClaw 最新版本编写。
- 什么是 OpenClaw?
- 为什么选择 OpenClaw?
- 准备工作
- 系统要求
- 推荐服务器配置
- 方法一:手动部署(推荐)
- Linux/macOS 部署
- 1. 安装 Node.js
- 2. 安装 OpenClaw
- 3. 运行引导向导
- 4. 启动 Gateway
- 5. 验证安装
- Windows 部署(原生支持)
- 1. 安装 Node.js
- 2. 安装 OpenClaw
- 3. 运行引导向导
- 4. 启动 Gateway
- 5. 验证安装
- 6. 防火墙配置
- Windows 常见问题
- 方法二:Docker 部署
- 1. 克隆仓库
- 2. 运行 Docker 安装脚本
- 3. 访问 Control UI
- 4. Docker 常用命令
- 方法三:阿里云服务器部署
- 1. 选购服务器
- 2. 安全组配置
- 3. 服务器初始化
- 4. 安装并配置 OpenClaw
- 5. 配置公网访问
- 6. 配置 systemd 服务
- 7. 配置反向代理(可选但推荐)
- 配置消息渠道
- Telegram 机器人配置
- 微信配置(通过企业微信)
- 配置 AI 模型
- OpenAI 配置
- Claude 配置
- 阿里云百炼(国内推荐)
- 常用命令速查
- 故障排查
- 1. 网关无法启动
- 2. 消息渠道连接失败
- 3. 模型调用失败
- 进阶配置
- 1. 启用定时任务
- 2. 配置多工作区
- 3. 安装技能
- 总结
- 参考资源