部署 Openclaw

使用官方部署方式, 需要注意网络问题,本次部署机为 德国 vps。
一键安装
curl -fsSL https://openclaw.ai/install.sh | bash
选择 codex 认证:
它会自动做的事:
- 检测到你已经安装了 OpenClaw
- 下载最新版本
- 原地升级(in-place upgrade)
- 自动运行 openclaw doctor 检查
- 重启服务
# 检查当前版本和是否有更新
openclaw update status
# 一键安全更新(推荐)
openclaw update
# 更新后不自动重启服务(可选)
openclaw update --no-restart
卸载#
# 1. 用内置卸载器彻底删除(服务 + 数据 + 配置)
openclaw uninstall --all --yes --non-interactive
# 2. 强制删除所有残留文件夹(最重要!Grok 的缓存全在这里)
rm -rf ~/.openclaw
rm -rf ~/.clawdbot
rm -rf ~/clawdbot
# 3. 删除全局 CLI(防止旧命令残留)
npm uninstall -g openclaw || pnpm remove -g openclaw || bun remove -g openclaw
# 4. 杀掉所有可能残留进程
pkill -9 -f openclaw || true
pkill -9 -f clawdbot || true
配置tg 机器人#
去 @BotFather 创建机器人 输入 /newbot 就可以,后面配置信息就可以了。
跟机器人对话后,xxxx 就是Pairing code:
这样可以只让这个用户进行操作
openclaw pairing approve telegram xxxx
第1步:关闭 Privacy Mode(最关键!)
- 打开 Telegram,搜索 @BotFather
- 发送 /setprivacy
- 选择你的机器人(@claxxxxx)
- 选择 Disable(关闭隐私模式)
- BotFather 会回复 “Privacy mode is disabled for ...”
第2步:把机器人设为群组管理员
- 进入群组 “ai投资论”
- 点击群组名称 → “管理群组” 或 “添加管理员”
- 找到你的机器人 @claw_987_ai_bot,点击添加为管理员
- 务必勾上以下权限:
- 发送消息
- 读取所有群组消息(Read all group messages)← 这个最重要!
- 发送媒体消息(可选)
错误解决#
跨域解决#
origin not allowed (open the Control UI from the gateway host or allow it in gateway.controlUi.allowedOrigins)
vim ~/.openclaw/openclaw.json
"gateway": {
"bind": "0.0.0.0",
"port": 18789,
"controlUi": {
"allowedOrigins": [
"https://openclaw.jacin.me",
"http://localhost:18789",
"http://127.0.0.1:18789"
],
"allowInsecureAuth": true
}
}
设备允许#
pairing required
This device needs pairing approval from the gateway host.
openclaw devices list
openclaw devices approve
这是 OpenClaw 故意设置的安全机制(2026 年版本加强的),不是 bug。
意思是:你从浏览器第一次访问网页仪表盘时,OpenClaw 把这个浏览器当成“新设备”,需要你在服务器上手动批准一次,才能正常使用 Logs、Channels、Chat 等功能。
之前 origin not allowed 解决了之后,这个 pairing 就会跳出来。
# 1. 查看需要批准的设备列表
openclaw devices list
Pending requests:
requestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
device: openclaw-control-ui
IP: 你的IP
time: just now
# 2. 批准(把 xxxxxxxx 换成你看到的实际 requestId)
openclaw devices approve xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
或者直接批准所有 pending 的(最快):
Bash
openclaw devices approve --all
Docker 沙盒模式#
如果你担心 OpenClaw 直接运行在宿主机上权限太高,可以开启 Docker 沙盒模式。
这一模式不是把整个 OpenClaw 搬进 Docker,而是:
- Gateway、配置、Bot Token、会话数据,仍然保留在宿主机 ~/.openclaw
- 只有 agent 的工具执行(如 exec、read、write、edit、apply_patch、process)改为在 Docker 容器里运行
也就是说:
原有数据不会丢,现有 URL token、Telegram 配置、历史会话都可以无缝保留。
文档: https://docs.openclaw.ai/gateway/sandboxing
先决条件#
服务器需要先安装好 Docker,并确保 daemon 可用:
docker --version docker info
如果这两个命令都正常,就可以继续。
———
方式说明#
OpenClaw 官方默认沙盒镜像名是:
openclaw-sandbox:bookworm-slim
但要注意:
全局 npm 安装的 openclaw 包里,通常不会自带 Dockerfile.sandbox。
所以如果你是像我这样直接在 VPS 上全局安装的 OpenClaw,通常需要手动从官方仓库拉取 Dockerfile.sandbox,然后本地构建一次镜像。
———
构建官方沙盒镜像#
第1步:下载官方 Dockerfile.sandbox#
mkdir -p ~/openclaw-sandbox-build
curl -fsSL https://raw.githubusercontent.com/openclaw/openclaw/main/Dockerfile.sandbox
-o ~/openclaw-sandbox-build/Dockerfile.sandbox
第2步:本地构建镜像#
docker build -t openclaw-sandbox:bookworm-slim
-f ~/openclaw-sandbox-build/Dockerfile.sandbox
~/openclaw-sandbox-build
构建完成后可以检查:
docker images | grep openclaw-sandbox
———
修改 OpenClaw 配置#
编辑:
vim ~/.openclaw/openclaw.json
在 agents.defaults 下增加 sandbox 配置,例如:
{ "agents": { "defaults": { "model": { "primary": "openai-codex/gpt-5.3-codex" }, "workspace": "/root/.openclaw/workspace", "sandbox": { "mode": "all", "scope": "agent", "workspaceAccess": "none", "docker": { "image": "openclaw-sandbox:bookworm-slim", "readOnlyRoot": true, "tmpfs": [ "/tmp", "/var/tmp", "/run" ], "network": "none" } } } } }
这几个配置的含义#
- mode: "all" 所有会话都进入 Docker 沙盒
- scope: "agent" 每个 agent 共用一个沙盒容器
- workspaceAccess: "none" 容器看不到宿主机真实工作区
- readOnlyRoot: true 容器根文件系统只读
- network: "none" 容器默认不能联网
这套是比较稳妥的安全配置。
———
可选:继续收紧高危工具#
如果你还想进一步降权,可以加上:
{ "tools": { "deny": [ "browser", "canvas", "nodes", "cron", "gateway" ], "fs": { "workspaceOnly": true } } }
这样会额外禁掉一些高风险宿主机能力。
———
重启服务#
改完配置后执行:
openclaw gateway restart
或者:
systemctl restart openclaw-gateway
———
验证是否生效#
1. 查看沙盒策略#
openclaw sandbox explain --json
如果看到这些字段,说明已经生效:
"mode": "all", "workspaceAccess": "none", "sessionIsSandboxed": true
2. 实际跑一次 agent#
比如发送一条测试消息后,再看返回结果中的 workspaceDir。
如果已经变成类似:
/root/.openclaw/sandboxes/agent-main-xxxxx
说明 agent 已经不再直接使用宿主机工作目录,而是在 Docker 沙盒里运行。
———
这一模式的核心结论#
- 不会丢失原有数据
- 不会丢失 Telegram 配置
- 不会丢失 gateway token
- 不会丢失历史会话
- 只是把工具执行从宿主机切换到 Docker 沙盒
所以它更适合已经在线上跑起来的 OpenClaw 机器做“原地加固”。
全程可以借助 codex -cli 完成所有的搭建。
———
评论
还没有评论,来发第一个吧