在 Raspberry Pi 上运行持久化 OpenClaw Gateway,Pi 只负责 gateway,模型通过云端 API 调用,硬件成本约 $35-80 一次性投入。

硬件兼容性

型号RAM状态备注
Pi 54/8 GB最佳推荐
Pi 44 GB良好最佳性价比
Pi 42 GB可用需加 swap
Pi 41 GB勉强需 swap + 精简配置
Pi 3B+1 GB慢可用但迟缓
Pi Zero 2 W512 MB不推荐-

最低要求:1 GB RAM,1 核,500 MB 可用磁盘,64 位 OS。

安装步骤

1. 烧录 OS

使用 Raspberry Pi OS Lite (64-bit)(无桌面),通过 Raspberry Pi Imager 预配置:

  • 主机名:gateway-host
  • 启用 SSH
  • 设置用户名/密码

2. 系统初始化

ssh user@gateway-host
sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl build-essential
 
# 设置时区(cron 和提醒功能需要)
sudo timedatectl set-timezone America/Chicago

3. 安装 Node.js 24

curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
sudo apt install -y nodejs

4. 添加 Swap(2 GB 及以下必须)

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile && sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

5. 安装 OpenClaw

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

Onboarding 向导中,无头设备推荐使用 API key 而非 OAuth,Telegram 是最易上手的 channel。

6. 验证

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

7. 访问 Control UI

# 在 Pi 上获取 dashboard URL
ssh user@gateway-host 'openclaw dashboard --no-open'
 
# 本地建立 SSH 隧道
ssh -N -L 18789:127.0.0.1:18789 user@gateway-host
# 浏览器打开 http://127.0.0.1:18789/

性能优化

使用 USB SSD:SD 卡慢且易损耗,USB SSD 显著提升性能。

启用模块编译缓存:

cat >> ~/.bashrc <<'EOF'
export NODE_COMPILE_CACHE=/var/tmp/openclaw-compile-cache
mkdir -p /var/tmp/openclaw-compile-cache
export OPENCLAW_NO_RESPAWN=1
EOF
source ~/.bashrc

减少 GPU 内存(无头设备):

echo 'gpu_mem=16' | sudo tee -a /boot/config.txt
sudo systemctl disable bluetooth

systemd 服务加固:

systemctl --user edit openclaw-gateway.service
[Service]
Environment=OPENCLAW_NO_RESPAWN=1
Environment=NODE_COMPILE_CACHE=/var/tmp/openclaw-compile-cache
Restart=always
RestartSec=2
TimeoutStartSec=90
systemctl --user daemon-reload && systemctl --user restart openclaw-gateway.service
sudo loginctl enable-linger "$(whoami)"

推荐模型配置

Pi 只运行 gateway,不要在 Pi 上跑本地 LLM,使用云端 API:

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "anthropic/claude-sonnet-4-6",
        "fallbacks": ["openai/gpt-5.4-mini"]
      }
    }
  }
}

常见问题

  • OOM:free -h 确认 swap 激活,禁用 cups bluetooth avahi-daemon
  • 性能慢:换 USB SSD,vcgencmd get_throttled 检查 CPU 限速(应为 0x0)
  • 服务不启动:journalctl --user -u openclaw-gateway.service --no-pager -n 100,确认 lingering 已启用
  • ARM 二进制问题:uname -m 确认为 aarch64,检查 skill 是否有 ARM64 构建
  • WiFi 断连:sudo iwconfig wlan0 power off

相关链接