适用于 OpenClaw v2026.2 | 本文适合需要 24/7 可用或多用户访问的用户。
TL;DR: 最简单方案:Tailscale("tailscale": {"mode": "serve"})。云服务器:Docker Compose 部署,推荐 2GB RAM、1 核 CPU。自建服务器:Raspberry Pi 5 或旧笔记本。安全配置:绑定 loopback,启用密码认证。SSH 隧道适合临时访问。
为什么需要远程部署?
| 场景 | 本地部署 | 远程部署 |
|---|---|---|
| 24/7 可用 | 需要电脑常开 | ✅ 随时可用 |
| 手机访问 | 需要同一网络 | ✅ 任意网络 |
| 团队共享 | ❌ 不支持 | ✅ 多人使用 |
| 家庭自动化 | 需要电脑在线 | ✅ 服务器运行 |
| 成本 | 零 | $5-20/月 |
部署方案对比
| 方案 | 难度 | 成本 | 安全性 | 适用场景 |
|---|---|---|---|---|
| Tailscale | ⭐ | 免费 | ⭐⭐⭐⭐⭐ | 个人、家庭 |
| SSH 隧道 | ⭐⭐ | 免费 | ⭐⭐⭐⭐ | 临时访问 |
| 云服务器 | ⭐⭐⭐ | $5-20/月 | ⭐⭐⭐ | 团队、生产 |
| 自建服务器 | ⭐⭐⭐⭐ | 电费+维护 | ⭐⭐⭐⭐ | 极客、隐私 |
方案一:Tailscale 私有网络
什么是 Tailscale?
Tailscale 是一个基于 WireGuard 的私有网络服务,让你可以安全地访问远程设备,无需暴露端口到公网。
安装 Tailscale
# macOS
brew install tailscale
# Ubuntu/Debian
curl -fsSL https://tailscale.com/install.sh | sh
# CentOS/RHEL
sudo dnf install tailscale
配置 Tailscale
# 登录 Tailscale
sudo tailscale up
# 查看状态
tailscale status
# 输出示例:
# 100.64.0.1 your-machine your-email@ linux -
# 获取 Tailnet 名称
tailscale debug whois
OpenClaw Tailscale 配置
{
"gateway": {
"port": 18789,
"bind": "loopback",
"tailscale": {
"mode": "serve",
"resetOnExit": true
}
}
}
| 模式 | 说明 |
|---|---|
serve |
仅 Tailnet 内可访问 |
funnel |
公开访问(需要密码认证) |
访问 Gateway
# 启动 Gateway
openclaw gateway
# 通过 Tailscale 访问
# https://your-machine.tailnet-name.ts.net
方案二:SSH 隧道
创建 SSH 隧道
# 本地转发(在本地执行)
ssh -L 18789:localhost:18789 user@remote-server
# 然后访问
# http://localhost:18789
反向隧道
# 在远程服务器执行
ssh -R 18789:localhost:18789 user@local-machine
# 然后在本地访问
# http://localhost:18789
持久化 SSH 隧道
使用 autossh:
# 安装 autossh
brew install autossh # macOS
sudo apt install autossh # Ubuntu
# 创建持久隧道
autossh -M 0 -f -N -L 18789:localhost:18789 user@remote-server
方案三:云服务器部署
选择云服务器
| 提供商 | 入门配置 | 价格 | 特点 |
|---|---|---|---|
| DigitalOcean | 2GB RAM | $12/月 | 简单易用 |
| Linode | 2GB RAM | $10/月 | 性价比高 |
| Vultr | 2GB RAM | $10/月 | 全球节点 |
| AWS Lightsail | 2GB RAM | $10/月 | AWS 生态 |
| Hetzner | 4GB RAM | €5/月 | 价格最低 |
推荐配置
| 配置项 | 最低 | 推荐 |
|---|---|---|
| CPU | 1 核 | 2 核 |
| 内存 | 2GB | 4GB |
| 存储 | 20GB | 40GB SSD |
| 带宽 | 1TB/月 | 2TB/月 |
| 系统 | Ubuntu 22.04 | Ubuntu 24.04 |
Docker 部署
# docker-compose.yml
version: '3.8'
services:
openclaw:
image: openclaw/openclaw:latest
container_name: openclaw
restart: unless-stopped
ports:
- "127.0.0.1:18789:18789"
volumes:
- ./openclaw-data:/root/.openclaw
environment:
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
- TZ=Asia/Shanghai
healthcheck:
test: ["CMD", "openclaw", "health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# 启动
docker-compose up -d
# 查看日志
docker-compose logs -f
# 更新
docker-compose pull && docker-compose up -d
系统服务部署
# 创建 systemd 服务
sudo nano /etc/systemd/system/openclaw.service
[Unit]
Description=OpenClaw Gateway
After=network.target
[Service]
Type=simple
User=openclaw
WorkingDirectory=/home/openclaw
ExecStart=/usr/local/bin/openclaw gateway --port 18789
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
# 启用服务
sudo systemctl daemon-reload
sudo systemctl enable openclaw
sudo systemctl start openclaw
# 查看状态
sudo systemctl status openclaw
反向代理配置
Nginx:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://127.0.0.1:18789;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Caddy:
your-domain.com {
reverse_proxy localhost:18789
}
方案四:自建服务器
硬件推荐
| 设备 | 价格 | 功耗 | 适用场景 |
|---|---|---|---|
| Raspberry Pi 5 | $80-120 | 5-10W | 轻量使用 |
| Intel NUC | $200-400 | 15-30W | 中等负载 |
| 旧笔记本 | 免费 | 20-40W | 预算有限 |
| Mini PC | $150-300 | 10-25W | 最佳平衡 |
家庭网络配置
# 端口转发(路由器配置)
# 外部端口 18789 -> 内部 IP:18789
# 动态 DNS
curl -u "user:password" "https://api.dynu.com/nic/update?hostname=your-domain.dynu.com"
安全配置
基础安全
# 防火墙配置
sudo ufw allow ssh
sudo ufw allow 18789/tcp
sudo ufw enable
# 禁用密码登录
sudo nano /etc/ssh/sshd_config
# PasswordAuthentication no
认证配置
{
"gateway": {
"auth": {
"mode": "password",
"password": "your-secure-password-here",
"sessionTimeout": 3600000
}
}
}
监控与维护
健康检查
# HTTP 健康检查
curl http://localhost:18789/health
# 自动重启
# 在 crontab 中添加
*/5 * * * * curl -f http://localhost:18789/health || systemctl restart openclaw
日志管理
# 日志轮转
sudo nano /etc/logrotate.d/openclaw
/var/log/openclaw/*.log {
daily
rotate 7
compress
missingok
notifempty
}
小结
远程部署让 OpenClaw 真正实现 24/7 可用:
- Tailscale:最简单的安全访问方案
- SSH 隧道:临时访问的快速方案
- 云服务器:团队和生产环境首选
- 自建服务器:隐私和成本的最佳平衡
更新记录:
- 2026-02-26:初版发布
系列导航:
- ← 上一篇:安全配置最佳实践
- → 下一篇:移动端接入:iOS 与 Android