LFZ 的技术笔记

低配 VPS 部署 OpenClaw 完整指南

OpenClaw 是一个轻量的 AI Agent 网关工具。在低配 VPS(1核1G甚至更低)上部署时,需要一些特别的步骤来避免 systemd 服务错误。本文记录完整流程。

一、安装基本依赖

1. 安装 curl

sudo apt-get install -y curl

2. 添加 NodeSource 官方源(Node 22)

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash -

3. 安装 Node.js

sudo apt-get install -y nodejs

4. 确认版本

node -v
npm -v

二、安装 OpenClaw

npm install -g openclaw@latest
openclaw --version

三、配置与 systemd 服务

直接运行 openclaw onboard 开始配置。但 root 用户下会报服务错误,需要手动创建 systemd 服务文件。

第一步:创建 systemd 服务文件

cat > /etc/systemd/system/openclaw-gateway.service << 'EOF'
[Unit]
Description=OpenClaw Gateway
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/.openclaw
ExecStart=/usr/bin/openclaw gateway
Restart=always
RestartSec=3
Environment=NODE_OPTIONS=--max-old-space-size=512
Environment=OPENCLAW_NO_RESPAWN=1
Environment=NODE_COMPILE_CACHE=/var/tmp/openclaw-compile-cache
Environment=HOME=/root

[Install]
WantedBy=multi-user.target
EOF

第二步:设置运行时目录(如仍报错)

如果仍然报运行时目录错误,执行:

export XDG_RUNTIME_DIR=/run/user/$(id -u)
loginctl enable-linger root
echo 'export XDG_RUNTIME_DIR=/run/user/$(id -u)' >> ~/.bashrc

第三步:启动服务

systemctl --user daemon-reload
systemctl --user enable openclaw-gateway.service
systemctl --user start openclaw-gateway.service

第四步:确认状态

openclaw status

四、网关诊断与 Cerebras 配置参考

网关诊断

openclaw gateway probe
openclaw gateway restart   # 重启服务

Cerebras API 配置示例

在 OpenClaw 配置中添加 Cerebras 作为 provider:

{
  "models": {
    "providers": {
      "cerebras": {
        "baseUrl": "https://api.cerebras.ai/v1",
        "apiKey": "你的Cerebras API Key",
        "api": "openai-completions",
        "models": [
          {
            "id": "gpt-oss-120b",
            "name": "gpt-oss-120b",
            "contextWindow": 128000,
            "maxTokens": 32000
          }
        ]
      }
    }
  }
}

五、卸载

需要完全卸载时的操作步骤:

1. 停止并禁用服务

systemctl stop openclaw-gateway.service
systemctl disable openclaw-gateway.service

2. 删除服务文件

rm /etc/systemd/system/openclaw-gateway.service
systemctl daemon-reload

3. 卸载 openclaw

npm uninstall -g openclaw

4. 删除数据目录

rm -rf /root/.openclaw

5. 确认进程已终止

ps aux | grep openclaw

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注