Skip to content

在 DigitalOcean 上运行 OpenClaw

目标

在 DigitalOcean 上运行持久的 OpenClaw Gateway,费用为 $6/月(或使用预留定价 $4/月)。

如果你想要 $0/月 的选项并且不介意 ARM + 特定提供商的设置,请参阅 Oracle Cloud 指南

成本对比 (2026)

提供商方案配置价格/月备注
Oracle CloudAlways Free ARM最高 4 OCPU, 24GB RAM$0ARM,容量有限 / 注册可能有问题
HetznerCX222 vCPU, 4GB RAM€3.79 (~$4)最便宜的付费选项
DigitalOceanBasic1 vCPU, 1GB RAM$6易用的 UI,良好的文档
VultrCloud Compute1 vCPU, 1GB RAM$6很多机房位置
LinodeNanode1 vCPU, 1GB RAM$5现在是 Akamai 的一部分

选择提供商:

  • DigitalOcean: 最简单的用户体验 + 可预测的设置(本指南)
  • Hetzner: 良好的性价比(参见 Hetzner 指南)
  • Oracle Cloud: 可以是 $0/月,但更挑剔且仅支持 ARM(参见 Oracle 指南)

前提条件

1) 创建 Droplet

  1. 登录 DigitalOcean
  2. 点击 Create → Droplets
  3. 选择:
    • Region: 离你(或你的用户)最近的地区
    • Image: Ubuntu 24.04 LTS
    • Size: Basic → Regular → $6/mo (1 vCPU, 1GB RAM, 25GB SSD)
    • Authentication: SSH key(推荐)或密码
  4. 点击 Create Droplet
  5. 记下 IP 地址

2) 通过 SSH 连接

bash
ssh root@YOUR_DROPLET_IP

3) 安装 OpenClaw

bash
# Update system
apt update && apt upgrade -y

# Install Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt install -y nodejs

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

# Verify
openclaw --version

4) 运行引导配置

bash
openclaw onboard --install-daemon

向导将引导你完成:

  • 模型认证(API 密钥或 OAuth)
  • 频道设置(Telegram、WhatsApp、Discord 等)
  • Gateway 令牌(自动生成)
  • 守护进程安装(systemd)

5) 验证 Gateway

bash
# Check status
openclaw status

# Check service
systemctl --user status openclaw-gateway.service

# View logs
journalctl --user -u openclaw-gateway.service -f

6) 访问控制面板

Gateway 默认绑定到本地回环地址。要访问控制界面:

选项 A: SSH 隧道(推荐)

bash
# From your local machine
ssh -L 18789:localhost:18789 root@YOUR_DROPLET_IP

# Then open: http://localhost:18789

选项 B: Tailscale Serve(HTTPS,仅本地回环)

bash
# On the droplet
curl -fsSL https://tailscale.com/install.sh | sh
tailscale up

# Configure Gateway to use Tailscale Serve
openclaw config set gateway.tailscale.mode serve
openclaw gateway restart

打开: https://<magicdns>/

注意:

  • Serve 保持 Gateway 仅限本地回环,并通过 Tailscale 身份标头进行身份验证。
  • 如果要使用令牌/密码认证,请设置 gateway.auth.allowTailscale: false 或使用 gateway.auth.mode: "password"

选项 C: Tailnet 绑定(不使用 Serve)

bash
openclaw config set gateway.bind tailnet
openclaw gateway restart

打开: http://<tailscale-ip>:18789 (需要令牌)。

7) 连接你的频道

Telegram

bash
openclaw pairing list telegram
openclaw pairing approve telegram <CODE>

WhatsApp

bash
openclaw channels login whatsapp
# Scan QR code

其他提供商请参见 Channels


1GB RAM 的优化

$6 的 droplet 只有 1GB RAM。为了保持流畅运行:

添加交换空间(推荐)

bash
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab

使用更轻量的模型

如果遇到 OOM 问题,考虑:

  • 使用基于 API 的模型(Claude、GPT)而不是本地模型
  • agents.defaults.model.primary 设置为更小的模型

监控内存

bash
free -h
htop

持久化

所有状态存储在:

  • ~/.openclaw/ — 配置、凭据、会话数据
  • ~/.openclaw/workspace/ — 工作空间(SOUL.md、记忆等)

这些在重启后会保留。定期备份:

bash
tar -czvf openclaw-backup.tar.gz ~/.openclaw ~/.openclaw/workspace

Oracle Cloud 免费替代方案

Oracle Cloud 提供 Always Free ARM 实例,性能明显优于这里的任何付费选项 — 而且 $0/月。

你将获得配置
4 OCPUsARM Ampere A1
24GB RAM绰绰有余
200GB 存储块存储
永久免费不会产生信用卡费用

注意事项:

  • 注册可能比较挑剔(如果失败请重试)
  • ARM 架构 — 大多数东西都能工作,但某些二进制文件需要 ARM 版本

完整设置指南请参见 Oracle Cloud。注册技巧和注册过程故障排除请参见这个社区指南


故障排除

Gateway 无法启动

bash
openclaw gateway status
openclaw doctor --non-interactive
journalctl -u openclaw --no-pager -n 50

端口已被占用

bash
lsof -i :18789
kill <PID>

内存不足

bash
# Check memory
free -h

# Add more swap
# Or upgrade to $12/mo droplet (2GB RAM)

另请参阅