Ansible 部署
openclaw-ansible 是官方维护的 Ansible Playbook,专为 生产服务器 设计,一条命令即可完成安全加固 + OpenClaw 部署。
快速开始
bash
# 一条命令完成部署(需要 SSH 访问目标服务器)
curl -fsSL https://raw.githubusercontent.com/openclaw/openclaw-ansible/main/install.sh | bash脚本会自动安装 Ansible(如果本机没有),克隆 openclaw-ansible Playbook 并执行部署。
你会获得什么
| 组件 | 说明 |
|---|---|
| 🔥 防火墙优先安全 | UFW 规则,仅开放必要端口 |
| 🔒 Tailscale VPN | 零配置组网,管理面板仅通过 VPN 访问 |
| 🐳 Docker 隔离 | Gateway 运行在容器中,与宿主机隔离 |
| ⚙️ systemd 集成 | 开机自启、崩溃自动重启、日志集成 journald |
服务器要求
| 项目 | 要求 |
|---|---|
| 操作系统 | Debian 11+ 或 Ubuntu 20.04+ |
| 架构 | x86_64 / amd64 |
| 内存 | >= 2 GB |
| 磁盘 | >= 10 GB |
| SSH 访问 | root 或 sudo 用户 |
部署清单
Playbook 按顺序安装以下组件:
- Tailscale — 零信任 VPN,用于安全管理
- UFW(Uncomplicated Firewall)— 防火墙规则
- Docker + Docker Compose v2
- Node.js 22 — 作为备用(非 Docker 场景)
- OpenClaw Gateway — 容器化部署
- systemd 服务 —
openclaw-gateway.service
部署后设置
部署完成后,Playbook 会输出:
✅ OpenClaw deployed successfully!
Gateway: http://your-server-ip:18789
Tailscale: http://100.x.y.z:18789 (admin only)
Dashboard: https://openclaw.example.com (after DNS setup)- 在浏览器打开 Gateway 地址,使用日志中的 Token 完成首次配对
- 配置模型 Provider(供应商):在控制面板 设置 > 模型 中添加 API Key
- 创建你的第一个 Agent(智能体)
安全架构——四层防御
┌─────────────────────────────────────────┐
│ Layer 4: Application Auth │
│ (API Key / Token / OAuth) │
├─────────────────────────────────────────┤
│ Layer 3: Docker Network Isolation │
│ (容器网络隔离) │
├─────────────────────────────────────────┤
│ Layer 2: Tailscale VPN │
│ (管理面板仅 VPN 可达) │
├─────────────────────────────────────────┤
│ Layer 1: UFW Firewall │
│ (仅开放 22, 80, 443) │
└─────────────────────────────────────────┘手动安装(不使用一键脚本)
如果你已有 Ansible 环境:
bash
# 克隆 Playbook
git clone https://github.com/openclaw/openclaw-ansible.git
cd openclaw-ansible
# 编辑 inventory
cp inventory.example.yml inventory.yml
# 编辑 inventory.yml,填入服务器信息
# 编辑变量
cp group_vars/all.example.yml group_vars/all.yml
# 编辑 all.yml,配置域名、Tailscale auth key 等
# 执行部署
ansible-playbook -i inventory.yml site.ymlinventory.yml 示例
yaml
all:
hosts:
openclaw-server:
ansible_host: 203.0.113.10
ansible_user: root
ansible_ssh_private_key_file: ~/.ssh/id_ed25519group_vars/all.yml 关键变量
yaml
openclaw_domain: openclaw.example.com
openclaw_version: latest
tailscale_auth_key: tskey-auth-xxxxx
ufw_allowed_ports:
- 22
- 80
- 443
docker_compose_version: "2.24.0"更新
bash
# 方法一:重新运行 Playbook(幂等操作)
ansible-playbook -i inventory.yml site.yml
# 方法二:仅更新 OpenClaw 容器
ansible-playbook -i inventory.yml site.yml --tags openclaw排障
SSH 连接失败
bash
# 检查 SSH 连通性
ssh -v root@your-server-ip
# 确认密钥权限
chmod 600 ~/.ssh/id_ed25519Tailscale 未上线
bash
# 在目标服务器上检查
sudo tailscale status
sudo systemctl status tailscaledDocker 容器未启动
bash
# 在目标服务器上检查
sudo docker compose -f /opt/openclaw/docker-compose.yml logs
sudo systemctl status openclaw-gateway