之前写了一篇用几十块 VPS 跑 OpenClaw 的文章,很多人在问具体怎么安装。今天把完整的安装流程整理出来,从零开始,一步一步跟着做就能跑起来。
OpenClaw 是什么
OpenClaw 是一个可以在本地或服务器上运行的 AI 助手框架,支持接入 OpenAI GPT、Claude、Gemini 等多种大模型。简单说,就是自己搭一个私人 AI 助手,不用每个月交订阅费。
官方 GitHub:https://github.com/openclaw/openclaw
准备阶段:选 VPS
最低配置要求:
– CPU:1 核(建议 2 核)
– 内存:1GB(建议 2GB)
– 硬盘:5GB
– 系统:Ubuntu 20.04 / 22.04(本文以此为准)
推荐服务商(我自己用过的):
| 服务商 | 价格 | 配置 | 特点 |
|---|---|---|---|
| RackNerd | $9/年 | 1核/768MB | 便宜,适合入门测试 |
| 搬瓦工 | $49/年 | 2核/2GB | 稳定,延迟低 |
| 腾讯云轻量 | ¥30/月 | 2核/2GB | 国内速度快 |
本文用 RackNerd 的 $9/年套餐演示。
第一步:连接服务器
在 Mac/Linux 终端:
ssh root@你的服务器IP
在 Windows:
下载 PuTTY 或用 Windows Terminal,输入:
ssh root@你的服务器IP
首次连接会提示确认,输入 yes 回车,然后输入密码。
第二步:安装 Docker
OpenClaw 通过 Docker 运行,所以先装 Docker。
切换到 root:
sudo -i
安装 Docker:
# 安装必要依赖
apt update && apt install -y ca-certificates curl gnupg lsb-release
# 添加 Docker GPG 密钥
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# 添加 Docker 源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
# 安装 Docker
apt update && apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 启动 Docker
systemctl enable docker
systemctl start docker
# 验证安装
docker --version
看到类似 Docker version 26.x.x 的输出就说明安装成功了。
第三步:安装 OpenClaw
方法一:官方一键安装(推荐)
# 下载安装脚本
curl -fsSL https://raw.githubusercontent.com/openclaw/openclaw/main/install.sh -o install.sh
chmod +x install.sh
./install.sh
方法二:手动安装
# 拉取 OpenClaw 镜像
docker pull openclaw/openclaw:latest
# 创建数据目录
mkdir -p ~/openclaw/data
# 启动容器
docker run -d \
--name openclaw \
--restart unless-stopped \
-p 3000:3000 \
-v ~/openclaw/data:/data \
openclaw/openclaw:latest
第四步:配置 OpenClaw
容器启动后,打开浏览器访问:
http://你的服务器IP:3000
首次访问会引导你配置 API Key。
获取 API Key:
OpenAI API Key:
1. 打开 platform.openai.com
2. 登录后点右上角头像 → API Keys
3. 点击 Create new secret key
4. 复制生成的 Key(格式:sk-xxxx...)
Claude API Key:
1. 打开 console.anthropic.com
2. 登录后点 API Keys
3. 点击 Create Key,复制
填入 OpenClaw:
在 OpenClaw 界面:
1. 进入 Settings → API Keys
2. 分别填入 OpenAI 和 Claude 的 Key
3. 选择默认模型(建议 GPT-4o 或 Claude 3.5 Sonnet)
4. 点击 Save
第五步:设置域名访问(可选)
如果想用域名访问而不是 IP:端口,需要配置 Nginx 反向代理。
安装 Nginx:
apt install -y nginx
配置反向代理:
# 创建配置文件
cat > /etc/nginx/sites-available/openclaw << EOF
server {
listen 80;
server_name 你的域名;
location / {
proxy_pass http://127.0.0.1:3000;
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_cache_bypass \$http_upgrade;
}
}
EOF
# 启用配置
ln -s /etc/nginx/sites-available/openclaw /etc/nginx/sites-enabled/
nginx -t
# 重载 Nginx
systemctl reload nginx
申请 SSL 证书(可选但强烈推荐):
apt install -y certbot python3-certbot-nginx
certbot --nginx -d 你的域名
申请成功后,用 https://你的域名 访问。
常见问题
Q:docker pull 太慢或失败?
A:配置国内镜像源:
mkdir -p /etc/docker
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://mirror.ccs.tencentyun.com"]
}
EOF
systemctl restart docker
Q:打开 http://IP:3000 显示连接被拒绝?
A:检查容器是否在运行:
docker ps
docker logs openclaw
如果没有运行,重新启动:
docker start openclaw
Q:API Key 报错 “Incorrect API key provided”?
A:检查 Key 是否填对,注意不要有多余空格。也可能是余额不足,充点钱再试。
Q:想同时用 GPT 和 Claude,怎么切换?
A:在 OpenClaw 界面左上角有模型切换按钮,可以随时在对话中切换不同的模型。
一键卸载
如果哪天不想用了,完整清理:
docker stop openclaw
docker rm openclaw
docker rmi openclaw/openclaw:latest
rm -rf ~/openclaw
费用总结
整个方案的费用:
– VPS:$9/年(约 6 元/月)
– API 调用:按量收费,GPT-4o 每 100 万 token 约 $5
相比 ChatGPT Plus 的 $20/月,同样的钱自己搭可以用将近一年。
有什么问题评论区见。