Phase 1 / Ep 04: UTM 虚拟机部署 —— Linux 环境下的完整实战

⏱ 预计阅读 5 分钟 更新于 2026/4/13

🎯 学习目标:在 Apple Silicon Mac 上用 UTM 虚拟机运行 Linux 版 OpenClaw,实现最高安全等级的隔离。

1. 为什么选择虚拟机?

三种安装方式的安全隔离等级:

graph LR
    Native["macOS 原生\n❌ 零隔离"] --> Docker["Docker 容器\n✅ 进程级隔离"] --> VM["UTM 虚拟机\n✅✅ 内核级隔离"]
    
    style Native fill:#fee2e2
    style Docker fill:#fef9c3
    style VM fill:#dcfce7

当你需要运行 full 权限的 Agent(拥有完整的 Shell、网络和进程管理能力),虚拟机是唯一能保证宿主机安全的方案。

2. UTM 安装 Ubuntu ARM64

Step 1: 下载 UTM

mac.getutm.app 下载并安装 UTM。

Step 2: 下载 Ubuntu Server ARM64

从 Ubuntu 官网下载 Ubuntu Server 24.04 LTS ARM64 ISO。

Step 3: 创建虚拟机

  • CPU: 4 核
  • 内存: 4GB(最低 2GB)
  • 磁盘: 30GB
  • 网络: Shared Network(桥接模式)

Step 4: 安装 Ubuntu

走完标准安装向导,建议选择最小化安装 + OpenSSH Server。

3. 在 Ubuntu 中安装 OpenClaw

# 安装 Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs

# 安装 OpenClaw
curl -fsSL https://openclaw.ai/install.sh | bash

# 运行 Onboarding
openclaw onboard --install-daemon

4. systemd 守护进程配置

安装时如果选择了 daemon 模式,OpenClaw 会自动创建 systemd 服务文件。你也可以手动配置:

# /etc/systemd/system/openclaw.service
[Unit]
Description=OpenClaw AI Agent Gateway
After=network-online.target

[Service]
Type=simple
User=openclaw
ExecStart=/home/openclaw/.openclaw/bin/openclaw gateway start --foreground
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable openclaw
sudo systemctl start openclaw
sudo systemctl status openclaw

5. SSH 远程管理

从 Mac 终端远程管理 VM 中的 OpenClaw:

# 获取 VM 的 IP 地址(在 VM 内)
ip addr show

# 从 Mac 连接
ssh [email protected]

# 远程管理 Agent
openclaw status
openclaw logs --follow

6. 三种安装方式决策矩阵

维度 macOS 原生 Docker UTM/VM
安装难度 ⭐ 最低 ⭐⭐ ⭐⭐⭐
安全隔离 ❌ 无 ✅ 进程级 ✅✅ 内核级
性能开销 低(约 5%) 中(约 15%)
迁移能力 强(导出 VM)
适用场景 开发调试 个人日用 生产级 / 多 Agent
推荐权限 basic / coding basic / coding / full full(推荐)

下节预告: Ep 05,我们深入 ~/.openclaw/ 目录。SOUL.md、MEMORY.md、sessions/ —— 每个文件都是 Agent 身体的一部分。理解它们,才能真正驾驭你的 Agent。