OpenClaw VPS Deploy
Deploy OpenClaw (official or custom fork) to a Hostinger VPS with full cloud access.
Quick Deploy
CODEBLOCK0
The script auto-reads ANTHROPIC_API_KEY from the local OpenClaw vault (~/.openclaw/secrets.json) or environment. Pass --anthropic to override.
What the Script Does
- 1. Connects via SSH (key auth — required, password auth often disabled on Hostinger)
- Installs Node.js 22 via nodesource apt repo
- Installs OpenClaw — either
npm install -g <package> or git clone + INLINECODE4 - Writes
openclaw.json with correct schema (see critical notes below) - Installs systemd service — auto-starts on reboot, restarts on crash
- Opens UFW ports — SSH (22) + gateway port
- Saves auth token to local vault as INLINECODE6
SSH Key on WSL2
The user's Windows SSH key is accessible at /mnt/c/Users/<username>/.ssh/id_ed25519 in WSL2. Copy it with correct permissions before use:
CODEBLOCK1
Getting the Server IP
From the Hostinger tab in the Control dashboard (VPS Servers section), or via API:
CODEBLOCK2
Critical Notes (Read Before Manually Deploying)
See references/gotchas.md for full details on every failure mode. Key points:
- 1. Never use
openclaw gateway start as ExecStart — use INLINECODE10 - Config schema: use
agents.list[] not agents.default (causes schema error) - Set
gateway.mode — required, use "remote" for cloud access - Set
XDG_RUNTIME_DIR=/run/user/0 in systemd + INLINECODE16 - Add public IP to
allowedOrigins — otherwise the UI blocks non-localhost connections - Performance: always set
OPENCLAW_NO_RESPAWN=1 and INLINECODE19
Correct openclaw.json Schema
CODEBLOCK3
Correct systemd Unit
CODEBLOCK4
Managing a Live Instance
CODEBLOCK5
Accessing the UI
Navigate to http://SERVER_IP:18789. When prompted for an auth token, use the value stored in:
- - Local vault: INLINECODE21
- Or retrieve: INLINECODE22
Multi-Agent VPS Setup
One VPS can run multiple isolated agents on separate ports, each with its own Cloudflare URL. No core OpenClaw changes needed — use --config-dir per agent.
See references/multi-agent.md for: port allocation, per-agent systemd services, provisioning script, resource planning, and Cloudflare tunnel integration.
CODEBLOCK6
Dependencies
- -
paramiko Python package (auto-installed by deploy.py if missing) - SSH private key with access to the target VPS
- INLINECODE26 in vault or environment
技能名称: openclaw-vps-deploy
详细描述:
OpenClaw VPS 部署
将 OpenClaw(官方版或自定义分支)部署到 Hostinger VPS,支持完整的云端访问。
快速部署
bash
官方包(最常见)
python3 scripts/deploy.py \
--ip 187.124.84.25 \
--key ~/.ssh/id_ed25519 \
--name Koda
自定义 Git 分支
python3 scripts/deploy.py \
--ip 187.124.84.25 \
--key ~/.ssh/id_ed25519 \
--repo https://github.com/your-org/openclaw \
--name Koda \
--gw-port 18789
脚本会自动从本地 OpenClaw 保险库(~/.openclaw/secrets.json)或环境中读取 ANTHROPICAPIKEY。使用 --anthropic 参数可覆盖。
脚本执行流程
- 1. 通过 SSH 连接(密钥认证——必需,Hostinger 通常禁用密码认证)
- 安装 Node.js 22(通过 nodesource apt 仓库)
- 安装 OpenClaw——执行 npm install -g 或 git clone + pnpm build
- 写入 openclaw.json(使用正确的 schema,参见下方关键说明)
- 安装 systemd 服务——开机自启,崩溃自动重启
- 开放 UFW 端口——SSH(22)+ 网关端口
- 将认证令牌保存到本地保险库,键名为 OPENCLAWVPS_TOKEN
WSL2 中的 SSH 密钥
用户的 Windows SSH 密钥在 WSL2 中位于 /mnt/c/Users/<用户名>/.ssh/id_ed25519。使用前需复制并设置正确权限:
bash
cp /mnt/c/Users/charl/.ssh/ided25519 /tmp/vpskey
chmod 600 /tmp/vps_key
python3 scripts/deploy.py --ip 1.2.3.4 --key /tmp/vps_key
获取服务器 IP
通过控制面板的 Hostinger 标签页(VPS 服务器部分),或通过 API:
bash
mcporter call hostinger-api.VPS_getVirtualMachinesV1 2>&1 | \
python3 -c import json,sys; [print(v[id], v[ipv4][0][address], v[hostname]) for v in json.load(sys.stdin) if v.get(ipv4)]
关键说明(手动部署前必读)
所有失败模式的完整细节请参见 references/gotchas.md。要点如下:
- 1. 切勿使用 openclaw gateway start 作为 ExecStart——应使用 openclaw gateway --bind lan --auth token --allow-unconfigured
- 配置 schema:使用 agents.list[] 而非 agents.default(会导致 schema 错误)
- 设置 gateway.mode——必填,云端访问使用 remote
- 在 systemd 中设置 XDGRUNTIMEDIR=/run/user/0 并执行 mkdir -p /run/user/0
- 将公网 IP 添加到 allowedOrigins——否则 UI 会阻止非 localhost 的连接
- 性能优化:务必设置 OPENCLAWNORESPAWN=1 和 NODECOMPILECACHE
正确的 openclaw.json Schema
json
{
agents: {
defaults: {
model: { primary: anthropic/claude-sonnet-4-6 }
},
list: [
{ id: main, default: true, name: Koda }
]
},
env: {
ANTHROPICAPIKEY: sk-ant-...
},
gateway: {
port: 18789,
bind: lan,
mode: remote,
auth: { mode: token, token: your-token },
controlUi: {
allowedOrigins: [
http://localhost:18789,
http://127.0.0.1:18789,
http://YOUR.SERVER.IP:18789
]
}
}
}
正确的 systemd 单元
ini
[Unit]
Description=OpenClaw Gateway
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/root
ExecStart=/usr/bin/openclaw gateway --bind lan --port 18789 --auth token --allow-unconfigured
Restart=always
RestartSec=5
Environment=HOME=/root
Environment=OPENCLAWNORESPAWN=1
Environment=NODECOMPILECACHE=/var/tmp/openclaw-compile-cache
Environment=XDGRUNTIMEDIR=/run/user/0
[Install]
WantedBy=multi-user.target
管理运行中的实例
bash
查看状态
ssh root@SERVER_IP systemctl status openclaw
查看日志(实时)
ssh root@SERVER_IP journalctl -u openclaw -f
重启
ssh root@SERVER_IP systemctl restart openclaw
更新 OpenClaw(npm)
ssh root@SERVER_IP npm install -g openclaw && systemctl restart openclaw
更新自定义分支(git)
ssh root@SERVER_IP cd /opt/openclaw && git pull && pnpm install && pnpm build && systemctl restart openclaw
访问 UI
在浏览器中访问 http://SERVER_IP:18789。提示输入认证令牌时,使用以下位置存储的值:
- - 本地保险库:OPENCLAWVPSWITHUNDERSCORES>_TOKEN
- 或通过命令获取:python3 -c import json; v=json.load(open(/home/charl/.openclaw/secrets.json)); [print(k,v[k]) for k in v if VPS in k and TOKEN in k]
多代理 VPS 设置
一台 VPS 可以在不同端口上运行多个隔离的代理,每个代理拥有独立的 Cloudflare URL。无需修改 OpenClaw 核心——每个代理使用 --config-dir 参数即可。
端口分配、每个代理的 systemd 服务、配置脚本、资源规划以及 Cloudflare 隧道集成,请参见 references/multi-agent.md。
bash
每个代理 = 独立端口上的独立网关
openclaw gateway --config-dir /root/agents/koda --port 18789
openclaw gateway --config-dir /root/agents/alex --port 18790
依赖项
- - paramiko Python 包(若缺失,deploy.py 会自动安装)
- 具有目标 VPS 访问权限的 SSH 私钥
- 保险库或环境中的 ANTHROPICAPIKEY