Skip to content

VPS 5 分钟部署

从零到一个能用的 OpenClaw 实例,目标:5 分钟内完成。

前置条件

  • 一台 VPS(Ubuntu 22.04/24.04 推荐,1GB+ 内存)
  • SSH 访问
  • 至少一个模型 Provider 的 API Key(没有的话用 Ollama 免费方案

步骤

1. 安装

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

脚本会自动:

  • 检测/安装 Node.js 24
  • 全局安装 OpenClaw CLI
  • 启动 onboarding 向导

2. Onboarding 向导

向导会依次问你:

  1. 选择模型 Provider — 推荐 Anthropic(最稳)或 OpenRouter(最灵活)
  2. 输入 API Key
  3. 选择 Channel(可跳过,后续配置)
  4. 安装系统服务 — 选 Yes,自动配置 systemd

3. 验证

bash
# 检查整体状态
openclaw status

# 检查 Gateway
openclaw gateway status

# 检查配置问题
openclaw doctor

✅ 成功标准:

  • Gateway 显示 runningactive
  • healthz 检查返回 {"ok":true,"status":"live"}
  • openclaw doctor 无 CRITICAL 错误

4. 连接 Channel

以 Telegram 为例(最快接入):

bash
# 方式一:向导
openclaw channels add --channel telegram --token "YOUR_BOT_TOKEN"

# 方式二:直接写配置
openclaw config set channels.telegram.enabled true
openclaw config set channels.telegram.botToken "YOUR_BOT_TOKEN"
openclaw config set channels.telegram.allowFrom '["*"]'

# 重启 Gateway
openclaw gateway restart

验证 Channel 配置:

bash
# 查看已配置的 Channel
openclaw channels list

# 查看实时日志(确认连接成功)
openclaw logs --follow

5. 安全加固(生产环境必做)

bash
# 防火墙:只开 SSH
ufw allow 22/tcp
ufw enable

# 验证防火墙状态
ufw status

# Gateway 默认绑定 127.0.0.1,不对外暴露
# 确认绑定地址
grep -i bind ~/.openclaw/openclaw.json

WARNING

Gateway 端口 18789 不应该对公网开放。它默认绑定 loopback,保持这个设置。

系统服务管理

OpenClaw 已安装为 systemd 用户服务,常用命令:

bash
# 查看状态
systemctl --user status openclaw-gateway

# 重启
systemctl --user restart openclaw-gateway

# 停止
systemctl --user stop openclaw-gateway

# 查看日志
journalctl --user -u openclaw-gateway -f

# 开机自启(必须执行,否则退出 SSH 后服务会停止)
loginctl enable-linger $(whoami)

配置文件速查

安装完成后,核心配置在 ~/.openclaw/openclaw.json

json5
{
  // 模型配置
  agents: {
    defaults: {
      model: { primary: "anthropic/claude-sonnet-4-5" },
      workspace: "~/.openclaw/workspace",
      heartbeat: { every: "30m" },
    }
  },
  // Channel 配置
  channels: {
    telegram: {
      enabled: true,
      botToken: "xxx:yyy",
      dmPolicy: "pairing",  // 首次连接需配对确认
    }
  }
}

常见问题

Q: openclaw 命令找不到?

bash
# 检查 npm 全局路径是否在 PATH 中
echo $PATH
npm prefix -g
# 如果不在,添加:
export PATH="$(npm prefix -g)/bin:$PATH"
echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.bashrc

Q: Gateway 启动失败?

bash
# 检查端口占用
lsof -i :18789
# 检查日志
openclaw logs --follow
# 运行诊断
openclaw doctor

Q: 内存不够 (OOM killed)?

Docker 构建需要 2GB+,纯 npm 安装 1GB 够用。如果是 sharp 编译 OOM:

bash
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install -g openclaw@latest

Q: 退出 SSH 后 Gateway 停止?

bash
# 启用 linger,让 systemd 用户服务在退出 SSH 后继续运行
loginctl enable-linger $(whoami)

成本估算

云服务商实例规格月成本
Vultr1GB/1vCPU$6
DigitalOcean1GB/1vCPU$6
Hetzner2GB/1vCPU€5
AWS Lightsail1GB/1vCPU$3.5 (前 3 个月免费)

下一步

基于 OpenClaw 开源项目