1 - PBS iSCSI Target for Veeam - 实施规范
版本: 1.0
日期: 2026-02-03
状态: 已批准
关联文档: pbs-iscsi-veeam-guide.md
1. 背景概述
本规范基于 docs/archive/pbs-iscsi-veeam-guide.md 中描述的混合备份架构方案,定义具体的 IaC 实施细节。
核心需求: T7910 冷备份服务器上的 PBS VM 通过 HBA 直通独占物理硬盘。需要在不改变硬件配置的情况下,让同主机的 Windows Server VM 能够使用底层 ZFS 存储空间运行 Veeam VBR。
解决方案: 在 PBS 的 ZFS 存储池上创建 ZVol,通过 LIO iSCSI Target 服务共享给 Windows Server。Windows 将 iSCSI 盘格式化为 ReFS,供 Veeam 使用 Fast Clone 功能。
2. 设计决策
技术参数
3. 文件清单
3.1 新建文件
ansible/
roles/
pbs-iscsi/
tasks/
main.yml # 主入口,包含其他任务文件
zvol.yml # ZVol 创建任务
iscsi-target.yml # iSCSI Target 配置任务
defaults/
main.yml # 角色变量定义
handlers/
main.yml # 服务处理器
playbooks/
deploy-pbs-iscsi.yml # 部署 playbook(含 verify play)
terraform/
esxi/
windows-server.tf # Windows Server VM 定义
3.2 修改文件
terraform/
esxi/
variables.tf # 追加 Windows VM 相关变量
4. 详细规范
4.1 Ansible Role: pbs-iscsi
defaults/main.yml
---
# =============================================================================
# PBS iSCSI Role - Default Variables
# =============================================================================
# -----------------------------------------------------------------------------
# ZVol Configuration
# -----------------------------------------------------------------------------
pbs_iscsi_zvol_name: "veeam-vol"
# ZVol 名称,将创建在 {{ pbs_zfs_pool_name }}/{{ pbs_iscsi_zvol_name }}
pbs_iscsi_zvol_size: "2T"
# ZVol 大小,支持 ZFS 单位格式 (K, M, G, T)
pbs_iscsi_zvol_blocksize: "64K"
# 卷块大小,64K 适合 iSCSI + ReFS 场景
pbs_iscsi_zvol_compression: "lz4"
# 压缩算法,lz4 提供良好的压缩比和低 CPU 开销
pbs_iscsi_zvol_sparse: true
# 精简置备,不预分配全部空间
# -----------------------------------------------------------------------------
# iSCSI Target Configuration
# -----------------------------------------------------------------------------
pbs_iscsi_iqn: "iqn.2026-02.lan.pbs:veeam"
# iSCSI Qualified Name,遵循 RFC 3720 格式
pbs_iscsi_portal_ip: "0.0.0.0"
# Portal 监听 IP,0.0.0.0 表示所有接口
pbs_iscsi_portal_port: 3260
# iSCSI 标准端口
pbs_iscsi_backstore_name: "veeam-backstore"
# LIO backstore 名称
# -----------------------------------------------------------------------------
# Demo Mode (No Authentication)
# -----------------------------------------------------------------------------
pbs_iscsi_demo_mode: true
# 启用 demo 模式,允许任何 initiator 连接
# 生产环境应设为 false 并配置 ACL
# -----------------------------------------------------------------------------
# Dependencies (from pbs role)
# -----------------------------------------------------------------------------
# pbs_zfs_pool_name: "backup-pool" # 从 pbs role 或 host_vars 获取
tasks/main.yml
---
# PBS iSCSI Role - Main Entry Point
- name: Include ZVol creation tasks
ansible.builtin.include_tasks: zvol.yml
tags: [zvol, iscsi]
- name: Include iSCSI target configuration tasks
ansible.builtin.include_tasks: iscsi-target.yml
tags: [iscsi]
tasks/zvol.yml
---
# ZVol Creation Tasks
- name: Check if ZVol already exists
ansible.builtin.command:
cmd: "zfs list {{ pbs_zfs_pool_name }}/{{ pbs_iscsi_zvol_name }}"
register: zvol_check
failed_when: false
changed_when: false
- name: Create ZVol for iSCSI target
ansible.builtin.command:
cmd: >-
zfs create
-V {{ pbs_iscsi_zvol_size }}
{{ '-s' if pbs_iscsi_zvol_sparse else '' }}
-o volblocksize={{ pbs_iscsi_zvol_blocksize }}
-o compression={{ pbs_iscsi_zvol_compression }}
{{ pbs_zfs_pool_name }}/{{ pbs_iscsi_zvol_name }}
when: zvol_check.rc != 0
- name: Verify ZVol device exists
ansible.builtin.stat:
path: "/dev/zvol/{{ pbs_zfs_pool_name }}/{{ pbs_iscsi_zvol_name }}"
register: zvol_device
failed_when: not zvol_device.stat.exists
tasks/iscsi-target.yml
---
# iSCSI Target Configuration Tasks
- name: Install targetcli-fb package
ansible.builtin.apt:
name: targetcli-fb
state: present
update_cache: yes
- name: Enable and start target service
ansible.builtin.systemd:
name: rtslib-fb-targetctl
enabled: yes
state: started
- name: Check if backstore exists
ansible.builtin.command:
cmd: "targetcli ls /backstores/block/{{ pbs_iscsi_backstore_name }}"
register: backstore_check
failed_when: false
changed_when: false
- name: Create block backstore from ZVol
ansible.builtin.command:
cmd: >-
targetcli /backstores/block create
{{ pbs_iscsi_backstore_name }}
/dev/zvol/{{ pbs_zfs_pool_name }}/{{ pbs_iscsi_zvol_name }}
when: backstore_check.rc != 0
notify: Save targetcli config
- name: Check if iSCSI target exists
ansible.builtin.command:
cmd: "targetcli ls /iscsi/{{ pbs_iscsi_iqn }}"
register: target_check
failed_when: false
changed_when: false
- name: Create iSCSI target
ansible.builtin.command:
cmd: "targetcli /iscsi create {{ pbs_iscsi_iqn }}"
when: target_check.rc != 0
notify: Save targetcli config
- name: Configure iSCSI portal
ansible.builtin.command:
cmd: >-
targetcli /iscsi/{{ pbs_iscsi_iqn }}/tpg1/portals create
{{ pbs_iscsi_portal_ip }} {{ pbs_iscsi_portal_port }}
register: portal_result
failed_when: portal_result.rc != 0 and 'already exists' not in portal_result.stderr
changed_when: portal_result.rc == 0
notify: Save targetcli config
- name: Create LUN mapping
ansible.builtin.command:
cmd: >-
targetcli /iscsi/{{ pbs_iscsi_iqn }}/tpg1/luns create
/backstores/block/{{ pbs_iscsi_backstore_name }}
register: lun_result
failed_when: lun_result.rc != 0 and 'already exists' not in lun_result.stderr
changed_when: lun_result.rc == 0
notify: Save targetcli config
- name: Configure demo mode (no authentication)
ansible.builtin.command:
cmd: >-
targetcli /iscsi/{{ pbs_iscsi_iqn }}/tpg1 set attribute
authentication=0
demo_mode_write_protect=0
generate_node_acls=1
cache_dynamic_acls=1
when: pbs_iscsi_demo_mode
notify: Save targetcli config
handlers/main.yml
---
# PBS iSCSI Role - Handlers
- name: Save targetcli config
ansible.builtin.command:
cmd: targetcli saveconfig
listen: Save targetcli config
- name: Restart target service
ansible.builtin.systemd:
name: rtslib-fb-targetctl
state: restarted
4.2 Playbook: deploy-pbs-iscsi.yml
---
# Deploy PBS iSCSI Target for Veeam
# Usage:
# ansible-playbook playbooks/deploy-pbs-iscsi.yml
# ansible-playbook playbooks/deploy-pbs-iscsi.yml --tags verify
- name: Deploy PBS iSCSI Target
hosts: pbs
become: yes
roles:
- role: pbs-iscsi
tags: [pbs-iscsi]
- name: Verify PBS iSCSI Deployment
hosts: pbs
become: yes
tags: [verify]
tasks:
- name: Verify ZVol exists
ansible.builtin.command:
cmd: "zfs list {{ pbs_zfs_pool_name }}/{{ pbs_iscsi_zvol_name }}"
changed_when: false
- name: Verify ZVol properties
ansible.builtin.command:
cmd: "zfs get volsize,volblocksize,compression {{ pbs_zfs_pool_name }}/{{ pbs_iscsi_zvol_name }}"
changed_when: false
register: zvol_props
- name: Display ZVol properties
ansible.builtin.debug:
var: zvol_props.stdout_lines
- name: Verify iSCSI target exists
ansible.builtin.command:
cmd: "targetcli ls /iscsi/{{ pbs_iscsi_iqn }}"
changed_when: false
- name: Verify iSCSI portal is listening
ansible.builtin.wait_for:
port: "{{ pbs_iscsi_portal_port }}"
timeout: 10
- name: Display iSCSI target summary
ansible.builtin.command:
cmd: "targetcli ls /iscsi"
changed_when: false
register: iscsi_summary
- name: Show iSCSI configuration
ansible.builtin.debug:
var: iscsi_summary.stdout_lines
variables.tf (追加内容)
# -----------------------------------------------------------------------------
# Windows Server VM Variables
# -----------------------------------------------------------------------------
variable "windows_vm_name" {
description = "Windows Server VM name"
default = "windows-server"
}
variable "windows_ip_address" {
description = "Windows Server static IP address"
type = string
}
variable "windows_num_cpus" {
description = "Number of vCPUs for Windows Server"
default = 4
}
variable "windows_memory_mb" {
description = "Memory in MB for Windows Server"
default = 8192
}
variable "windows_system_disk_gb" {
description = "System disk size in GB for Windows Server"
default = 60
}
windows-server.tf
# =============================================================================
# Windows Server VM Definition (Veeam Host)
# =============================================================================
module "windows_server" {
source = "../modules/esxi-vm"
# Basic Configuration
vm_name = var.windows_vm_name
resource_pool_id = data.vsphere_host.host.resource_pool_id
datastore_id = data.vsphere_datastore.datastore.id
network_id = data.vsphere_network.network.id
host_system_id = data.vsphere_host.host.id
# Hardware Resources
num_cpus = var.windows_num_cpus
memory = var.windows_memory_mb
system_disk_size = var.windows_system_disk_gb
# Firmware & Guest OS
firmware = "efi"
guest_id = "windows2019srv_64Guest" # Compatible with Windows Server 2019/2022
}
# -----------------------------------------------------------------------------
# Ansible Inventory Registration
# -----------------------------------------------------------------------------
resource "ansible_host" "windows_server" {
name = "windows-server"
groups = ["esxi_vms", "windows"]
variables = {
ansible_host = var.windows_ip_address
# Windows Ansible connection (WinRM) - requires manual setup first
# ansible_connection = "winrm"
# ansible_winrm_transport = "ntlm"
# ansible_winrm_server_cert_validation = "ignore"
# iSCSI connection info (for future automation)
iscsi_target_ip = var.pbs_ip_address
iscsi_target_iqn = "iqn.2026-02.lan.pbs:veeam"
}
depends_on = [module.windows_server]
}
# -----------------------------------------------------------------------------
# Outputs
# -----------------------------------------------------------------------------
output "windows_server_vm_id" {
value = module.windows_server.vm_id
description = "Windows Server VM Managed Object ID"
}
output "windows_server_ip" {
value = var.windows_ip_address
description = "Windows Server IP Address"
}
5. 实施顺序
┌─────────────────────────────────────────────────────────────────┐
│ Phase 1: Ansible Role (pbs-iscsi) │
├─────────────────────────────────────────────────────────────────┤
│ 1. ansible/roles/pbs-iscsi/defaults/main.yml ← 先定义变量 │
│ 2. ansible/roles/pbs-iscsi/handlers/main.yml ← handler │
│ 3. ansible/roles/pbs-iscsi/tasks/zvol.yml ← ZVol 任务 │
│ 4. ansible/roles/pbs-iscsi/tasks/iscsi-target.yml← iSCSI 任务 │
│ 5. ansible/roles/pbs-iscsi/tasks/main.yml ← 主入口 │
└─────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────┐
│ Phase 2: Playbook │
├─────────────────────────────────────────────────────────────────┤
│ 6. ansible/playbooks/deploy-pbs-iscsi.yml ← 部署脚本 │
│ → 语法检查: --syntax-check │
│ → 干跑验证: --check --diff │
│ → 实际部署 (在 PBS 上执行) │
│ → 验证部署: --tags verify │
└─────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────┐
│ Phase 3: Terraform (可与 Phase 2 并行) │
├─────────────────────────────────────────────────────────────────┤
│ 7. terraform/esxi/variables.tf ← 追加变量 │
│ 8. terraform/esxi/windows-server.tf ← VM 定义 │
│ → terraform validate │
│ → terraform plan │
│ → terraform apply (创建 VM shell) │
└─────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────┐
│ Phase 4: 手动配置 (Windows 端) │
├─────────────────────────────────────────────────────────────────┤
│ 9. 安装 Windows Server (从 ISO) │
│ 10. 配置静态 IP │
│ 11. iSCSI Initiator → 连接 PBS IP │
│ 12. 磁盘管理 → GPT 初始化 → ReFS 格式化 (64K 分配单元) │
│ 13. 安装 Veeam VBR Community Edition │
│ 14. 配置 Backup Repository (ReFS 卷) │
└─────────────────────────────────────────────────────────────────┘
6. 验证方法
6.1 Ansible 验证
# 语法检查
ansible-playbook ansible/playbooks/deploy-pbs-iscsi.yml --syntax-check
# 干跑模式 (不实际执行)
ansible-playbook ansible/playbooks/deploy-pbs-iscsi.yml --check --diff
# 部署后验证
ansible-playbook ansible/playbooks/deploy-pbs-iscsi.yml --tags verify
6.2 手动验证命令 (在 PBS 上执行)
# 检查 ZVol
zfs list backup-pool/veeam-vol
zfs get volsize,volblocksize,compression backup-pool/veeam-vol
# 检查 iSCSI Target
targetcli ls /iscsi
ss -tlnp | grep 3260
# 检查设备
ls -la /dev/zvol/backup-pool/veeam-vol
cd terraform/esxi
# 格式检查
terraform fmt -check
# 语法验证
terraform validate
# 计划预览
terraform plan
6.4 Windows 端验证
- iSCSI Initiator → Quick Connect → 输入 PBS IP → 应显示 Target
- 磁盘管理 → 应出现 2TB 未初始化磁盘
- Veeam Repository → 添加 ReFS 卷后,检查 Fast Clone 是否启用
7. 后续工作
7.1 Windows Ansible 自动化 (Phase 2)
计划通过 ansible.windows collection 自动化以下任务:
# 未来的 windows-iscsi role 草案
- name: Start iSCSI Initiator service
win_service:
name: MSiSCSI
start_mode: auto
state: started
- name: Connect to iSCSI target
win_shell: |
New-IscsiTargetPortal -TargetPortalAddress {{ iscsi_target_ip }}
Connect-IscsiTarget -NodeAddress {{ iscsi_target_iqn }} -IsPersistent $true
- name: Initialize and format disk
win_shell: |
$disk = Get-Disk | Where-Object { $_.OperationalStatus -eq 'Offline' }
Set-Disk -Number $disk.Number -IsOffline $false
Initialize-Disk -Number $disk.Number -PartitionStyle GPT
New-Partition -DiskNumber $disk.Number -UseMaximumSize -AssignDriveLetter |
Format-Volume -FileSystem ReFS -AllocationUnitSize 65536 -NewFileSystemLabel "VeeamRepo"
7.2 可选增强
- ZFS 空间监控: 添加 Prometheus exporter 或简单的 cron 告警脚本
- iSCSI ACL: 如需提高安全性,可配置 initiator IQN 白名单
- 自动扩容: 监控 ZVol 使用率,达到阈值时自动扩容
7.3 相关文档更新
部署完成后需更新:
docs/archive/pbs-iscsi-veeam-guide.md — 已归档的历史实施记录ansible/README.md — 添加 pbs-iscsi role 说明
2 - Proxmox Backup Server + Veeam 混合备份架构方案 (iSCSI)
版本: 1.0
日期: 2026-02-03
状态: 草案
适用场景: 冷备份服务器 (T7910), 混合环境 (PVE + ESXi + Windows/Mac)
1. 方案背景与目标
当前 T7910 作为冷备份服务器,运行 ESXi 8.x,并直通 HBA 卡给 PBS (Proxmox Backup Server) 虚拟机管理 ZFS 存储池。
为了实现全平台统一备份(不仅针对 Proxmox VM,还包括 Windows/Mac 物理机及 ESXi VM),计划引入 Veeam Backup & Replication (VBR) 运行在 Windows Server 上。
本方案旨在解决核心冲突:如何在 PBS 独占直通硬盘的情况下,让 Windows Server 高效利用底层存储空间?
2. 架构设计:iSCSI over ZFS
采用 iSCSI 块存储共享 方案。PBS 继续独占物理硬件,但在 ZFS 上划分独立的块设备 (ZVol),通过 iSCSI 协议共享给 Windows Server。
架构拓扑
graph TD
subgraph "T7910 (ESXi Host)"
HBA[LSI 3008 HBA]
subgraph "PBS VM (Debian)"
ZFS_Pool[ZFS Pool (backup-storage)]
PBS_App[PBS Service]
iSCSI_Svc[LIO iSCSI Target]
ZFS_Pool --Dataset--> PBS_App
ZFS_Pool --ZVol--> iSCSI_Svc
end
subgraph "Windows Server VM"
Veeam[Veeam VBR]
iSCSI_Init[iSCSI Initiator]
NTFS_ReFS[ReFS Volume]
end
HBA ==PCIe直通==> PBS_VM
iSCSI_Svc ==虚拟网络 (vSwitch)==> iSCSI_Init
iSCSI_Init --> NTFS_ReFS
NTFS_ReFS --> Veeam
end
核心优势
- Veeam 最佳实践: Windows 将 iSCSI 目标识别为“本地磁盘”,可将其格式化为 ReFS (Resilient File System)。Veeam 在 ReFS 上支持 Block Cloning (Fast Clone) 技术,能极快地合并增量备份(Synthetic Full),且节省大量空间。
- 存储统一管理: ZFS 为底层提供 RAID 保护、压缩和数据完整性校验(Bit Rot Protection)。
- 零硬件变动: 无需重新规划直通卡或物理连线。
- 网络高性能: 利用 ESXi 内部虚拟交换机 (vSwitch),PBS 与 Windows 间的 iSCSI 流量通过内存总线传输(VMXNET3 虚拟网卡),速度极快(可达 10Gbps+),不受物理千兆网口限制。
3. 实施规划
3.1 PBS 端配置 (Ansible 自动化)
我们需要编写一个新的 Ansible Role (pbs-iscsi) 来执行以下任务:
- 安装依赖:
targetcli-fb (Linux LIO iSCSI 管理工具)。 - 创建 ZVol:
- 名称:
backup-storage/veeam-vol - 大小: 按需分配 (例如 2TB)
- 属性:
volblocksize=64k (推荐配合 iSCSI), compression=lz4, sparse=on (精简置备)
- 配置 iSCSI Target:
- Backstore: 映射上述 ZVol。
- IQN (iSCSI Qualified Name): 例如
iqn.2026-02.lan.pbs:veeam。 - Portal: 监听 PBS IP (0.0.0.0:3260)。
- LUN: 映射 Backstore 到 LUN 0。
- ACL: 限制仅允许 Windows Server 的 IQN 连接 (可选,内网环境也可开放 demo 模式)。
3.2 Windows 端配置 (手动/脚本)
- 部署 VM: 安装 Windows Server 2019/2022 Standard。
- 连接 iSCSI:
- 打开 “iSCSI Initiator”。
- Target: 输入 PBS IP (
192.168.1.249)。 - Connect -> Done。
- 磁盘初始化:
- “Disk Management” -> 联机 -> 初始化 (GPT)。
- 新建卷 -> 格式化为 ReFS (分配单元大小建议 64K 以匹配 ReFS 最佳实践)。
- 部署 Veeam:
- 安装 Veeam VBR Community Edition。
- Add Repository -> Direct Attached Storage -> Microsoft Windows -> 选择 ReFS 卷。
- 关键设置: 确保勾选 “Align backup file data blocks” (通常默认) 以启用 Fast Clone。
4. 自动化冷备调度 (Veeam 驱动)
由于引入了 Windows,原本的自动化逻辑(WOL -> 备份 -> 关机)可以转移到 Windows 内部,利用 PowerShell 实现更灵活的控制:
新流程:
- 每周六 00:00:
pve0 (Cron) 发送 WOL 唤醒 T7910。 - T7910 启动: ESXi 自动启动 PBS VM 和 Windows VM。
- Windows 启动:
- Veeam 调度器检测到 missed schedule,自动开始运行备份作业。
- 作业内容:
- Backup ESXi VMs (通过 vCenter/ESXi API)。
- Backup Agents (物理机/Mac 等)。
- 备份后动作 (Post-Job Script):
- Veeam 作业配置 “Run the following script after this job”。
- 脚本内容 (PowerShell):
- 检查其他作业是否还在运行。
- 调用 SSH (plink.exe) 命令关闭 PBS VM。
- 调用 ESXi API (PowerCLI) 关闭宿主机 T7910。
5. 资源分配建议 (T7910)
注:ZFS 需要内存做 ARC 缓存,但作为冷备机,性能要求不是第一位的,8-12GB 给 PBS 足够。Windows Server 运行 Veeam SQL 数据库需要一定内存,8GB 起步。
6. 风险与注意事项
- ZVol 空间规划: ZVol 占用的空间是从 ZFS 池中划走的。如果 PBS (PVE 备份) 数据增长过快,可能导致存储池填满。建议设置 ZFS Quota 或保留一定的 Free Space。
- 启动依赖: Windows VM 必须在 PBS VM 完全启动并加载 ZFS 之后才能成功连接 iSCSI 盘。
- 解决方案: 在 ESXi 中设置启动延迟,PBS 设为第一顺位,Windows 设为延迟 120秒启动。
- ReFS 兼容性: ReFS 对硬件错误比较敏感,底层的 ZFS 已经提供了强大的保护,这其实是双重保险。
7. 下一步行动
- 确认 ZFS 存储池剩余空间。
- 编写
ansible/roles/pbs-iscsi。 - 准备 Windows Server 镜像和 License。
3 - Proxmox Backup Server on ESXi 8.x - Deployment Guide
已退役/仅作历史记录(2026-09-21):ESXi 宿主已退役,T7910 现为独立 pve2,PBS 为 VM100。下文的部署命令、NVMe special vdev 状态和 Ansible 备份作业入口属于旧环境,不可用于重建当前环境。当前两块 NVMe 已直通,special vdev 留待后续实施;备份业务策略改由 PVE/PBS 管理。现状见备份架构规范 v1.14 / D18
。保留此路径以兼容历史链接。
说明:本指南覆盖在 ESXi 8.x 环境中通过 Infrastructure as Code 方式部署 Proxmox Backup Server,包含 LSI 3008 HBA 直通、ZFS 分层存储(special vdev)配置、Terraform 与 Ansible 集成的完整实施流程。
文档版本: 1.1
创建日期: 2026-01-29
最后更新: 2026-01-31
适用环境: ESXi 8.x, vCenter Server, Terraform 1.14+, Ansible 2.16+
⚠️ 重要更新 (2026-01-31)
pbs_zfs role 已合并到 pbs role 中。ZFS 相关 tasks 现位于 ansible/roles/pbs/tasks/zfs-*.yml。
本文档中对 roles/pbs_zfs/ 的引用仅作历史参考,实际文件路径已变更为 roles/pbs/tasks/zfs-*.yml。
Table of Contents
1. Overview
1.1. Project Goals
本项目的目标是在 ESXi 8.x 虚拟化环境中部署一个高性能的 Proxmox Backup Server,用于混合环境(Proxmox VE + ESXi)的备份管理。通过 Infrastructure as Code 实现完全自动化、可重复、可审计的部署流程。
核心目标:
- ✅ 自动化部署:Terraform 管理基础设施,Ansible 管理配置
- ✅ 高性能存储:ZFS Mirror Pool(HDD,可选 NVMe special vdev 升级)
- ✅ 硬件直通:LSI 3008 HBA 直通提供原生磁盘访问
- ✅ 可维护性:完整的文档、验证机制、监控集成
- ✅ 资产管理:与 Netbox IPAM/DCIM 集成
1.2. Key Features
存储特性:
- ZFS Mirror Pool: 2 × 8TB HDD(通过 LSI 3008 HBA 直通)
- ZFS Special vdev: 已启用 —— 2× Samsung SM963 NVMe 组镜像(
special mirror-1),经 bifurcation 拆分接入 - 性能优化: 针对 PBS 工作负载的 ZFS 参数调优
- 数据保护: Mirror 冗余 + ZFS 校验和
IaC 特性:
- Terraform 管理: VM 创建、PCIe 直通、网络配置
- Ansible 自动化: ZFS 配置、PBS 安装、用户管理
- 动态 Inventory: Terraform 作为 inventory source of truth
- 自动验证: 部署后健康检查和性能测试
集成特性:
- Netbox 集成: 自动注册 VM、IP、服务记录
- 监控就绪: 暴露 PBS metrics 端点
- 备份策略: ZFS 快照自动化
1.3. Architecture Summary
ESXi Host (192.168.1.251)
↓
PBS VM (192.168.1.249)
├─ 8 vCPU, 16GB RAM (预留)
├─ 80GB System Disk (ESXi Datastore)
├─ PCIe Passthrough:
│ └─ LSI 3008 HBA → 2 × 8TB HDD
└─ ZFS Storage Pool:
└─ Data vdev: mirror (HDD) - ~7.3TB usable
部署流程:
Terraform (Infrastructure)
↓
PBS ISO Installation (Manual)
↓
Ansible (Configuration)
↓
Verification (Automated)
2. Architecture Design
2.1. System Architecture
┌─────────────────────────────────────────────────────────────────┐
│ vCenter Server: 192.168.1.250 │
│ Datacenter: Roseville │
└─────────────────────────────────────────────────────────────────┘
│
↓
┌─────────────────────────────────────────────────────────────────┐
│ ESXi Host: 192.168.1.251 │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ PBS VM: 192.168.1.249 │ │
│ │ ┌─────────────────────────────────────────────────────┐ │ │
│ │ │ Guest OS: Proxmox Backup Server │ │ │
│ │ │ • 8 vCPU │ │ │
│ │ │ • 16GB RAM (Fully Reserved) │ │ │
│ │ │ • 80GB System Disk (ext4) │ │ │
│ │ │ • EFI Firmware, VMXNET3 Network │ │ │
│ │ └─────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────────┐ │ │
│ │ │ PCIe Passthrough Devices │ │ │
│ │ │ ┌─────────────────────────────────────────────┐ │ │ │
│ │ │ │ LSI 3008 HBA (IT Mode) │ │ │ │
│ │ │ │ PCI ID: 0000:XX:XX.X (from discovery) │ │ │ │
│ │ │ │ ├─ SATA Port 0 → 8TB HDD #1 (/dev/sdb) │ │ │ │
│ │ │ │ └─ SATA Port 1 → 8TB HDD #2 (/dev/sdc) │ │ │ │
│ │ │ └─────────────────────────────────────────────┘ │ │ │
│ │ │ ┌─────────────────────────────────────────────┐ │ │ │
│ │ │ │ NVMe #1 (via PCIe Adapter) │ │ │ │
│ │ │ │ PCI ID: 0000:YY:YY.Y │ │ │ │
│ │ │ │ 256GB → /dev/nvme0n1 │ │ │ │
│ │ │ └─────────────────────────────────────────────┘ │ │ │
│ │ │ ┌─────────────────────────────────────────────┐ │ │ │
│ │ │ │ NVMe #2 (via PCIe Adapter) │ │ │ │
│ │ │ │ PCI ID: 0000:ZZ:ZZ.Z │ │ │ │
│ │ │ │ 256GB → /dev/nvme1n1 │ │ │ │
│ │ │ └─────────────────────────────────────────────┘ │ │ │
│ │ └─────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────────┐ │ │
│ │ │ ZFS Storage Pool: backup-pool │ │ │
│ │ │ ┌───────────────────────────────────────────────┐ │ │ │
│ │ │ │ Data vdev (mirror) │ │ │ │
│ │ │ │ • Device: /dev/sdb, /dev/sdc │ │ │ │
│ │ │ │ • Raw: 16TB → Usable: ~8TB │ │ │ │
│ │ │ │ • Purpose: Backup data (blocks ≥ 128KB) │ │ │ │
│ │ │ │ • Performance: ~200-300 MB/s seq write │ │ │ │
│ │ │ └───────────────────────────────────────────────┘ │ │ │
│ │ │ ┌───────────────────────────────────────────────┐ │ │ │
│ │ │ │ Special vdev (mirror) │ │ │ │
│ │ │ │ • Device: /dev/nvme0n1, /dev/nvme1n1 │ │ │ │
│ │ │ │ • Raw: 512GB → Usable: ~220GB │ │ │ │
│ │ │ │ • Purpose: Metadata + blocks < 128KB │ │ │ │
│ │ │ │ • Performance: ~3000 MB/s, 50k+ IOPS │ │ │ │
│ │ │ └───────────────────────────────────────────────┘ │ │ │
│ │ │ │ │ │
│ │ │ Dataset: backup-pool/datastore │ │ │
│ │ │ Mount: /mnt/backup-pool/datastore │ │ │
│ │ │ PBS Datastore: backup-storage │ │ │
│ │ └─────────────────────────────────────────────────────┘ │ │
│ └───────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
2.2. Hardware Configuration
关键配置要求:
- ✅ BIOS/UEFI 启用 VT-d/IOMMU
- ✅ LSI 3008 刷入 IT 模式固件(非 IR/RAID)
- ✅ NVMe 通过独立 PCIe 插槽或转接卡
- ✅ ESXi 启用 PCIe 直通(Passthrough Mode)
2.3. Storage Architecture
2.3.1. ZFS Pool 结构(当前部署:HDD-Only)
backup-pool (总容量: ~7.3TB 可用)
│
└─ Data vdev: mirror-0
├─ /dev/sdb (8TB HDD #1)
└─ /dev/sdc (8TB HDD #2)
• 用途: 所有数据和元数据
• 读写性能: ~250 MB/s 读, ~200 MB/s 写
• IOPS: ~150-200 (4K随机)
• 网络瓶颈: 1Gbps = 125 MB/s(实际限制)
⚠️ 更正(2026-08-11):本文档多处称 special vdev “需要 bifurcation 支持"而"暂不可用”,该记录有误。实际 backup-pool 早已启用 special vdev:
backup-pool
mirror-0 sdb + sdc 2× HGST 8TB
special
mirror-1 nvme0n1 + nvme1n1 2× Samsung SM963(镜像)
两块 NVMe 位于 03:01.0 / 03:02.0 —— 同一总线、不同 device 号,正是 bifurcation 拆分的结果,说明该转接卡与主板均支持 bifurcation。
另注意 special_small_blocks = recordsize = 128K,意味着几乎所有 ≤128K 的块都优先落 NVMe,已超出"仅元数据"的范畴(special vdev 实占 48.5G / 20.4%)。若只想缓存元数据,通常设 32K/64K。
该方案的可行性已被引用为 pve1 加装 special vdev 的先例,见备份架构整合规范 D17。
以下为原文记录的"未来可选升级",其前提(bifurcation 不可用)已不成立:
backup-pool (升级配置: ~8TB 数据 + ~220GB 元数据)
│
├─ Data vdev: mirror-0
│ ├─ /dev/sdb (8TB HDD #1)
│ └─ /dev/sdc (8TB HDD #2)
│ • 用途: 存储 ≥ 128KB 的数据块
│
└─ Special vdev: mirror-1
├─ /dev/nvme0n1 (256GB NVMe #1)
└─ /dev/nvme1n1 (256GB NVMe #2)
• 用途: 所有元数据 + < 128KB 的小文件
• 升级方法: zpool add backup-pool special mirror /dev/nvme0n1 /dev/nvme1n1
2.3.2. ZFS 关键参数
2.3.3. 存储性能预期
容量规划:
- 256GB NVMe 可支持约 20-40TB 的实际数据(元数据占比 0.5-1%)
- PBS 去重 会增加元数据量,建议监控 special vdev 使用率
- 如果 special vdev 满,ZFS 自动溢出到 HDD(性能下降但不会丢数据)
2.4. Hardware Compatibility and Troubleshooting
2.4.1. PCIe Passthrough Device Compatibility
⚠️ CRITICAL: Not all PCIe devices work with ESXi passthrough
During deployment, we discovered significant compatibility issues with certain NVMe devices:
2.4.2. Intel Optane Memory Incompatibility (CRITICAL)
Device Identification:
# Controller shows zero namespaces
nvme id-ctrl /dev/nvme0 | grep nn
# Output: nn : 0
Root Cause Analysis:
- Intel Optane Memory (MEMPEK1W016GA) is NOT a standard NVMe SSD
- Designed exclusively for Intel RST (Rapid Storage Technology) caching in Windows/specific Intel chipsets
- Does not support NVMe namespace management commands (
oacs : 0x6 - bit 3 not set) - Reports zero capacity (
tnvmcap : 0, unvmcap : 0) - Cannot create namespaces:
nvme create-ns returns Invalid Command Opcode
Impact:
- No
/dev/nvme0n1 block devices will ever appear - Controllers are detected (
/sys/class/nvme/nvme0 exists) but unusable - Cannot be used for ZFS, even with firmware updates
Resolution:
# Remove Optane devices from VM configuration
# Edit VM .vmx file or use Terraform to remove PCI passthrough entries
# These devices are fundamentally incompatible with standalone use
2.4.3. Samsung SM963 NVMe ESXi Crash Issue
Symptom:
ESXi PSOD (Purple Screen of Death) on VM shutdown
Error: VERIFY bora/devices/pcipassthru/pciPassthru.c:2254
Root Cause:
- Samsung SM963 fails Function Level Reset (FLR) during VM shutdown
- Device hangs during PCIe reset sequence
- ESXi crashes when attempting to reclaim the device
Workaround (✅ TESTED 2026-01-31 - WORKING):
使用 D3→D0 电源状态转换代替 FLR 重置。原理:D3(深度睡眠)→ D0(正常工作)的电源状态切换会触发硬件级重置,绕过 SM963 固件的 FLR 缺陷。
# On ESXi host, edit the VM .vmx file
ssh root@192.168.1.251
cd /vmfs/volumes/*/proxmox-backup-server/
vi proxmox-backup-server.vmx
# First, check which pciPassthru index corresponds to Samsung NVMe:
grep pciPassthru proxmox-backup-server.vmx
# Look for vendorId = "0x144d" (Samsung) to identify the correct index
# Add resetMethod for Samsung NVMe devices (adjust index as needed):
pciPassthru1.resetMethod = "d3d0"
pciPassthru2.resetMethod = "d3d0"
注意事项:
- 必须在 VM 关机状态下修改 .vmx 文件
- pciPassthru 索引从 0 开始,按设备添加顺序排列
- 只需给 Samsung NVMe 配置,HBA 等其他设备无需修改
2.4.4. Architecture Options
✅ RECOMMENDED: HDD + NVMe Special vdev(FLR workaround 已验证可用)
backup-pool (Full Configuration with Special vdev)
│
├─ Data vdev: mirror-0
│ ├─ /dev/sdb (8TB HDD #1)
│ └─ /dev/sdc (8TB HDD #2)
│
└─ Special vdev: mirror-1 (metadata + small blocks)
├─ /dev/nvme0n1 (Samsung SM963 256GB #1)
└─ /dev/nvme1n1 (Samsung SM963 256GB #2)
• Metadata IOPS: 100,000+
• Small block acceleration: <128K files on NVMe
备选: HDD-Only Configuration(如不使用 NVMe)
backup-pool (Simplified Configuration)
│
└─ Data vdev: mirror-0
├─ /dev/sdb (8TB HDD #1)
└─ /dev/sdc (8TB HDD #2)
• Usable Capacity: ~7.3TB
• Sequential Performance: 200-300 MB/s
• Random IOPS: 150-200
• Network Bottleneck: 1Gbps = 125 MB/s (actual limit)
Performance Comparison:
Key Insight: Special vdev 主要提升 元数据操作性能(目录浏览、快照管理、Web UI 响应),对大文件顺序读写影响不大。
2.5. Network Topology
┌─────────────────────────────────────────┐
│ Network: 192.168.1.0/24 │
│ Gateway: 192.168.1.1 │
│ DNS: 192.168.1.1 │
└─────────────────────────────────────────┘
│
├─ 192.168.1.250 → vCenter Server
├─ 192.168.1.251 → ESXi Host
├─ 192.168.1.249 → PBS VM (New)
├─ 192.168.1.104 → Netbox
└─ 192.168.1.50-52 → Proxmox VE Cluster
PBS VM 网络配置:
- IP: 192.168.1.249/24 (静态)
- 网关: 192.168.1.1
- DNS: 192.168.1.1
- 主机名: pbs.willfan.me
- 虚拟网卡: VMXNET3 (VMware 准虚拟化)
防火墙端口:
- TCP 8007: PBS Web UI / API (HTTPS)
- TCP 22: SSH 管理
- ICMP: Ping 监控
2.5. IaC Workflow
┌──────────────────────────────────────────────────────────────┐
│ Phase 1: Terraform (Infrastructure Provisioning) │
├──────────────────────────────────────────────────────────────┤
│ terraform/esxi/pbs.tf │
│ ├─ Create PBS VM (8vCPU, 16GB, 80GB) │
│ ├─ Configure PCIe Passthrough (HBA + NVMe) │
│ ├─ Set Static IP (192.168.1.249) │
│ └─ Register to Ansible Inventory (ansible_host resource) │
│ │
│ Output: VM Created, Devices Attached, IP Configured │
└──────────────────────────────────────────────────────────────┘
↓
┌──────────────────────────────────────────────────────────────┐
│ Phase 2: PBS ISO Installation (Manual) │
├──────────────────────────────────────────────────────────────┤
│ • Mount PBS ISO via vCenter │
│ • Boot from ISO, run installer │
│ • Configure: Hostname, IP, Root Password │
│ • Reboot, verify SSH connectivity │
│ │
│ Output: PBS OS Installed, SSH Accessible │
└──────────────────────────────────────────────────────────────┘
↓
┌──────────────────────────────────────────────────────────────┐
│ Phase 3: Ansible (Configuration Management) │
├──────────────────────────────────────────────────────────────┤
│ ansible/inventory/terraform-esxi.yml │
│ └─ Read PBS from Terraform state (dynamic inventory) │
│ │
│ ansible/roles/pbs/ │
│ ├─ Install system packages (chrony, vim, etc) │
│ ├─ Configure network (if needed) │
│ └─ Create PBS users and permissions │
│ │
│ ansible/roles/pbs_zfs/ │
│ ├─ Verify devices (/dev/sdb, sdc, nvme0n1, nvme1n1) │
│ ├─ Create ZFS pool (mirror + special vdev) │
│ ├─ Optimize ZFS parameters │
│ └─ Create PBS datastore (via API) │
│ │
│ ansible/playbooks/deploy-pbs.yml │
│ └─ Execute roles + automated verification │
│ │
│ Output: ZFS Configured, PBS Datastore Ready │
└──────────────────────────────────────────────────────────────┘
↓
┌──────────────────────────────────────────────────────────────┐
│ Phase 4: Netbox Integration (Asset Management) │
├──────────────────────────────────────────────────────────────┤
│ terraform/netbox-integration/pbs-esxi.tf │
│ ├─ Create ESXi Cluster record │
│ ├─ Create PBS VM record │
│ ├─ Create Network Interface │
│ ├─ Create IP Address (192.168.1.249) │
│ └─ Create Service records (PBS Web UI, API) │
│ │
│ Output: PBS Registered in Netbox │
└──────────────────────────────────────────────────────────────┘
↓
┌──────────────────────────────────────────────────────────────┐
│ Phase 5: Verification (Automated Testing) │
├──────────────────────────────────────────────────────────────┤
│ ansible-playbook deploy-pbs.yml --tags verify │
│ ├─ ZFS pool status (ONLINE check) │
│ ├─ PBS service status (systemd check) │
│ ├─ PBS API accessibility (curl test) │
│ ├─ Datastore configuration (API query) │
│ └─ Performance baseline (fio test) │
│ │
│ Output: Health Report, Performance Metrics │
└──────────────────────────────────────────────────────────────┘
关键设计原则:
- Terraform as Source of Truth: 基础设施状态存储在 Terraform state
- Dynamic Inventory: Ansible 从 Terraform state 读取主机信息
- Idempotent: 所有 Ansible tasks 可重复执行
- Verification First: 每个阶段都有自动验证
3. Prerequisites
3.1. Hardware Requirements
3.1.1. ESXi Host 要求
最低配置:
- ESXi 8.0 或更高版本
- CPU: Intel VT-d 或 AMD-Vi 支持(IOMMU)
- 内存: 至少 32GB(为 PBS VM 预留 16GB)
- 可用 PCIe 插槽: 至少 3 个
- 1 × LSI 3008 HBA
- 2 × NVMe (或 1 × 双口 PCIe 转接卡)
BIOS/UEFI 设置:
✅ Intel VT-d / AMD-Vi: Enabled
✅ IOMMU: Enabled
✅ SR-IOV: Enabled (可选)
✅ PCIe ACS (Access Control Services): Enabled
3.1.2. Storage 设备要求
LSI 3008 HBA:
- ✅ 固件模式: IT Mode (非 IR/RAID 模式)
- ✅ 连接设备: 2 × 8TB SATA HDD(仅用于 PBS)
- ✅ 驱动: ESXi 8.x 原生支持
- ❌ 不要配置 RAID: HBA 应设置为 JBOD/直通模式
验证 IT 模式:
# 在 ESXi 上检查 HBA
esxcli hardware pci list | grep -i lsi
# 应显示: LSI Logic SAS3008 IT
# 在 PBS VM 内检查(部署后)
lspci | grep -i lsi
# 应显示: LSI Logic / Symbios Logic SAS3008 PCI-Express Fusion-MPT SAS-3
NVMe 设备:
- ✅ 容量: 2 × 256GB (或更大)
- ✅ 接口: PCIe 3.0 x4 或更高
- ✅ 连接: 通过 PCIe 转接卡或主板 M.2 插槽
- ⚠️ 确保 NVMe 在独立的 IOMMU 组(后续验证)
3.1.3. Network 要求
- ✅ 静态 IP 可用: 192.168.1.249
- ✅ 网络带宽: 至少 1Gbps(推荐 10Gbps)
- ✅ VLAN: 根据环境配置(可选)
3.2. Software Requirements
3.2.1. 本地开发环境
必需软件:
# Terraform
terraform --version
# 要求: >= 1.14.0
# Ansible
ansible --version
# 要求: >= 2.16.0
# Python
python3 --version
# 要求: >= 3.8
# Git
git --version
Terraform Providers:
# terraform/esxi/versions.tf
required_providers {
vsphere = {
source = "hashicorp/vsphere"
version = "~> 2.6"
}
ansible = {
source = "ansible/ansible"
version = "~> 1.3.0"
}
}
Ansible Collections:
# 安装所需 collections
ansible-galaxy collection install community.general
ansible-galaxy collection install cloud.terraform
3.2.2. vCenter Server
- ✅ vCenter Server 版本: 7.0 或 8.0
- ✅ ESXi Host 已添加到 vCenter
- ✅ Datacenter 和 Cluster 已配置
- ✅ Datastore 有足够空间(至少 100GB for VM + ISO)
3.2.3. Proxmox Backup Server ISO
下载最新版本:
# 官方下载页面
https://www.proxmox.com/en/downloads/proxmox-backup-server
# 当前稳定版 (示例)
proxmox-backup-server_3.1-1.iso
3.3. Access Requirements
3.3.1. Credentials Checklist
vCenter / ESXi:
PBS VM:
Netbox:
3.3.2. SSH Agent Setup
在宿主机将已批准的 SSH 私钥加载到 SSH agent,并确认 public identity 已加载:
ssh-add /path/to/host-managed-key
ssh-add -L
不要在仓库工作区或 sandbox 中创建、复制或配置私钥路径。启动 sandbox 后再次运行 ssh-add -L;Ansible
通过转发的 agent 连接 PBS。
3.3.3. Ansible Vault Setup
# 创建 vault 密码文件
echo "your-secure-vault-password" > ansible/.vault_pass
chmod 600 ansible/.vault_pass
# 将密码文件添加到 .gitignore(已包含)
4. Infrastructure as Code Structure
4.1. Project File Organization
本部署涉及以下目录和文件:
IaC/
├── terraform/
│ ├── esxi/ # ESXi 基础设施
│ │ ├── main.tf # 已存在(空主文件)
│ │ ├── provider.tf # 已存在(vSphere provider)
│ │ ├── versions.tf # 🔄 需更新:添加 Ansible provider
│ │ ├── variables.tf # 🔄 需更新:添加 PBS 变量
│ │ ├── terraform.tfvars # 🔄 需更新:填写 PBS 配置
│ │ ├── pbs.tf # 🆕 PBS VM 定义 + PCIe 直通配置
│ │ ├── pbs-iso.tf # 🆕 ISO 管理(可选)
│ │ └── outputs.tf # 🆕 PBS 输出
│ │
│ ├── modules/
│ │ └── esxi-vm/ # 🆕 通用 ESXi VM 模块
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── outputs.tf
│ │
│ └── netbox-integration/
│ └── pbs-esxi.tf # 🆕 PBS Netbox 记录
│
├── ansible/
│ ├── inventory/
│ │ ├── terraform-esxi.yml # 🆕 ESXi Terraform inventory
│ │ ├── groups.yml # 🔄 需更新:添加 esxi_vms 组
│ │ └── group_vars/
│ │ └── esxi_vms.yml # 🆕 ESXi VMs 组变量
│ │
│ ├── roles/
│ │ ├── pbs/ # 🆕 PBS 核心角色
│ │ │ ├── tasks/
│ │ │ │ ├── main.yml
│ │ │ │ ├── install.yml
│ │ │ │ ├── configure.yml
│ │ │ │ └── users.yml
│ │ │ ├── defaults/main.yml
│ │ │ ├── handlers/main.yml
│ │ │ ├── templates/
│ │ │ │ └── network-interfaces.j2
│ │ │ └── vars/
│ │ │ └── vault.yml # 🔐 加密的密码
│ │ │
│ │ └── pbs_zfs/ # 🆕 ZFS 配置角色
│ │ ├── tasks/
│ │ │ ├── main.yml
│ │ │ ├── verify-devices.yml
│ │ │ ├── create-pool.yml
│ │ │ ├── optimize.yml
│ │ │ └── datastore.yml
│ │ ├── defaults/main.yml
│ │ ├── handlers/main.yml
│ │ └── templates/
│ │ └── zfs-arc.conf.j2
│ │
│ └── playbooks/
│ └── deploy-pbs.yml # 🆕 完整部署 playbook
│
├── scripts/
│ └── pbs/ # 🆕 PBS 工具脚本
│ ├── discover-pci-devices.sh # PCI 设备发现
│ ├── create-hba-passthrough.sh # HBA 直通辅助
│ └── validate-deployment.sh # 部署验证
│
└── docs/
└── deployment/
└── pbs-esxi-deployment.md # 📄 本文档
符号说明:
- 🆕 新建文件
- 🔄 更新现有文件
- 🔐 需要加密/敏感
- ✅ 已存在,无需修改
4.2.1. Provider Configuration
文件: terraform/esxi/versions.tf
terraform {
required_version = ">= 1.0.0"
# Terraform Cloud Backend(已配置)
cloud {
organization = "homelab-roseville"
workspaces {
name = "iac-esxi-lab" # 新建 workspace
}
}
required_providers {
vsphere = {
source = "hashicorp/vsphere"
version = "~> 2.6"
}
# ✨ 新增 Ansible Provider
ansible = {
source = "ansible/ansible"
version = "~> 1.3.0"
}
}
}
文件: terraform/esxi/provider.tf
provider "vsphere" {
user = var.vsphere_user
password = var.vsphere_password
vsphere_server = var.vsphere_server
allow_unverified_ssl = true
}
# Ansible Provider 无需额外配置
# 资源会自动写入 Terraform state
4.2.2. Module Design
文件: terraform/modules/esxi-vm/main.tf
# 通用 ESXi VM 模块
# 支持 PCIe 直通、内存预留、EFI 固件
resource "vsphere_virtual_machine" "vm" {
name = var.vm_name
resource_pool_id = var.resource_pool_id
datastore_id = var.datastore_id
num_cpus = var.num_cpus
memory = var.memory
# PCIe 直通必须预留内存
memory_reservation = var.memory_reservation
# EFI 固件
firmware = var.firmware
# 网络配置
network_interface {
network_id = var.network_id
adapter_type = var.network_adapter_type
}
# 系统磁盘
disk {
label = "disk0"
size = var.system_disk_size
thin_provisioned = true
}
# PCIe 直通设备
dynamic "pci_device_id" {
for_each = var.pci_device_ids
content {
device_id = pci_device_id.value
}
}
# 客户机配置(如果使用 cloud-init)
# ...
}
4.2.3. PBS VM Resource
文件: terraform/esxi/pbs.tf
# PBS VM 定义
module "pbs" {
source = "../modules/esxi-vm"
# 基础配置
vm_name = var.pbs_vm_name
resource_pool_id = data.vsphere_host.host.resource_pool_id
datastore_id = data.vsphere_datastore.datastore.id
network_id = data.vsphere_network.network.id
# 硬件配置
num_cpus = var.pbs_num_cpus
memory = var.pbs_memory_mb
memory_reservation = var.pbs_memory_mb # 预留全部(PCIe 直通要求)
system_disk_size = var.pbs_system_disk_gb
firmware = "efi"
network_adapter_type = "vmxnet3"
# PCIe 直通设备
pci_device_ids = concat(
[var.pbs_hba_pci_id], # LSI 3008 HBA
var.pbs_nvme_pci_ids # 2 × NVMe
)
}
# ✨ 注册到 Ansible Inventory
resource "ansible_host" "pbs" {
name = "pbs"
groups = ["esxi_vms"]
variables = {
ansible_user = "root"
ansible_host = var.pbs_ip_address
# PBS 特定变量(传递给 Ansible)
pbs_datastore_path = "/mnt/backup-pool/datastore"
pbs_zfs_pool = "backup-pool"
}
depends_on = [module.pbs]
}
# 输出
output "pbs_vm_id" {
value = module.pbs.vm_id
description = "PBS VM Managed Object ID"
}
output "pbs_ip" {
value = var.pbs_ip_address
description = "PBS Management IP"
}
4.3. Ansible Roles Structure
4.3.1. pbs Role (Core Configuration)
目录结构:
roles/pbs/
├── tasks/
│ ├── main.yml # 主入口
│ ├── install.yml # 包安装
│ ├── configure.yml # 系统配置
│ └── users.yml # PBS 用户管理
├── defaults/main.yml # 默认变量
├── handlers/main.yml # 处理器
├── templates/
│ └── network-interfaces.j2
└── vars/
└── vault.yml # 🔐 加密密码
关键文件: roles/pbs/tasks/main.yml
---
- name: Include system package installation
include_tasks: install.yml
tags: [install, packages]
- name: Include PBS configuration
include_tasks: configure.yml
tags: [configure]
- name: Include PBS user management
include_tasks: users.yml
tags: [users]
关键文件: roles/pbs/defaults/main.yml
---
# PBS Configuration
pbs_timezone: "Australia/Sydney"
pbs_port: 8007
pbs_datastore_name: "backup-storage"
# ZFS ARC Limits (内存 16GB)
pbs_zfs_arc_max_gb: 8
pbs_zfs_arc_min_gb: 2
# Network Configuration
pbs_reconfigure_network: false
# PBS Users (passwords in vault.yml)
pbs_backup_user_email: "fanweiblue@gmail.com"
4.3.2. pbs_zfs Role (Storage Configuration)
目录结构:
roles/pbs_zfs/
├── tasks/
│ ├── main.yml # 主流程
│ ├── verify-devices.yml # 设备验证
│ ├── create-pool.yml # 创建 ZFS pool
│ ├── optimize.yml # 性能优化
│ └── datastore.yml # PBS datastore
├── defaults/main.yml # ZFS 参数
├── handlers/main.yml # initramfs 更新
└── templates/
└── zfs-arc.conf.j2 # ARC 配置
关键文件: roles/pbs_zfs/defaults/main.yml
---
# ZFS Pool Configuration
pbs_zfs_pool_name: "backup-pool"
pbs_zfs_mount_point: "/mnt/backup-pool"
# Device Paths(from Terraform variables)
pbs_zfs_hdd_devices:
- /dev/sdb
- /dev/sdc
pbs_zfs_nvme_devices:
- /dev/nvme0n1
- /dev/nvme1n1
# ZFS Optimization Parameters
pbs_zfs_ashift: 12
pbs_zfs_compression: "zstd"
pbs_zfs_atime: "off"
pbs_zfs_special_small_blocks: "128K"
pbs_zfs_recordsize: "128K"
pbs_zfs_primarycache: "metadata"
pbs_zfs_redundant_metadata: "most"
# ARC Configuration
pbs_zfs_arc_max_gb: 8
pbs_zfs_arc_min_gb: 2
pbs_zfs_arc_max_bytes: "{{ (pbs_zfs_arc_max_gb * 1024 * 1024 * 1024) | int }}"
# PBS Datastore
pbs_datastore_name: "backup-storage"
pbs_datastore_path: "/mnt/backup-pool/datastore"
pbs_gc_schedule: "daily"
4.4. Inventory Source of Truth
架构原则:Terraform 是 infrastructure 的唯一真实来源(Source of Truth),Ansible inventory 通过动态插件从 Terraform state 读取。
Proxmox 环境(已有参考):
# ansible/inventory/terraform.yml
plugin: cloud.terraform.terraform_provider
project_path: ../terraform/proxmox
ESXi 环境(新建):
# ansible/inventory/terraform-esxi.yml
plugin: cloud.terraform.terraform_provider
project_path: ../terraform/esxi
关键点:
- ✅ 从
ansible/ 运行 Ansible 时,project_path 使用相对于该目录的 ../terraform/...;当前 inventory 由 Terraform Cloud state 提供数据 - ✅ Ansible 自动发现所有
ansible_host 资源 - ✅ 无需手动维护
hosts.yml 文件 - ❌ 不要在
ansible/inventory/esxi_vms/hosts.yml 中硬编码主机
4.4.2. Inventory Groups
文件: ansible/inventory/groups.yml(更新)
---
all:
children:
proxmox_cluster:
esxi_hosts:
esxi_vms: # ← 新增组
oci:
tailscale:
children:
proxmox_cluster:
oci:
pve_lxc:
pve_vms:
esxi_vms: # ← 加入 Tailscale 组(如果需要)
pve_lxc:
pve_vms:
文件: ansible/inventory/group_vars/esxi_vms.yml(新建)
---
# ESXi VMs 组变量
ansible_python_interpreter: /usr/bin/python3
ansible_ssh_common_args: '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
ansible_connection: ssh
# 默认用户(可被 host 变量覆盖)
ansible_user: root
4.4.3. 验证 Inventory
# 查看所有主机(包括从 Terraform 读取的)
ansible-inventory --list
# 查看 esxi_vms 组
ansible-inventory --graph esxi_vms
# 输出示例:
# esxi_vms:
# |--pbs
# 查看 PBS 主机详情
ansible-inventory --host pbs --yaml
# 输出示例:
# ansible_host: 192.168.1.249
# ansible_user: root
# pbs_datastore_path: /mnt/backup-pool/datastore
# pbs_zfs_pool: backup-pool
# 测试连接
ansible pbs -m ping
5. Implementation Phases Overview
部署分为 6 个阶段,总耗时约 10-14 小时(首次部署,包括学习和调试)。
建议实施节奏:
- 第 1 天: Phase 0-1(硬件发现 + Terraform 部署)
- 第 2 天: Phase 2-3(PBS 安装 + Ansible 配置)
- 第 3 天: Phase 4-5(Netbox 集成 + 验证测试)
前置检查清单:
6. Phase 0: Discovery and Preparation
6.1. Hardware Device Discovery
在开始 Terraform 部署前,必须获取 PCIe 设备的准确 ID。
6.1.1. 创建发现脚本
文件: scripts/pbs/discover-pci-devices.sh
#!/bin/bash
# PBS PCIe Device Discovery Script
# Purpose: Discover LSI HBA and NVMe PCI IDs on ESXi host
echo "=== PBS Hardware Discovery ==="
echo ""
echo "1. LSI 3008 HBA Card:"
esxcli hardware pci list | grep -A 10 "LSI.*3008"
echo ""
echo "2. NVMe Devices:"
esxcli hardware pci list | grep -A 10 "NVMe\|Non-Volatile"
echo ""
echo "3. All PCIe Devices (condensed):"
esxcli hardware pci list | grep -E "Address:|Device Name:"
echo ""
echo "4. Connected SATA Disks (via HBA):"
esxcli storage core device list | grep -E "Display Name:|Size:"
echo ""
echo "=== Instructions ==="
echo "Copy the PCI IDs (format: 0000:XX:XX.X) to terraform/esxi/terraform.tfvars"
6.1.2. 执行发现脚本
# 1. 将脚本复制到 ESXi
scp scripts/pbs/discover-pci-devices.sh root@192.168.1.251:/tmp/
# 2. SSH 到 ESXi 并执行
ssh root@192.168.1.251
chmod +x /tmp/discover-pci-devices.sh
/tmp/discover-pci-devices.sh > /tmp/pbs-hardware-info.txt
cat /tmp/pbs-hardware-info.txt
预期输出示例:
1. LSI 3008 HBA Card:
Address: 0000:03:00.0
Device Name: LSI Logic / Symbios Logic SAS3008 PCI-Express Fusion-MPT SAS-3
2. NVMe Devices:
Address: 0000:01:00.0
Device Name: Samsung Electronics Co Ltd NVMe SSD Controller
Address: 0000:02:00.0
Device Name: Samsung Electronics Co Ltd NVMe SSD Controller
记录以下信息:
- LSI HBA PCI ID:
0000:03:00.0 - NVMe 1 PCI ID:
0000:01:00.0 - NVMe 2 PCI ID:
0000:02:00.0
6.2. 配置文件准备
文件: terraform/esxi/terraform.tfvars(追加)
# ==========================================
# PBS Configuration
# ==========================================
# VM Basic Settings
pbs_vm_name = "proxmox-backup-server"
pbs_vmid = 200
pbs_ip_address = "192.168.1.249"
# Hardware Resources
pbs_num_cpus = 8
pbs_memory_mb = 16384
pbs_system_disk_gb = 80
# PCIe Passthrough Devices (从 Phase 0.1 获取)
pbs_hba_pci_id = "0000:03:00.0" # ← 替换为实际 ID
pbs_nvme_pci_ids = [
"0000:01:00.0", # ← 替换为实际 ID
"0000:02:00.0" # ← 替换为实际 ID
]
6.2.2. Ansible Vault
cd ansible/
# 创建加密的密码文件
ansible-vault create roles/pbs/vars/vault.yml
# 内容(输入后保存):
---
pbs_root_password: "YourSecureRootPassword"
pbs_backup_user_password: "BackupUserPassword"
6.3. 验证先决条件
# 1. 检查 IOMMU
ssh root@192.168.1.251 "esxcli system settings kernel list | grep iommu"
# 应显示: iovDisableIR = TRUE
# 2. 检查 HBA IT 模式
ssh root@192.168.1.251 "esxcli hardware pci list | grep -i lsi"
# 确认显示 "SAS3008 IT"
# 3. 测试 vCenter 连接
cd terraform/esxi/
terraform init
terraform validate
文件: terraform/esxi/versions.tf(完整内容)
terraform {
required_version = ">= 1.0.0"
cloud {
organization = "homelab-roseville"
workspaces {
name = "iac-esxi-lab"
}
}
required_providers {
vsphere = {
source = "hashicorp/vsphere"
version = "~> 2.6"
}
ansible = {
source = "ansible/ansible"
version = "~> 1.3.0"
}
}
}
7.2. 创建 ESXi VM 模块
文件: terraform/modules/esxi-vm/main.tf
terraform {
required_providers {
vsphere = {
source = "hashicorp/vsphere"
}
}
}
resource "vsphere_virtual_machine" "vm" {
name = var.vm_name
resource_pool_id = var.resource_pool_id
datastore_id = var.datastore_id
num_cpus = var.num_cpus
memory = var.memory
memory_reservation = var.memory_reservation
firmware = var.firmware
guest_id = var.guest_id
network_interface {
network_id = var.network_id
adapter_type = var.network_adapter_type
}
disk {
label = "disk0"
size = var.system_disk_size
thin_provisioned = true
}
# PCIe 直通设备
dynamic "pci_device_id" {
for_each = var.pci_device_ids
content {
device_id = pci_device_id.value
}
}
cdrom {
client_device = true
}
wait_for_guest_net_timeout = 0
}
output "vm_id" {
value = vsphere_virtual_machine.vm.id
}
output "vm_name" {
value = vsphere_virtual_machine.vm.name
}
文件: terraform/modules/esxi-vm/variables.tf
variable "vm_name" {
type = string
}
variable "resource_pool_id" {
type = string
}
variable "datastore_id" {
type = string
}
variable "network_id" {
type = string
}
variable "num_cpus" {
type = number
default = 2
}
variable "memory" {
type = number
default = 4096
}
variable "memory_reservation" {
type = number
default = 0
}
variable "system_disk_size" {
type = number
default = 40
}
variable "firmware" {
type = string
default = "efi"
}
variable "guest_id" {
type = string
default = "debian11_64Guest"
}
variable "network_adapter_type" {
type = string
default = "vmxnet3"
}
variable "pci_device_ids" {
type = list(string)
default = []
}
7.3. PBS VM 定义
文件: terraform/esxi/pbs.tf
module "pbs" {
source = "../modules/esxi-vm"
vm_name = var.pbs_vm_name
resource_pool_id = data.vsphere_host.host.resource_pool_id
datastore_id = data.vsphere_datastore.datastore.id
network_id = data.vsphere_network.network.id
num_cpus = var.pbs_num_cpus
memory = var.pbs_memory_mb
memory_reservation = var.pbs_memory_mb
system_disk_size = var.pbs_system_disk_gb
firmware = "efi"
guest_id = "debian11_64Guest"
network_adapter_type = "vmxnet3"
pci_device_ids = concat(
[var.pbs_hba_pci_id],
var.pbs_nvme_pci_ids
)
}
resource "ansible_host" "pbs" {
name = "pbs"
groups = ["esxi_vms"]
variables = {
ansible_user = "root"
ansible_host = var.pbs_ip_address
pbs_datastore_path = "/mnt/backup-pool/datastore"
pbs_zfs_pool = "backup-pool"
}
depends_on = [module.pbs]
}
output "pbs_vm_id" {
value = module.pbs.vm_id
}
output "pbs_ip" {
value = var.pbs_ip_address
}
7.4. 扩展变量定义
文件: terraform/esxi/variables.tf(追加)
# PBS VM Configuration
variable "pbs_vm_name" {
type = string
default = "proxmox-backup-server"
}
variable "pbs_vmid" {
type = number
default = 200
}
variable "pbs_ip_address" {
type = string
}
variable "pbs_num_cpus" {
type = number
default = 8
}
variable "pbs_memory_mb" {
type = number
default = 16384
}
variable "pbs_system_disk_gb" {
type = number
default = 80
}
variable "pbs_hba_pci_id" {
type = string
description = "LSI 3008 HBA PCI ID (e.g., 0000:03:00.0)"
}
variable "pbs_nvme_pci_ids" {
type = list(string)
description = "NVMe PCI IDs (e.g., ['0000:01:00.0', '0000:02:00.0'])"
}
cd terraform/esxi/
# 1. 初始化(首次或添加新 provider)
terraform init -upgrade
# 2. 验证配置
terraform validate
# 3. 预览变更
terraform plan
# 检查输出:
# - 将创建 vsphere_virtual_machine.vm (module.pbs)
# - 将创建 ansible_host.pbs
# - PCI devices: 3 个(1 HBA + 2 NVMe)
# 4. 应用
terraform apply
# 5. 验证输出
terraform output pbs_vm_id
terraform output pbs_ip
7.6. 启用 PCIe 直通(ESXi 端)
Terraform 会附加 PCI 设备,但首次使用需要在 ESXi 端启用直通模式:
# SSH 到 ESXi
ssh root@192.168.1.251
# 启用 HBA 直通
esxcli hardware pci pcipassthru set -d=0000:03:00.0 -e=true -a
# 启用 NVMe 直通
esxcli hardware pci pcipassthru set -d=0000:01:00.0 -e=true -a
esxcli hardware pci pcipassthru set -d=0000:02:00.0 -e=true -a
# 重启 ESXi(必须)
reboot
重启后验证:
# 检查直通状态
esxcli hardware pci pcipassthru list | grep -E "0000:03:00.0|0000:01:00.0|0000:02:00.0"
# 应显示: Enabled = true
8. Phase 2: PBS ISO Installation
8.1. 挂载 PBS ISO
通过 vCenter Web UI:
上传 PBS ISO 到 ESXi Datastore
- 导航到: Storage → Datastore → Upload
- 上传:
proxmox-backup-server_3.1-1.iso
配置 VM CD/DVD
- 右键 PBS VM → Edit Settings
- CD/DVD Drive → Datastore ISO File
- 选择:
proxmox-backup-server_3.1-1.iso - ✅ Connect at power on
启动 VM
8.2. PBS 安装流程
启动后选择:
- Install Proxmox Backup Server (Graphical)
安装配置:
完成安装:
- 点击 Install
- 等待约 5-10 分钟
- Reboot
- 卸载 ISO(Edit Settings → CD/DVD → Client Device)
8.3. 初始验证
# 1. SSH 连接测试
ssh root@192.168.1.249
# 2. 检查系统信息
uname -a
cat /etc/os-release
# 3. 验证直通设备
lsblk
# 应看到:
# sda 80G (系统盘)
# sdb 8T (HDD #1)
# sdc 8T (HDD #2)
# nvme0n1 256G
# nvme1n1 256G
lspci | grep -i "lsi\|nvme"
# 应看到:
# 03:00.0 Serial Attached SCSI controller: LSI Logic SAS3008
# 01:00.0 Non-Volatile memory controller: Samsung ...
# 02:00.0 Non-Volatile memory controller: Samsung ...
# 4. 网络测试
ip addr show
ping -c 3 192.168.1.1
ping -c 3 8.8.8.8
# 5. 检查 PBS 服务
systemctl status proxmox-backup
# 6. 访问 Web UI(从浏览器)
# https://192.168.1.249:8007
9. Phase 3: Ansible Configuration
9.1. 创建 Ansible Inventory
文件: ansible/inventory/terraform-esxi.yml
plugin: cloud.terraform.terraform_provider
project_path: ../terraform/esxi
更新: ansible/inventory/groups.yml
all:
children:
proxmox_cluster:
esxi_hosts:
esxi_vms:
oci:
tailscale:
children:
proxmox_cluster:
oci:
pve_lxc:
pve_vms:
esxi_vms:
pve_lxc:
pve_vms:
创建: ansible/inventory/group_vars/esxi_vms.yml
---
ansible_python_interpreter: /usr/bin/python3
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
验证 Inventory:
cd ansible/
ansible-inventory --list
ansible-inventory --host pbs
ansible pbs -m ping
9.2. 创建 pbs Role
文件: ansible/roles/pbs/tasks/main.yml
---
- include_tasks: install.yml
tags: [install]
- include_tasks: configure.yml
tags: [configure]
- include_tasks: users.yml
tags: [users]
文件: ansible/roles/pbs/tasks/install.yml
---
- name: Update apt cache
apt:
update_cache: yes
cache_valid_time: 3600
- name: Install ZFS utilities
apt:
name:
- zfsutils-linux
- zfs-dkms
state: present
- name: Install system utilities
apt:
name:
- vim
- htop
- iotop
- fio
- chrony
- curl
state: present
- name: Ensure chrony is running
systemd:
name: chrony
state: started
enabled: yes
文件: ansible/roles/pbs/tasks/configure.yml
---
- name: Set timezone
timezone:
name: "{{ pbs_timezone | default('Australia/Sydney') }}"
- name: Configure ZFS ARC limits
lineinfile:
path: /etc/modprobe.d/zfs.conf
line: "options zfs zfs_arc_max={{ pbs_zfs_arc_max_bytes }}"
create: yes
notify: Update PBS initramfs
文件: ansible/roles/pbs/handlers/main.yml
配置变化后由 handler 重建 initramfs,同一个 play 中多次通知只执行一次。
---
- name: Update PBS initramfs
ansible.builtin.command: update-initramfs -u
changed_when: true
文件: ansible/roles/pbs/tasks/users.yml
---
- name: Wait for PBS API
wait_for:
port: 8007
timeout: 60
- name: Create PBS backup user
uri:
url: "https://{{ ansible_host }}:8007/api2/json/access/users"
method: POST
user: root@pam
password: "{{ pbs_root_password }}"
force_basic_auth: yes
validate_certs: no
body_format: json
body:
userid: "backup@pbs"
password: "{{ pbs_backup_user_password }}"
email: "fanweiblue@gmail.com"
status_code: [200, 201]
failed_when: false
文件: ansible/roles/pbs/defaults/main.yml
---
pbs_timezone: "Australia/Sydney"
pbs_port: 8007
pbs_zfs_arc_max_gb: 8
pbs_zfs_arc_max_bytes: "{{ (pbs_zfs_arc_max_gb * 1024 * 1024 * 1024) | int }}"
9.3. 创建 pbs_zfs Role
文件: ansible/roles/pbs_zfs/tasks/main.yml
---
- include_tasks: verify-devices.yml
tags: [verify]
- include_tasks: create-pool.yml
tags: [pool]
- include_tasks: optimize.yml
tags: [optimize]
- include_tasks: datastore.yml
tags: [datastore]
文件: ansible/roles/pbs_zfs/tasks/verify-devices.yml
---
- name: Check HDD devices
stat:
path: "/dev/{{ item }}"
loop:
- sdb
- sdc
register: hdd_check
- name: Assert HDDs exist
assert:
that: hdd_check.results | selectattr('stat.exists') | list | length == 2
fail_msg: "HDD devices not found"
- name: Check NVMe devices
stat:
path: "/dev/{{ item }}"
loop:
- nvme0n1
- nvme1n1
register: nvme_check
- name: Assert NVMes exist
assert:
that: nvme_check.results | selectattr('stat.exists') | list | length == 2
fail_msg: "NVMe devices not found"
文件: ansible/roles/pbs_zfs/tasks/create-pool.yml
---
- name: Check if pool exists
command: zpool list backup-pool
register: pool_check
failed_when: false
changed_when: false
- name: Create ZFS pool with HDD mirror
command: >
zpool create
-o ashift=12
-O compression=lz4
-O atime=off
-O xattr=sa
-O dnodesize=auto
-m /mnt/backup-pool
backup-pool
mirror /dev/sdb /dev/sdc
when: pool_check.rc != 0
- name: Add NVMe special vdev
command: >
zpool add backup-pool
special
mirror /dev/nvme0n1 /dev/nvme1n1
when: pool_check.rc != 0
文件: ansible/roles/pbs_zfs/tasks/optimize.yml
---
- name: Set special_small_blocks
command: zfs set special_small_blocks=128K backup-pool
- name: Set recordsize
command: zfs set recordsize=128K backup-pool
- name: Enable zstd compression
command: zfs set compression=zstd backup-pool
- name: Optimize cache
command: zfs set primarycache=metadata backup-pool
- name: Set redundant metadata
command: zfs set redundant_metadata=most backup-pool
文件: ansible/roles/pbs_zfs/tasks/datastore.yml
---
- name: Create ZFS dataset
command: zfs create backup-pool/datastore
args:
creates: /mnt/backup-pool/datastore
- name: Set permissions
file:
path: /mnt/backup-pool/datastore
owner: backup
group: backup
mode: '0770'
state: directory
- name: Create PBS datastore
uri:
url: "https://{{ ansible_host }}:8007/api2/json/admin/datastore"
method: POST
user: root@pam
password: "{{ pbs_root_password }}"
force_basic_auth: yes
validate_certs: no
body_format: json
body:
name: "backup-storage"
path: "/mnt/backup-pool/datastore"
"gc-schedule": "daily"
status_code: [200, 201]
failed_when: false
9.4. 部署 Playbook
文件: ansible/playbooks/deploy-pbs.yml
---
- name: Deploy Proxmox Backup Server
hosts: pbs
become: yes
vars_files:
- ../roles/pbs/vars/vault.yml
roles:
- role: pbs
tags: [pbs]
- role: pbs_zfs
tags: [zfs]
- name: Verify Deployment
hosts: pbs
become: yes
tags: [verify]
vars_files:
- ../roles/pbs/vars/vault.yml
tasks:
- name: Check ZFS pool
command: zpool status backup-pool
register: zpool_status
failed_when: "'ONLINE' not in zpool_status.stdout"
- name: Check PBS service
systemd:
name: proxmox-backup
register: pbs_service
- name: Test PBS API
uri:
url: "https://{{ ansible_host }}:8007/api2/json/admin/datastore"
user: root@pam
password: "{{ pbs_root_password }}"
force_basic_auth: yes
validate_certs: no
register: api_test
- name: Display summary
debug:
msg:
- "✅ PBS Deployment Complete"
- "Web UI: https://{{ ansible_host }}:8007"
- "ZFS Pool: ONLINE"
- "Datastore: backup-storage"
9.5. 执行部署
cd ansible/
# 完整部署
ansible-playbook playbooks/deploy-pbs.yml --ask-vault-pass
# 仅验证
ansible-playbook playbooks/deploy-pbs.yml --tags verify --ask-vault-pass
10. Phase 4: Netbox Integration
文件: terraform/netbox-integration/pbs-esxi.tf
resource "netbox_site" "roseville" {
name = "Roseville"
slug = "roseville"
}
resource "netbox_cluster_type" "vmware" {
name = "VMware ESXi"
slug = "vmware-esxi"
}
resource "netbox_cluster" "esxi" {
name = "ESXi-Roseville"
cluster_type_id = netbox_cluster_type.vmware.id
site_id = netbox_site.roseville.id
}
resource "netbox_virtual_machine" "pbs" {
name = "proxmox-backup-server"
cluster_id = netbox_cluster.esxi.id
vcpus = 8
memory = 16384
disk = 80
comments = "PBS with ZFS (2×8TB HDD + 2×256GB NVMe special vdev)"
tags = ["backup", "zfs", "esxi"]
}
resource "netbox_interface" "pbs_eth0" {
name = "eth0"
virtual_machine_id = netbox_virtual_machine.pbs.id
type = "virtual"
}
resource "netbox_ip_address" "pbs_ip" {
ip_address = "192.168.1.249/24"
status = "active"
interface_id = netbox_interface.pbs_eth0.id
dns_name = "pbs.willfan.me"
}
resource "netbox_service" "pbs_web" {
name = "PBS Web UI"
virtual_machine_id = netbox_virtual_machine.pbs.id
protocol = "tcp"
ports = [8007]
}
执行:
cd terraform/netbox-integration/
terraform apply
11.1. 自动验证
已包含在 deploy-pbs.yml 的 verify 标签中。
11.2. 手动验证清单
# ZFS 健康
zpool status backup-pool
zpool list -v backup-pool
zfs list
# PBS 服务
systemctl status proxmox-backup
journalctl -u proxmox-backup -n 50
# 网络
curl -k https://192.168.1.249:8007
11.3. 性能测试
# 顺序写入
fio --name=seq --rw=write --bs=1M --size=10G --directory=/mnt/backup-pool/datastore --ioengine=libaio --direct=1
# 随机混合
fio --name=rand --rw=randrw --bs=128k --size=5G --numjobs=4 --directory=/mnt/backup-pool/datastore --ioengine=libaio --direct=1
# ZFS I/O 监控
zpool iostat -v backup-pool 2
# ARC 统计
arc_summary
12. Troubleshooting
12.1. PCIe 直通失败
症状: VM 无法启动,错误 “Failed to power on”
解决:
# 检查直通状态
esxcli hardware pci pcipassthru list
# 检查 IOMMU 组
esxcli hardware pci list | grep -A 5 "0000:03:00.0"
# 确保内存预留
# terraform: memory_reservation = memory
12.2. ZFS 设备未找到
症状: /dev/sdb 不存在
解决:
# 检查设备
lsblk
ls -l /dev/disk/by-id/
# 如果是 /dev/disk/by-id/scsi-xxx
# 修改 ansible role 使用 by-id 路径
12.3. PBS API 不可访问
症状: Ansible API 调用失败
解决:
# 检查 PBS 服务
systemctl status proxmox-backup
journalctl -xe
# 检查防火墙
ss -tlnp | grep 8007
# 手动测试
curl -k https://localhost:8007
13. Appendix
13.1. Quick Command Reference
# Terraform
terraform init
terraform plan
terraform apply
terraform destroy
# Ansible
ansible-inventory --list
ansible pbs -m ping
ansible-playbook playbooks/deploy-pbs.yml
# ZFS
zpool status
zfs list
zpool iostat -v 2
# PBS
systemctl status proxmox-backup
proxmox-backup-manager datastore list
13.2. File Index
- Terraform:
terraform/esxi/*.tf - Ansible Roles:
ansible/roles/pbs*/ - Playbooks:
ansible/playbooks/deploy-pbs.yml - Scripts:
scripts/pbs/*.sh
- Netbox Deployment:
docs/guides/netbox-deployment.md - Ansible Verification:
docs/learningnotes/2025-11-30-ansible-deployment-verification.md - Proxmox Terraform:
docs/learningnotes/2025-11-28-terraform-proxmox.md
文档结束
4 - Veeam Backup & Replication 部署指南
版本: 1.0
日期: 2026-02-03
状态: 已完成
适用场景: T7910 冷备份服务器,混合环境备份 (ESXi VM + Windows/Mac 物理机)
1. 架构概述
1.1 备份架构
┌─────────────────────────────────────────────────────────────────┐
│ T7910 (ESXi Host) │
├─────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────────────────┐ │
│ │ PBS VM │ │ Windows Server VM │ │
│ │ │ iSCSI │ │ │
│ │ ZFS Pool ──────┼────────►│ ReFS Volume (E:) │ │
│ │ (backup-pool) │ │ │ │ │
│ │ │ │ ▼ │ │
│ │ - veeam-vol │ │ Veeam VBR │ │
│ │ (2TB ZVol) │ │ Community Edition │ │
│ │ │ │ │ │
│ │ - timemachine │ └─────────────────────────────┘ │
│ │ (1TB dataset)│ │ │
│ └────────┬────────┘ │ │
│ │ SMB │ Backup │
└───────────┼──────────────────────────────┼─────────────────────┘
│ │
▼ ▼
┌──────────┐ ┌──────────────────┐
│ Mac │ │ ESXi VMs │
│ (Time │ │ Windows PC │
│ Machine) │ │ │
└──────────┘ └──────────────────┘
1.2 组件说明
2. 前置条件
2.1 硬件要求
2.2 软件要求
- ESXi 8.x
- Windows Server 2022 Datacenter/Standard
- Veeam Backup & Replication 13 Community Edition
- VMware Tools (Windows VM)
3. 部署步骤
3.1 PBS 端:iSCSI Target 配置
使用 Ansible 自动化部署:
# 部署 PBS iSCSI Target
ansible-playbook playbooks/deploy-pbs-iscsi.yml
# 验证部署
ansible-playbook playbooks/deploy-pbs-iscsi.yml --tags verify
手动验证命令 (在 PBS 上执行):
# 检查 ZVol
zfs list backup-pool/veeam-vol
# 检查 iSCSI Target
targetcli ls /iscsi
# 检查端口
ss -tlnp | grep 3260
配置参数:
3.2 Windows Server VM 创建
Terraform 配置:
cd terraform/esxi
terraform plan
terraform apply
关键配置 (terraform.tfvars):
windows_vm_name = "windows-server"
windows_ip_address = "192.168.1.248"
windows_num_cpus = 4
windows_memory_mb = 16384
windows_system_disk_gb = 80
3.3 Windows Server 安装
从 ISO 安装 Windows Server 2022
- 在 ESXi Web UI 挂载 ISO
- 启动 VM,完成安装向导
- 设置 Administrator 密码
配置静态 IP
New-NetIPAddress -InterfaceAlias "Ethernet0" -IPAddress 192.168.1.248 -PrefixLength 24 -DefaultGateway 192.168.1.1
Set-DnsClientServerAddress -InterfaceAlias "Ethernet0" -ServerAddresses 192.168.1.1
安装 VMware Tools
- ESXi Web UI → 右键 VM → Guest OS → Install VMware Tools
- Windows 内运行 CD 驱动器中的 setup64.exe
- 重启
启用 WinRM (用于 Ansible 管理)
Enable-PSRemoting -Force
Set-Item WSMan:\localhost\Service\AllowUnencrypted -Value $true
Set-Item WSMan:\localhost\Service\Auth\Basic -Value $true
3.4 Windows 端:iSCSI + ReFS 配置
使用 Ansible 自动化:
# 配置 iSCSI 连接和 ReFS 格式化
ansible-playbook playbooks/deploy-windows-iscsi.yml
# 验证配置
ansible-playbook playbooks/deploy-windows-iscsi.yml --tags verify
预期结果:
=== iSCSI Session ===
Target: iqn.2026-02.lan.pbs:veeam
Connected: True
Persistent: True
=== ReFS Volume ===
Drive: E:
Size: 2047.94 GB
Free: 2035.99 GB
3.5 Veeam VBR 安装
下载 Veeam VBR Community Edition
安装前准备
- 关闭 IE Enhanced Security Configuration (Server Manager → Local Server)
- 确保 C: 盘有足够空间 (建议 20GB+)
安装 Veeam
- 运行安装程序
- 选择 Veeam Backup & Replication
- 使用默认设置 (PostgreSQL 数据库)
- 等待安装完成 (可能需要 10-20 分钟)
首次启动
- 启动 Veeam Backup & Replication Console
- 连接到
127.0.0.1:9392 - 使用 Windows 凭证 (Administrator)
3.6 Veeam 配置
3.6.1 添加 Backup Repository
- Backup Infrastructure → Backup Repositories
- 右键 → Add Backup Repository → Direct attached storage → Microsoft Windows
- 名称:
PBS-iSCSI-ReFS - 路径:
E:\Backups - 勾选 Use per-VM backup files (启用 Fast Clone)
3.6.2 添加 ESXi 服务器
- Backup Infrastructure → Managed Servers → Add Server
- 选择 VMware vSphere → vSphere
- 输入 ESXi IP:
192.168.1.251 - 输入 root 凭证
3.6.3 创建备份作业
- Home → Backup Job → VMware vSphere
- 名称:
ESXi-VMs-Backup - 添加要备份的 VM
- 选择 Repository:
PBS-iSCSI-ReFS - 设置计划或手动运行
4. 备份 Windows 物理机
4.1 准备工作
在目标 Windows PC 上创建本地管理员账户:
# 创建 Veeam 专用账户
net user VeeamAdmin "YourPassword123!" /add
net localgroup Administrators VeeamAdmin /add
启用远程管理:
# 允许远程管理员访问
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "LocalAccountTokenFilterPolicy" -Value 1 -PropertyType DWORD -Force
# 启用防火墙规则
Enable-NetFirewallRule -DisplayGroup "File and Printer Sharing"
Enable-NetFirewallRule -DisplayGroup "Windows Management Instrumentation (WMI)"
重启 PC。
4.2 在 Veeam 中添加
- Inventory → Physical Infrastructure
- 右键 → Add Protection Group → Individual computers
- 输入 PC 的 IP 地址
- 使用凭证:
电脑名\VeeamAdmin
5. Mac 备份 (Time Machine)
Mac 使用 Fileserver LXC 上的 Samba 共享进行 Time Machine 备份。基础设施由 Terraform 管理,首次 Samba/Avahi 配置使用一次性 playbook:
# 仅在首次初始化或明确恢复配置时执行
ansible-playbook playbooks/configure-fileserver-timemachine.yml
Mac 端配置:
- 系统设置 → 通用 → Time Machine
- 添加备份磁盘
- 选择 Fileserver 通告的 Time Machine 目标,或手动连接
smb://192.168.1.111/TimeMachine - 用户名:
timemachine - 密码: 从加密的
vault_timemachine_password 获取
6. 故障排除
6.1 Veeam 服务无法启动
症状: VeeamBackupSvc 卡在 Starting 状态
解决方案:
# 重启 PostgreSQL
Restart-Service -Name "postgresql-x64-17"
# 等待后启动 Veeam
Start-Sleep -Seconds 30
Start-Service -Name "VeeamBackupSvc"
6.2 VBR Console 无法连接
症状: SSL Connection error 或 Cannot connect to localhost
解决方案:
# 删除 SSL 证书缓存
Stop-Service -Name "VeeamBackupSvc" -Force
Remove-Item -Path "C:\ProgramData\Veeam\Backup\SSL\*" -Force -Recurse
Start-Service -Name "VeeamBackupSvc"
6.3 iSCSI 磁盘不可见
检查步骤:
# 检查 iSCSI 服务
Get-Service -Name MSiSCSI
# 检查连接
Get-IscsiTarget
Get-IscsiSession
# 重新连接
Connect-IscsiTarget -NodeAddress "iqn.2026-02.lan.pbs:veeam" -IsPersistent $true
6.4 Windows PC 备份失败 (Access Denied)
解决方案:
- 创建本地管理员账户
- 添加注册表项
LocalAccountTokenFilterPolicy = 1 - 启用 WMI 防火墙规则
- 重启 PC
7. 备份架构总览
8. 相关文档