Mục Tiêu Buổi Học
- Hiểu cơ chế vMotion 5 bước (pre-copy, track dirty pages, switchover, resume, cleanup)
- Thực hiện vMotion thành công và kiểm tra prerequisites
- Thực hiện Storage vMotion di chuyển VMDK giữa datastores
- Cấu hình EVC (Enhanced vMotion Compatibility) cho cluster mixed CPU
- Quản lý Resource Pools với Shares, Reservations và Limits
- Quy trình Zero-Downtime Maintenance Mode an toàn
LÝ THUYẾT — MODULE 7
7.1 vMotion — Live Migration
Điều kiện để vMotion hoạt động: ✓ Shared storage (cả 2 host cùng access DS) ✓ Kết nối mạng vMotion (vmknic với vMotion enabled) ✓ Compatible CPU (Enhanced vMotion Compatibility - EVC) ✓ VM không có CD-ROM đang gắn từ local ✓ Không có passthrough devices Cơ chế vMotion (5 bước): 1. Pre-copy: Copy memory pages đang chạy sang host đích 2. Track dirty pages: Theo dõi pages thay đổi trong lúc copy 3. Switchover: Tạm dừng VM (< 1ms), copy dirty pages còn lại 4. Resume: VM tiếp tục chạy trên host đích 5. Cleanup: Giải phóng tài nguyên trên host nguồn
vMotion Network Requirements & Encryption
Network tối thiểu cho vMotion: - 1 GbE minimum (hỗ trợ vMotion cơ bản) - 10 GbE khuyến nghị cho production (nhanh hơn, ít ảnh hưởng workload) vMotion Encryption (vSphere 8.0): - Opportunistic (mặc định): Mã hóa nếu cả 2 host đều hỗ trợ - Required: Bắt buộc mã hóa — vMotion thất bại nếu 1 host không hỗ trợ - Disabled: Không mã hóa (legacy hoặc performance sensitive) Cấu hình: VM → Edit Settings → VM Options → vMotion Encryption
Storage vMotion
Di chuyển VMDK files giữa các datastores TRONG KHI VM đang chạy: - Tạo mirror disk trên datastore đích - Copy dữ liệu nền - Tracked writes (changed block tracking) - Cutover khi mirror đồng bộ vSphere 8.0: Có thể thay đổi datastore VÀ Storage Policy đồng thời trong 1 Storage vMotion operation — không cần 2 bước riêng lẻ. Use cases: - Di chuyển từ SATA sang SSD - Cân bằng storage utilization - Tiền datacenter migration
Enhanced vMotion Compatibility (EVC)
Vấn đề: Intel Haswell host muốn vMotion đến Intel Sandy Bridge → Lỗi: "CPU Incompatible" EVC giải pháp: - Cluster EVC Mode = Sandy Bridge (baseline thấp nhất) - Tất cả hosts trong cluster "present" CPU features của Sandy Bridge - VMs có thể vMotion tự do trong cluster - Chỉ áp dụng cho NEW VMs hoặc powered-off VMs Intel EVC Modes (thứ tự từ cũ → mới): Merom → Penryn → Nehalem → Westmere → Sandy Bridge → Ivy Bridge → Haswell → Broadwell → Skylake → Cascade Lake → Ice Lake → Sapphire Rapids
Resource Management
| Tính năng | Mô tả | Khi nào dùng |
|---|---|---|
| CPU/Memory Shares | Relative priority | Nhiều VMs cạnh tranh tài nguyên |
| Reservations | Guaranteed resources | Mission-critical VMs |
| Limits | Maximum cap | Tránh VM "noisy neighbor" |
| Memory Balloon | Reclaim idle guest memory | Memory overcommit |
| Memory Swap | Swap VM memory to disk | Last resort, ảnh hưởng perf |
| TPS | Share identical memory pages | Memory deduplication |
LAB THỰC HÀNH — MODULE 7
Lab 7.1 — vMotion
Kiểm tra prerequisites:
1. vSphere Client → VM → Summary → Compatibility
Đảm bảo không có warnings
2. Kiểm tra vMotion vmknic:
Host → Configure → VMkernel Adapters → vmk1
Services: ✓ vMotion
3. Migrate VM:
Right-click VM → Migrate
Migration Type: Change compute resource only
Destination: esxi-02.lab.local
Network: DPG-VM-Production
Priority: High priority (uses more CPU for fast migration)
4. Monitor:
Tasks & Events → Task "Relocate virtual machine"
Theo dõi % completion
5. Xác nhận:
VM Summary → Host: esxi-02.lab.local ✓
Lab 7.2 — Storage vMotion
Migrate disk giữa datastores: Right-click VM → Migrate Migration Type: Change storage only VM Storage Policy: Keep existing policies OR chọn Policy mới và datastore mới DS-iSCSI-VMFS6-01 → DS-NFS-Dev Disk format: Same as source / Thin Provision / Thick Monitor: Tasks → "Relocate virtual machine" (storage)
Lab 7.3 — Cross-host + Cross-storage vMotion
Right-click VM → Migrate Migration Type: Change both compute resource and storage Destination Host: esxi-03.lab.local Destination Datastore: DS-NFS-Dev Đây là combined vMotion + Storage vMotion trong 1 operation
Lab 7.4 — Resource Pools và Reservations
Scenario: Web app VM cần đảm bảo 2 GHz CPU và 4 GB RAM 1. Tạo Resource Pool: Cluster → New Resource Pool Name: RP-Critical-Apps CPU: Shares High, Reservation 4000 MHz, Limit Unlimited Memory: Shares High, Reservation 8192 MB, Limit Unlimited 2. Cấu hình VM Resources: Right-click VM → Edit Settings → Virtual Hardware → CPU → Reservation: 2000 MHz → Memory → Reservation: 4096 MB 3. Kiểm tra Admission Control: vCenter sẽ báo lỗi nếu cluster không đủ tài nguyên để đảm bảo reservation 4. Monitor Resource Contention: Host → Monitor → Performance → CPU/Memory Metrics cần xem: - CPU Ready (target: <5%) - Memory Balloon (target: 0 khi đủ RAM) - Memory Swap (target: 0)
ỨNG DỤNG DOANH NGHIỆP — MODULE 6
Thiết kế và vận hành vMotion & Storage vMotion trong môi trường doanh nghiệp — từ network design đến scheduled migration và EVC mode.
1. vMotion Network Design — Dedicated 10GbE
Production cluster bắt buộc dùng dedicated vmkernel port cho vMotion — không share với VM traffic hay management.
Yêu cầu Network cho vMotion Production
- Bandwidth tối thiểu 10GbE dedicated cho vMotion vmkernel — không dùng 1GbE chung với VM traffic
- Latency <150ms cho long-distance vMotion (cross-datacenter)
- VLAN riêng cho vMotion (tách biệt hoàn toàn với management VLAN)
- Jumbo Frames (MTU 9000) nên được bật end-to-end để tối ưu throughput
### TOPOLOGY — vMotion Network Design (Best Practice) ┌──────────────────────────────────────────────────────────┐ │ vDS: vDS-Prod-01 │ │ ┌──────────────────┐ ┌──────────────────────────────┐ │ │ │ dvPG-Mgmt │ │ dvPG-vMotion (VLAN 200) │ │ │ │ VLAN 100 │ │ MTU 9000, dedicated vmk │ │ │ │ vmk0 (Mgmt) │ │ vmk1 (vMotion) │ │ │ └──────────────────┘ └──────────────────────────────┘ │ │ ┌──────────────────┐ ┌──────────────────────────────┐ │ │ │ dvPG-vSAN │ │ dvPG-VM-Traffic │ │ │ │ VLAN 300 │ │ VLAN 10, 20, 30 (trunk) │ │ │ │ vmk2 (vSAN) │ │ VM port groups │ │ │ └──────────────────┘ └──────────────────────────────┘ │ │ │ │ Uplinks: 2x 25GbE (LACP Active/Active) │ └──────────────────────────────────────────────────────────┘ ### PowerCLI — Tạo vmkernel vMotion port Connect-VIServer vcsa-01.lab.local -User [email protected] # Tạo vMotion vmkernel trên tất cả hosts trong cluster Get-Cluster "CL-HN-Prod-01" | Get-VMHost | ForEach-Object { $vmhost = $_ New-VMHostNetworkAdapter -VMHost $vmhost ` -PortGroup "dvPG-vMotion" ` -VirtualSwitch (Get-VDSwitch "vDS-Prod-01") ` -IP "10.200.1.$(($vmhost.Name -split '\.' )[0] -replace '\D','')" ` -SubnetMask "255.255.255.0" ` -VMotionEnabled $true ` -Mtu 9000 }
Best Practice — vMotion vmkernel
- Chỉ bật vMotion service trên vmkernel vMotion — không bật Mgmt, vSAN cùng vmk
- Dùng Multi-NIC vMotion (2 vmk vMotion) để tăng bandwidth và redundancy
- Test vMotion sau khi cấu hình: ping vmk IP giữa các host + chạy vMotion test VM
2. Cross-Datacenter vMotion — Prerequisites & Giới Hạn
vMotion giữa 2 datacenter (HN → HCM) yêu cầu thêm điều kiện so với vMotion trong cùng cluster.
| Điều kiện | Trong cluster | Cross-vCenter (khác DC) | Ghi chú |
|---|---|---|---|
| Shared Storage | Bắt buộc | Không cần (Storage vMotion đồng thời) | Cross-DC dùng vMotion + Storage vMotion |
| Network latency | <10ms | <150ms (RTT) | Cao hơn → vMotion timeout |
| vCenter relationship | Cùng vCenter | Enhanced Linked Mode | Cùng SSO domain |
| EVC Mode | Khuyến nghị | Bắt buộc nếu CPU khác thế hệ | Baseline = CPU thấp nhất |
| VM portgroup | Phải tồn tại | Phải tồn tại ở đích | Tên portgroup phải khớp |
| Bandwidth minimum | 250 Mbps | Phụ thuộc WAN link | Lớn hơn = nhanh hơn |
### PowerCLI — Cross-vCenter vMotion (Enhanced Linked Mode) # Di chuyển VM từ vCenter HN sang vCenter HCM $vmName = "LNXWEB-PORTAL-PRD-01" $srcVC = "vcsa-hn.corp.com" $dstVC = "vcsa-hcm.corp.com" $dstCluster = "CL-HCM-Prod-01" $dstDS = "vSAN-HCM-Prod" $dstPG = "dvPG-App-PRD" Connect-VIServer $srcVC, $dstVC -User [email protected] $vm = Get-VM -Name $vmName -Server $srcVC $dstHost = Get-Cluster $dstCluster -Server $dstVC | Get-VMHost | Select-Object -First 1 $dstDatastore = Get-Datastore -Name $dstDS -Server $dstVC $dstNetwork = Get-VDPortgroup -Name $dstPG -Server $dstVC Move-VM -VM $vm ` -Destination $dstHost ` -Datastore $dstDatastore ` -NetworkAdapter (Get-NetworkAdapter $vm) ` -PortGroup $dstNetwork ` -Confirm:$false
3. Storage vMotion — Use Cases Doanh Nghiệp
Storage vMotion cho phép migrate disk VM giữa các datastore không cần downtime — đây là công cụ không thể thiếu trong storage lifecycle management.
| Use Case | Kịch bản thực tế | Thao tác |
|---|---|---|
| Storage Refresh | Thay thế SAN cũ bằng All-Flash Array mới | svMotion từ old-LUN sang new-LUN, không downtime |
| Datastore Full | Datastore đạt 90% — cần giải phóng space | Di chuyển large VM sang datastore khác còn trống |
| Tiering Storage | Hạ tier VM từ Flash xuống NL-SAS sau EOL | svMotion sang tier thấp hơn khi workload giảm |
| vSAN Migration | Onboard workload từ NFS vào vSAN cluster | svMotion từ NFS datastore vào vSAN datastore |
| Disk Format Change | Convert Thick Provision → Thin để tiết kiệm space | svMotion + chọn Thin Provision tại đích |
### PowerCLI — Storage vMotion tất cả VMs khỏi datastore sắp decommission
$srcDatastore = Get-Datastore "vSAN-Old-Pool"
$dstDatastore = Get-Datastore "vSAN-New-AFA-01"
$vms = Get-VM -Datastore $srcDatastore | Where-Object { $_.PowerState -ne "PoweredOff" }
Write-Host "Cần migrate: $($vms.Count) VMs"
foreach ($vm in $vms) {
Write-Host "Migrating: $($vm.Name)..."
Move-VM -VM $vm -Datastore $dstDatastore -DiskStorageFormat Thin -Confirm:$false
Start-Sleep -Seconds 5 # Tránh overload storage controller
}
Write-Host "Hoàn thành. Kiểm tra datastore cũ: $(($srcDatastore | Get-VM).Count) VMs còn lại."
4. Enhanced vMotion Compatibility (EVC) Mode — Setup & Lưu Ý
EVC đảm bảo tất cả CPU trong cluster trình bày cùng feature set cho VMs — cho phép vMotion giữa các host có CPU khác thế hệ.
Nguyên tắc hoạt động của EVC
- EVC baseline = CPU generation thấp nhất trong cluster (ví dụ: Intel Skylake nếu có mix Skylake + Cascade Lake)
- Chỉ áp dụng cho VMs được power on sau khi bật EVC — VMs đang chạy không bị ảnh hưởng ngay
- Khi nâng cấp tất cả hosts lên thế hệ mới → có thể nâng EVC baseline (cần power off VMs trước)
- AMD và Intel EVC không tương thích nhau — không thể mix AMD + Intel trong 1 EVC cluster
### PowerCLI — Kiểm tra và Set EVC Mode Connect-VIServer vcsa-01.lab.local # Xem danh sách EVC modes hỗ trợ $cluster = Get-Cluster "CL-HN-Prod-01" $cluster | Get-View | Select-Object -ExpandProperty Capability | Select-Object SupportedEVCMode # Kiểm tra EVC hiện tại $cluster | Select-Object Name, EVCMode # Set EVC mode (cluster phải không có VMs đang chạy với CPU incompatible) # Hoặc migrate VMs ra trước Set-Cluster -Cluster $cluster -EVCMode "intel-skylake" -Confirm:$false # Xác nhận Get-Cluster "CL-HN-Prod-01" | Select-Object Name, EVCMode # Output: CL-HN-Prod-01 intel-skylake
| EVC Baseline | CPU Families hỗ trợ | Khi nào dùng |
|---|---|---|
| intel-broadwell | Broadwell, Skylake, CascadeLake, IceLake | Cluster mix nhiều thế hệ cũ |
| intel-skylake | Skylake, CascadeLake, IceLake, Sapphire | Phổ biến nhất trong DC hiện tại |
| intel-icelake | IceLake, Sapphire Rapids | New cluster all-new hardware |
| amd-zen3 | Zen3, Zen4 (EPYC) | AMD-only cluster |
5. Scheduled vMotion — Maintenance Window Planning
Dùng scheduled vMotion để proactively evacuate host trước maintenance window — đảm bảo không có VMs bị impact khi host vào maintenance mode.
### PowerCLI — Scheduled Evacuation trước Maintenance Window
# Chạy trước maintenance window 30 phút
param(
[string]$HostToMaintain = "esxi-hn-r01-01.hoatranlab.io.local",
[string]$TargetCluster = "CL-HN-Prod-01"
)
Connect-VIServer vcsa-hn.corp.com
$hostObj = Get-VMHost -Name $HostToMaintain
$vms = Get-VM -Location $hostObj | Where-Object { $_.PowerState -eq "PoweredOn" }
$dstHosts = Get-Cluster $TargetCluster | Get-VMHost |
Where-Object { $_.Name -ne $HostToMaintain -and $_.ConnectionState -eq "Connected" }
Write-Host "[$(Get-Date)] Bắt đầu evacuate $($vms.Count) VMs khỏi $HostToMaintain"
foreach ($vm in $vms) {
# Chọn host có ít CPU ready nhất
$bestHost = $dstHosts | Sort-Object { ($_ | Get-Stat -Stat cpu.ready.summation -MaxSamples 5).Value | Measure-Object -Average | Select-Object -ExpandProperty Average } | Select-Object -First 1
Write-Host " → vMotion $($vm.Name) → $($bestHost.Name)"
Move-VM -VM $vm -Destination $bestHost -Confirm:$false -RunAsync | Out-Null
}
# Chờ tất cả vMotion hoàn thành
Get-Task | Where-Object { $_.Name -eq "RelocateVM_Task" -and $_.State -eq "Running" } | Wait-Task
Write-Host "[$(Get-Date)] Evacuation hoàn thành. Vào Maintenance Mode..."
Set-VMHost -VMHost $hostObj -State Maintenance -Confirm:$false
Best Practice — Maintenance Window
- Luôn evacuate thủ công trước khi DRS tự migrate — kiểm soát được destination host
- Kiểm tra anti-affinity rules trước khi vMotion — tránh vi phạm rule khi migration
- Xác nhận host đích có đủ RAM free:
($dstHost | Get-View).Summary.QuickStats.FreeMemoryMB
6. vMotion Validation Checklist — Pre & Post Migration
Checklist xác nhận vMotion cluster hoạt động đúng trước khi đưa vào production và sau mỗi lần migrate.
Pre-vMotion Checklist
Post-vMotion Validation