LAB 10 ~90 phút Module 12 Hybrid Storage

Azure File Sync — Hybrid Cloud Storage

Triển khai Storage Sync Service, tạo sync group và cloud endpoint, cài Azure File Sync agent trên Windows Server, cấu hình cloud tiering để tối ưu không gian lưu trữ on-premises.

🎯 Mục Tiêu Lab

Tạo Storage Account, Azure File Share (SMB) làm cloud endpoint

Tạo Storage Sync Service và Sync Group trên Azure Portal

Cài đặt và đăng ký Azure File Sync agent trên Windows Server

Thêm Server Endpoint và xác minh quá trình đồng bộ hoàn thành

Cấu hình Cloud Tiering (free space 20%, cache 30 ngày)

Mount Azure File Share như ổ Z: và so sánh với server endpoint

📋 Chuẩn Bị

Yêu cầu:
  • Windows Server 2019/2022 VM (Azure hoặc on-premises)
  • VM cần có ổ đĩa dữ liệu thứ hai (Data disk ≥ 32 GB)
  • Azure subscription với quyền Contributor
  • Kết nối Internet từ Windows Server (để download agent)
Lưu ý:
  • Azure File Sync agent chỉ hỗ trợ Windows Server 2012 R2 trở lên
  • Cloud Tiering: file ít dùng sẽ được chuyển lên cloud, chỉ còn placeholder trên server
  • Sync lần đầu có thể mất vài phút tùy lượng data
  • Region: Southeast Asia cho toàn bộ resources

🏗️ Kịch Bản & Tài Nguyên

HoaTranLab có file server on-premises với thư mục S:\lab10share. Yêu cầu: đồng bộ lên Azure Files để backup + truy cập từ nhiều chi nhánh, đồng thời bật Cloud Tiering để tiết kiệm dung lượng local.

Resource Group
rg-lab10-filesync
Storage Account
stlab10sync
File Share
lab10share
Sync Service
sss-hoatranlab-lab10
Sync Group
sg-lab10
Server Path
S:\lab10share

🧪 Các Bước Thực Hiện

1

Tạo Storage Account & Azure File Share

Cách 1 — Azure Portal
  1. 1.1Storage Accounts → Create → Name: stlab10sync → Region: Southeast Asia → LRS → GPv2
  2. 1.2Advanced tab → Minimum TLS version: TLS 1.2 → Review + Create
  3. 1.3Storage Account → File shares → + File share → Name: lab10share → Quota: 100 GiB → Tier: Transaction optimized
  4. 1.4File share → Upload một vài file test để có data ban đầu
Cách 2 — Azure CLI
Azure CLI
# Tạo resource group
az group create \
  --name rg-lab10-filesync \
  --location southeastasia

# Tạo Storage Account (TLS 1.2 bắt buộc)
az storage account create \
  --resource-group rg-lab10-filesync \
  --name stlab10sync \
  --location southeastasia \
  --sku Standard_LRS \
  --kind StorageV2 \
  --min-tls-version TLS1_2 \
  --enable-large-file-share

# Tạo file share (100 GiB)
az storage share create \
  --account-name stlab10sync \
  --name lab10share \
  --quota 100 \
  --auth-mode login
2

Tạo Storage Sync Service & Sync Group

Storage Sync Service là service gốc quản lý tất cả sync relationship. Một Sync Group định nghĩa topology: 1 cloud endpoint + nhiều server endpoints.

Cách 1 — Azure Portal
  1. 2.1Marketplace → search "Azure File Sync" → Create → Name: sss-hoatranlab-lab10 → Resource Group: rg-lab10-filesync → Southeast Asia
  2. 2.2Storage Sync Service → Sync groups → + Sync group → Name: sg-lab10
  3. 2.3Cloud endpoint: Storage account = stlab10sync → Azure File Share = lab10share → Create
Cách 2 — Azure CLI
Azure CLI
# Tạo Storage Sync Service
az storagesync create \
  --resource-group rg-lab10-filesync \
  --name sss-hoatranlab-lab10 \
  --location southeastasia

# Tạo Sync Group
az storagesync sync-group create \
  --resource-group rg-lab10-filesync \
  --storage-sync-service sss-hoatranlab-lab10 \
  --name sg-lab10

# Lấy storage account resource ID
SA_ID=$(az storage account show \
  --resource-group rg-lab10-filesync \
  --name stlab10sync \
  --query id --output tsv)

# Tạo Cloud Endpoint
az storagesync sync-group cloud-endpoint create \
  --resource-group rg-lab10-filesync \
  --storage-sync-service sss-hoatranlab-lab10 \
  --sync-group-name sg-lab10 \
  --name ce-lab10 \
  --storage-account $SA_ID \
  --azure-file-share-name lab10share
3

Chuẩn Bị Windows Server & Cài Azure File Sync Agent

Thực hiện các lệnh sau trong PowerShell (chạy as Administrator) trên Windows Server cần đồng bộ:

Cách 1 — Azure Portal (download agent)
  1. 3.1Truy cập aka.ms/afs/agent → Download StorageSyncAgent_WS2022.msi
  2. 3.2Chạy installer → Next → Accept → Install → Finish (wizard đăng ký server tự mở)
  3. 3.3Registration wizard → Sign in Azure → chọn Subscription, Resource Group, Storage Sync Service → Register
  4. 3.4Portal → Storage Sync Service → Registered servers → server xuất hiện với Status: Online
PowerShell (Windows Server)
PowerShell-CMD (Windows)— Run as Administrator
# Khởi tạo ổ đĩa dữ liệu S: (nếu dùng VM Azure)
# Mở Disk Management: diskmgmt.msc
# Format Disk 2 → NTFS, drive letter S:, label "Data"

# Tạo thư mục sync và thêm data test
New-Item -Type Directory -Path 'S:\lab10share' -Force
# Copy một số files vào thư mục
Copy-Item -Path 'C:\Windows\System32\drivers\etc\*' `
  -Destination 'S:\lab10share' -Recurse

# Tạo SMB share (optional - cho phép truy cập nội bộ)
New-SmbShare -Name 'lab10share' `
  -Path 'S:\lab10share' `
  -FullAccess 'Administrators' `
  -ReadAccess 'Everyone'

# Cài Az module để kiểm tra compatibility
Install-Module -Name Az.StorageSync -AllowClobber -Force -Scope CurrentUser

# Kiểm tra compatibility trước khi sync
Invoke-AzStorageSyncCompatibilityCheck -Path 'S:\lab10share'
4

Thêm Server Endpoint & Bật Cloud Tiering

Cách 1 — Azure Portal
  1. 4.1Storage Sync Service → Sync groups → sg-lab10 → Add server endpoint
  2. 4.2Registered server: chọn Windows Server vừa đăng ký → Path: S:\lab10share
  3. 4.3Cloud Tiering: Enabled → Volume free space: 20% → Cache duration: 30 days
  4. 4.4Offline Data Transfer: Disabled → Create → chờ sync health: Healthy (green)
  5. 4.5Theo dõi: Sync Group → Server Endpoint → Sync Activity để thấy tiến trình upload files
Cloud Tiering: Khi bật, file ít được truy cập sẽ tự động được chuyển lên Azure Files, chỉ còn file placeholder trên server. Khi user mở file → tự động tải về. Volume free space 20% = server luôn giữ ít nhất 20% dung lượng trống.
Cách 2 — Azure CLI
Azure CLI
# Xem registered servers
az storagesync registered-server list \
  --resource-group rg-lab10-filesync \
  --storage-sync-service sss-hoatranlab-lab10 \
  --output table

# Lấy server ID (từ output lệnh trên)
SERVER_ID=""

# Thêm server endpoint với cloud tiering
az storagesync sync-group server-endpoint create \
  --resource-group rg-lab10-filesync \
  --storage-sync-service sss-hoatranlab-lab10 \
  --sync-group-name sg-lab10 \
  --name se-lab10-server \
  --server-id $SERVER_ID \
  --server-local-path "S:\lab10share" \
  --cloud-tiering Enabled \
  --volume-free-space-percent 20 \
  --tier-files-older-than-days 30
5

Xác Minh Sync & Mount File Share

Sau khi sync hoàn thành, mount Azure File Share như ổ mạng và so sánh nội dung với server local.

PowerShell-CMD (Windows)— Chạy trên Windows Server
# Lấy storage account key để mount
$storageAccountName = "stlab10sync"
$storageAccountKey  = "YOUR_STORAGE_KEY"  # lấy từ Portal → Keys

# Mount Azure File Share thành ổ Z:
$connectTestResult = Test-NetConnection `
  -ComputerName "$storageAccountName.file.core.windows.net" `
  -Port 445

if ($connectTestResult.TcpTestSucceeded) {
    # Mount với -Persist để giữ sau reboot
    net use Z: "\\$storageAccountName.file.core.windows.net\lab10share" `
      /u:"localhost\$storageAccountName" $storageAccountKey /Persistent:Yes
    Write-Host "Mounted successfully as Z:" -ForegroundColor Green
} else {
    Write-Host "Port 445 blocked - check firewall" -ForegroundColor Red
}

# So sánh nội dung S: (server local) và Z: (Azure Files cloud)
$serverFiles = Get-ChildItem -Path 'S:\lab10share' -Recurse | Select-Object Name
$cloudFiles  = Get-ChildItem -Path 'Z:\' -Recurse | Select-Object Name

# Kiểm tra sự khác biệt
Compare-Object $serverFiles $cloudFiles -Property Name
Kết quả (Output)— So sánh thành công: không có sự khác biệt
# Nếu sync hoàn thành, Compare-Object trả về NOTHING (không có diff)
# Portal kiểm tra: Sync Group → Server Endpoint → Sync Activity
# Health: Healthy | Files synced: X files | Last sync: vài giây/phút trước

Drive Z: mounted as \\stlab10sync.file.core.windows.net\lab10share
Files on S:\lab10share : 12 items
Files on Z:\           : 12 items
Diff                   : (none) — sync complete

📊 Kết Quả Đầu Ra Lab 10

Storage Sync Service Online

sss-hoatranlab-lab10 hiển thị trong portal, Sync Group sg-lab10 active

Server đã đăng ký thành công

Registered Servers → Status: Online, Server OS version hiển thị

Sync Health: Healthy

Server Endpoint health indicator màu xanh, Last sync time hiển thị

Files đồng bộ lên Azure Files

Portal → File Share lab10share → có đủ files từ S:\lab10share

Cloud Tiering bật thành công

Volume free space policy 20% active, tiered files có icon cloud trên server

Ổ Z: mount thành công

net use Z: trả về OK, duyệt ổ Z: thấy đầy đủ files từ cloud

🧹 Dọn Dẹp Tài Nguyên

Azure CLI
# Unregister server trước (cần làm trên server hoặc qua portal)
# Portal: Storage Sync Service → Registered Servers → chọn server → Unregister

# Xóa toàn bộ resource group
az group delete \
  --name rg-lab10-filesync \
  --yes \
  --no-wait

# Unmount ổ Z: trên Windows Server
# net use Z: /delete

❓ Câu Hỏi Ôn Tập

1. Azure File Sync khác Azure Files thuần túy như thế nào? Khi nào cần dùng File Sync?

Gợi ý: Azure Files = cloud-only SMB share; File Sync = bi-directional sync giữa on-premises server và cloud, hỗ trợ offline access, cloud tiering — dùng khi có server hiện tại cần hybrid

2. Cloud Tiering hoạt động như thế nào? File tiered khác file thường ở điểm nào?

Gợi ý: File tiered = chỉ còn reparse point (placeholder) trên server, data thực ở cloud; khi access → agent tự recall về; icon có dấu cloud trong Explorer; dùng để giải phóng dung lượng local

3. Một Sync Group có thể có bao nhiêu cloud endpoint và bao nhiêu server endpoint?

Gợi ý: Đúng 1 cloud endpoint (1 Azure File Share), nhiều server endpoints (nhiều server/path) — đây là mô hình hub-spoke cho multi-branch

4. Tại sao cần chạy Invoke-AzStorageSyncCompatibilityCheck trước khi thêm server endpoint?

Gợi ý: Kiểm tra file system features không tương thích (reparse points, EFS, symbolic links, unsupported chars) — phát hiện trước tránh sync lỗi sau khi cấu hình

5. Nếu một file bị sửa đồng thời trên server và trên Azure Files, Azure File Sync xử lý conflict như thế nào?

Gợi ý: Last-write-wins policy — file được ghi sau sẽ thắng, phiên bản kia được đổi tên thành <filename>-<computername>-timestamp.<ext> để giữ cả 2

Lab 09: Azure Backup Thư viện Labs Lab 11: Azure Monitor & Alerts
Zalo