🦞 OpenClaw 在 Linux 上的简单部署全过程

OpenClaw 是一个开源的 AI 个人助手框架,核心是 Gateway(网关服务)和 Agent(AI 智能体)。本文档覆盖从零开始在 Linux 服务器上部署 OpenClaw 的完整流程。

目录

  1. 系统要求
  2. 方法一:一键安装(推荐)
  3. 方法二:npm 手动安装
  4. 方法三:Docker 部署
  5. 方法四:从源码构建
  6. 首次配置(Onboarding)
  7. 作为系统服务运行(systemd)
  8. VPS / 服务器调优
  9. 验证安装
  10. 日常管理与更新
  11. 卸载
  12. 常见问题

1. 系统要求

  • 操作系统 — Linux(Ubuntu/Debian/Fedora/RHEL/Alpine 均支持,含 WSL2)
  • Node.js — Node 24(推荐)或 Node 22.19+
  • 内存 — 至少 512MB(建议 1GB+)
  • 磁盘 — 至少 2GB 可用空间
  • 网络 — 能访问 npm / GitHub
一键安装脚本会自动安装 Node.js,不需要事先装好 Node。

2. 方法一:一键安装(推荐)

最快速的安装方式。脚本自动检测系统、安装 Node.js、安装 OpenClaw。

2.1 标准安装

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

之后会提示是否启动配置向导,建议直接走完。

2.2 跳过配置向导

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

2.3 本地前缀安装(不依赖系统 Node)

将 Node 和 OpenClaw 都装到 ~/.openclaw 下:

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

2.4 安装工作流程

检测 OS → 检查/安装 Node 24 → 检查/安装 Git
     → 安装 OpenClaw → 注册 systemd 服务 →(可选)配置向导

3. 方法二:npm 手动安装

自己管理 Node.js 环境的:

npm install -g openclaw@latest
openclaw onboard --install-daemon

用 pnpm:

pnpm add -g openclaw@latest
pnpm approve-builds -g
openclaw onboard --install-daemon

如果报 EACCES 错误,切到用户目录:

mkdir -p "$HOME/.npm-global"
npm config set prefix "$HOME/.npm-global"
export PATH="$HOME/.npm-global/bin:$PATH"
# 将 export 加入 ~/.bashrc

4. 方法三:Docker 部署

前置条件

  • Docker Engine + Docker Compose v2
  • 至少 2GB 内存(1GB 机器上构建可能 OOM)

构建并启动

git clone https://github.com/openclaw/openclaw.git
cd openclaw
./scripts/docker/setup.sh

或用预构建镜像:

export OPENCLAW_IMAGE="ghcr.io/openclaw/openclaw:latest"
./scripts/docker/setup.sh
公网 VPS 上用 Docker 务必配置防火墙规则。

5. 方法四:从源码构建

适合想尝鲜最新代码的:

git clone https://github.com/openclaw/openclaw.git
cd openclaw
pnpm install && pnpm build && pnpm ui:build
pnpm link --global
openclaw onboard --install-daemon

需要提前装好 pnpm


6. 首次配置(Onboarding)

openclaw onboard

或带服务安装:

openclaw onboard --install-daemon

向导会依次让你:

  1. 选择模型提供商(Anthropic / OpenAI / Google 等)
  2. 输入 API Key
  3. 设置 Gateway Token(身份验证)
  4. 确认配置路径(默认 ~/.openclaw)

非交互式配置:

openclaw onboard --provider anthropic --api-key sk-xxx --gateway-token my-token --non-interactive

7. 作为系统服务运行(systemd)

--install-daemon 会自动配置 systemd 用户服务。

查看状态

systemctl --user status openclaw-gateway.service

手动控制

openclaw gateway stop # 停止
openclaw gateway start # 启动
openclaw gateway restart # 重启

查看日志

journalctl --user -u openclaw-gateway.service -f

调优配置

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

8. VPS / 服务器调优

开启 Node 编译缓存

小内存 VPS(1~2GB)上 CLI 响应速度提升明显:

grep -q 'NODE_COMPILE_CACHE=/var/tmp/openclaw-compile-cache' ~/.bashrc || 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

安全建议

  • 仅本机访问 — Gateway 绑定 localhost:18789(默认已安全)
  • 内网访问 — 绑定 lan,配置 gateway.auth.token
  • 公网 VPS — 优先 Tailscale 或 SSH 隧道
  • 必须暴露公网 — 务必设置 gateway.auth.tokenpassword

9. 验证安装

openclaw --version # 检查版本
openclaw doctor # 运行诊断
openclaw gateway status # 查看 Gateway 状态
openclaw dashboard # 打开浏览器控制面板

正常时 Gateway 应监听 18789 端口,浏览器打开控制面板后即可开始聊天。


10. 日常管理与更新

更新

openclaw update # CLI自更新
curl -fsSL https://openclaw.ai/install.sh | bash # 重新运行安装脚本
npm update -g openclaw # npm 手动更新

切换版本频道

openclaw update --channel dev # dev 频道(git 安装)
openclaw update --channel stable # 切回 stable

备份与迁移

tar czf openclaw-backup-$(date +%Y%m%d).tar.gz -C ~ .openclaw

在目标机器安装 OpenClaw 后解压备份到 ~/.openclaw 即可。


11. 卸载

快捷方式(CLI 还在)

openclaw uninstall --all --yes

手动卸载(CLI 已不可用)

systemctl --user disable --now openclaw-gateway.service
rm -f ~/.config/systemd/user/openclaw-gateway.service
systemctl --user daemon-reload

rm -rf ~/.openclaw
npm rm -g openclaw

12. 常见问题

openclaw: command not found

npm 全局 bin 不在 PATH 中:

export PATH="$(npm prefix -g)/bin:$PATH"
# 加入 ~/.bashrc 或 ~/.zshrc 永久生效

npm 报 EACCES 权限错误

npm 前缀指向 root 目录,切换到用户目录:

mkdir -p "$HOME/.npm-global"
npm config set prefix "$HOME/.npm-global"
export PATH="$HOME/.npm-global/bin:$PATH"

Gateway 启动失败 / 端口占用

lsof -i :18789

默认端口 18789,可在 ~/.openclaw/config.yaml 中修改。

Docker 构建 OOM(exit 137)

用预构建镜像代替本地构建:

export OPENCLAW_IMAGE="ghcr.io/openclaw/openclaw:latest"
./scripts/docker/setup.sh"

相关资源


本文档基于 OpenClaw 官方文档整理。如有更新,请以 docs.openclaw.ai 为准。

标签: none

仅有一条评论

  1. 这里是岩屾,测试一下评论功能

添加新评论