Lý Thuyết Cốt Lõi
1. Azure Files vs Azure Blob Storage — Khi Nào Dùng Gì?
Azure Files và Azure Blob Storage đều là dịch vụ lưu trữ object trên Azure, nhưng phục vụ các use-case khác nhau. Hiểu rõ sự khác biệt là nền tảng để chọn đúng dịch vụ.
| Tiêu chí | Azure Files | Azure Blob Storage |
|---|---|---|
| Giao thức | SMB 3.0/2.1, NFS 4.1, REST API | REST API, HTTPS |
| Cấu trúc dữ liệu | Hệ thống file (thư mục, file) | Flat object store (containers, blobs) |
| Mount/map | Mount như network drive (Windows/Linux/macOS) | Truy cập qua SDK/REST, không mount trực tiếp |
| Use-case | Lift & shift app dùng file share, home directories, shared config | Backup, media, data lake, static web, big data |
| Dung lượng tối đa | Standard: 5 TiB/share; Premium: 100 TiB/share | Lên tới petabytes/account |
| Performance tiers | Standard (HDD), Premium (SSD) | Hot, Cool, Cold, Archive |
2. Quản Lý Azure File Shares
Azure Files cung cấp file shares được quản lý đầy đủ trên cloud, có thể truy cập đồng thời từ nhiều máy tính qua giao thức SMB hoặc NFS.
- • Tạo trong Storage Account (General-purpose v2 hoặc FileStorage)
- • Đặt quota (dung lượng tối đa) để kiểm soát chi phí
- • SMB: port 445 phải mở từ client đến Azure
- • NFS: chỉ hỗ trợ trên Premium FileStorage, cần VNet integration
- • Storage Account Key: toàn quyền, dùng cho admin
- • Azure AD Kerberos: xác thực theo identity cho Windows clients
- • On-prem AD DS: join domain server truy cập qua SMB với AD credentials
- • Mã hóa khi truyền: TLS 1.2 bắt buộc khi dùng SMB 3.0
- • Dùng lệnh
net usehoặc PowerShellNew-PSDrive - • Portal cung cấp script mount sẵn cho Windows/Linux/macOS
- • Lưu credentials vào Windows Credential Manager để tự động mount khi khởi động
- • Cài
cifs-utilspackage - • Mount bằng lệnh
mount -t cifsvới credentials file - • Thêm vào
/etc/fstabđể mount tự động khi boot
3. Azure File Share Snapshots
Snapshot là bản sao read-only của file share tại một thời điểm cụ thể. Snapshot được lưu trữ incremental — chỉ lưu thay đổi so với snapshot trước, tiết kiệm chi phí.
Số snapshot tối đa / file share
Thời gian lưu tối đa một snapshot
Chỉ lưu delta thay đổi, không nhân bản toàn bộ
- • Browse: duyệt nội dung snapshot qua Portal hoặc mount path đặc biệt
- • Restore file: phục hồi file/thư mục đơn lẻ từ snapshot về share hiện tại
- • Restore share: tạo share mới từ snapshot (không overwrite live share)
- • Delete: xóa snapshot không ảnh hưởng share gốc
- • Snapshot tích hợp với tính năng "Previous Versions" của Windows Explorer
- • Người dùng cuối có thể tự phục hồi file mà không cần IT
- • Chuột phải file → Properties → Previous Versions → chọn phiên bản cần khôi phục
- • Lý tưởng cho môi trường doanh nghiệp VN: giảm tải IT helpdesk
4. Azure File Sync — Kiến Trúc & Thành Phần
Azure File Sync biến Windows Server thành cache nhanh của Azure file share. Dữ liệu ít dùng tự động được cloud tiering lên Azure, tiết kiệm không gian on-premises mà vẫn truy cập được như file local.
Resource Azure cấp cao nhất của File Sync. Được tạo trong một Resource Group cụ thể. Một subscription có thể có nhiều Storage Sync Service. Tất cả sync groups và registered servers thuộc về một Storage Sync Service.
Định nghĩa topology đồng bộ hóa. Mỗi sync group gồm 1 cloud endpoint và từ 1 đến nhiều server endpoints. Tất cả endpoints trong một sync group luôn nhất quán với nhau (bi-directional sync).
Trỏ đến một Azure file share cụ thể. Mỗi Azure file share chỉ có thể là cloud endpoint của một sync group duy nhất. Thay đổi trực tiếp trên Azure file share sẽ được phát hiện và đồng bộ xuống server endpoints trong vòng 24 giờ (change detection job).
Đại diện cho một vị trí cụ thể trên Windows Server đã đăng ký, ví dụ D:\SyncFolder. Một server có thể có nhiều server endpoints thuộc các sync groups khác nhau, miễn là các path không chồng nhau.
Cloud tiering là tính năng tùy chọn cho phép các file ít truy cập được thay thế bằng stub file (placeholder) chỉ vài KB trên server, trong khi dữ liệu thực được lưu trên Azure.
- • Volume free space policy: duy trì % free space trên volume (VD: giữ 20% free → tier file cũ nhất khi volume gần đầy)
- • Date policy: tier file không được truy cập trong N ngày (VD: 30 ngày)
- • Khi mở stub file → Azure File Sync tự động tải dữ liệu từ Azure
- • Recall trong suốt với người dùng (giống file local)
- • Có thể recall toàn bộ share bằng PowerShell khi cần offline
Bài Tập Thực Hành (Lab)
Tạo Storage Account và Azure File Share
# Tạo Resource Group
az group create \
--name rg-az104-m19 \
--location southeastasia \
--tags Module=19 Course=AZ-104 Lab=FileSync
# Tạo Storage Account (General Purpose v2)
# Tên storage account phải unique toàn cầu, viết thường, 3-24 ký tự
STORAGE_NAME="staz104m19$(date +%s | tail -c 6)"
echo "Storage Account name: $STORAGE_NAME"
az storage account create \
--name $STORAGE_NAME \
--resource-group rg-az104-m19 \
--location southeastasia \
--sku Standard_LRS \
--kind StorageV2 \
--https-only true \
--min-tls-version TLS1_2 \
--allow-blob-public-access false
# Lấy connection string
CONN_STR=$(az storage account show-connection-string \
--name $STORAGE_NAME \
--resource-group rg-az104-m19 \
--query connectionString -o tsv)
# Tạo Azure File Share với quota 50 GiB
az storage share create \
--name "hoatranlab-fileshare" \
--quota 50 \
--connection-string "$CONN_STR"
# Tạo thư mục con trong file share
az storage directory create \
--name "documents" \
--share-name "hoatranlab-fileshare" \
--connection-string "$CONN_STR"
az storage directory create \
--name "projects" \
--share-name "hoatranlab-fileshare" \
--connection-string "$CONN_STR"
# Upload file test
echo "Azure Files Lab Test - $(date)" > /tmp/test-upload.txt
az storage file upload \
--source /tmp/test-upload.txt \
--share-name "hoatranlab-fileshare" \
--path "documents/test-upload.txt" \
--connection-string "$CONN_STR"
echo "File share created successfully!"
az storage share show --name "hoatranlab-fileshare" \
--connection-string "$CONN_STR" \
--query "{name:name, quota:properties.quota, usage:properties.shareUsageBytes}" -o table
Mount Azure File Share trên Linux (Ubuntu/RHEL)
# === Chạy trên Linux VM hoặc lấy script từ Portal ===
# Portal → Storage Account → File shares → hoatranlab-fileshare → Connect → Linux
# Thay các biến sau bằng giá trị thực của bạn
STORAGE_ACCOUNT_NAME="staz104m19XXXXXX" # thay bằng tên thực
SHARE_NAME="hoatranlab-fileshare"
STORAGE_KEY=$(az storage account keys list \
--account-name $STORAGE_ACCOUNT_NAME \
--resource-group rg-az104-m19 \
--query "[0].value" -o tsv)
# Cài cifs-utils (Ubuntu/Debian)
sudo apt-get update && sudo apt-get install -y cifs-utils
# Tạo mount point
sudo mkdir -p /mnt/hoatranlab-share
# Tạo credentials file (bảo mật hơn dùng trực tiếp trên command line)
sudo bash -c "cat > /etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred << EOF
username=${STORAGE_ACCOUNT_NAME}
password=${STORAGE_KEY}
EOF"
sudo chmod 600 /etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred
# Mount file share
sudo mount -t cifs \
//${STORAGE_ACCOUNT_NAME}.file.core.windows.net/${SHARE_NAME} \
/mnt/hoatranlab-share \
-o credentials=/etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred,\
serverino,nosharesock,actimeo=30,vers=3.0,file_mode=0777,dir_mode=0777
# Kiểm tra mount thành công
df -h /mnt/hoatranlab-share
ls -la /mnt/hoatranlab-share/
# Ghi file test để xác nhận read/write
echo "Written from Linux VM at $(date)" | sudo tee /mnt/hoatranlab-share/documents/linux-test.txt
# Thêm vào /etc/fstab để auto-mount khi reboot
echo "//${STORAGE_ACCOUNT_NAME}.file.core.windows.net/${SHARE_NAME} /mnt/hoatranlab-share cifs credentials=/etc/smbcredentials/${STORAGE_ACCOUNT_NAME}.cred,serverino,nosharesock,actimeo=30,vers=3.0,file_mode=0777,dir_mode=0777,_netdev 0 0" | sudo tee -a /etc/fstab
Tạo Snapshot và Phục hồi File từ Snapshot
STORAGE_NAME="staz104m19XXXXXX" # thay bằng tên thực
CONN_STR=$(az storage account show-connection-string \
--name $STORAGE_NAME \
--resource-group rg-az104-m19 \
--query connectionString -o tsv)
# Upload file "quan trọng" trước khi tạo snapshot
echo "Dữ liệu quan trọng - Version 1.0 - $(date)" > /tmp/important.txt
az storage file upload \
--source /tmp/important.txt \
--share-name "hoatranlab-fileshare" \
--path "documents/important.txt" \
--connection-string "$CONN_STR"
# TẠO SNAPSHOT (point-in-time backup)
SNAPSHOT_TIME=$(az storage share snapshot \
--name "hoatranlab-fileshare" \
--connection-string "$CONN_STR" \
--query snapshot -o tsv)
echo "Snapshot created at: $SNAPSHOT_TIME"
# Mô phỏng tai nạn: xóa file quan trọng
az storage file delete \
--share-name "hoatranlab-fileshare" \
--path "documents/important.txt" \
--connection-string "$CONN_STR"
echo "File deleted (simulating accident)!"
# Xác nhận file đã bị xóa
az storage file exists \
--share-name "hoatranlab-fileshare" \
--path "documents/important.txt" \
--connection-string "$CONN_STR"
# PHỤC HỒI file từ snapshot
az storage file copy start \
--source-share "hoatranlab-fileshare" \
--source-path "documents/important.txt" \
--source-snapshot "$SNAPSHOT_TIME" \
--destination-share "hoatranlab-fileshare" \
--destination-path "documents/important.txt" \
--connection-string "$CONN_STR"
echo "File restored from snapshot!"
# Liệt kê tất cả snapshots của share
az storage share list \
--connection-string "$CONN_STR" \
--include-snapshots \
--query "[?name=='hoatranlab-fileshare'].[name,snapshot]" \
--output table
Triển khai Storage Sync Service và cấu hình Azure File Sync
# Tạo Storage Sync Service
az storagesync create \
--resource-group rg-az104-m19 \
--storage-sync-service-name "sss-hoatranlab-m19" \
--location southeastasia
# Tạo Sync Group
az storagesync sync-group create \
--resource-group rg-az104-m19 \
--storage-sync-service-name "sss-hoatranlab-m19" \
--sync-group-name "sg-hoatranlab-prod"
# Tạo file share riêng cho File Sync (nên dùng share khác với share thông thường)
STORAGE_NAME="staz104m19XXXXXX" # thay bằng tên thực
CONN_STR=$(az storage account show-connection-string \
--name $STORAGE_NAME \
--resource-group rg-az104-m19 \
--query connectionString -o tsv)
az storage share create \
--name "filesync-cloud-endpoint" \
--quota 100 \
--connection-string "$CONN_STR"
# Lấy Resource ID của storage account
STORAGE_ID=$(az storage account show \
--name $STORAGE_NAME \
--resource-group rg-az104-m19 \
--query id -o tsv)
# Tạo Cloud Endpoint
az storagesync sync-group cloud-endpoint create \
--resource-group rg-az104-m19 \
--storage-sync-service-name "sss-hoatranlab-m19" \
--sync-group-name "sg-hoatranlab-prod" \
--name "cloud-ep-01" \
--storage-account-resource-id "$STORAGE_ID" \
--azure-file-share-name "filesync-cloud-endpoint"
echo "=== Cloud Endpoint created ==="
echo "Next: Install Azure File Sync agent on Windows Server,"
echo "then register server and create Server Endpoint via Portal."
echo ""
echo "Agent download: https://aka.ms/afs/agent"
echo ""
echo "PowerShell commands to run ON THE WINDOWS SERVER after agent install:"
echo "Register-AzStorageSyncServer -ResourceGroupName rg-az104-m19 -StorageSyncServiceName sss-hoatranlab-m19"
# Chạy trên Windows Server đã cài Azure File Sync Agent
# Import module
Import-Module "C:\Program Files\Azure\StorageSyncAgent\StorageSync.Management.PowerShell.Cmdlets.dll"
# Đăng nhập Azure
Connect-AzAccount
# Đăng ký Windows Server với Storage Sync Service
Register-AzStorageSyncServer `
-ResourceGroupName "rg-az104-m19" `
-StorageSyncServiceName "sss-hoatranlab-m19"
# Sau khi đăng ký, tạo Server Endpoint qua CLI hoặc Portal
# Thay SERVER_ENDPOINT_ID bằng ID server vừa đăng ký (lấy từ Portal)
$serverEndpointPath = "D:\SyncData"
New-Item -ItemType Directory -Force -Path $serverEndpointPath
# Kiểm tra trạng thái đồng bộ
Get-StorageSyncServer
Invoke-AzStorageSyncCompatibilityCheck -Path $serverEndpointPath
Cleanup — Dọn dẹp tài nguyên
# Nếu đã có server endpoint và cloud endpoint, xóa theo thứ tự:
# 1. Xóa server endpoint trước (qua Portal hoặc CLI)
# az storagesync sync-group server-endpoint delete ...
# 2. Xóa cloud endpoint
az storagesync sync-group cloud-endpoint delete \
--resource-group rg-az104-m19 \
--storage-sync-service-name "sss-hoatranlab-m19" \
--sync-group-name "sg-hoatranlab-prod" \
--name "cloud-ep-01" \
--yes
# 3. Xóa sync group
az storagesync sync-group delete \
--resource-group rg-az104-m19 \
--storage-sync-service-name "sss-hoatranlab-m19" \
--name "sg-hoatranlab-prod" \
--yes
# 4. Xóa Storage Sync Service
az storagesync delete \
--resource-group rg-az104-m19 \
--storage-sync-service-name "sss-hoatranlab-m19" \
--yes
# 5. Xóa toàn bộ Resource Group (xóa storage account + file shares + snapshots)
az group delete --name rg-az104-m19 --yes --no-wait
echo "Cleanup initiated. Resources will be deleted in background."
Kết Quả Đầu Ra
Chọn đúng dịch vụ lưu trữ cho từng use-case: file share mount vs object storage
Tạo file share với quota, tạo thư mục, upload file qua CLI và Portal
Mount qua SMB với credentials file, cấu hình auto-mount khi reboot qua /etc/fstab
Tạo snapshot point-in-time, phục hồi file đơn lẻ từ snapshot về live share
Tạo Storage Sync Service, Sync Group, Cloud Endpoint và hiểu quy trình đăng ký server
Cấu hình volume free space policy và date policy, hiểu cơ chế recall stub file tự động
Ứng Dụng Thực Tế
Tình huống 1: Công ty kế toán — Di chuyển file server lên cloud
Công ty kế toán tại TP.HCM với 150 nhân viên đang dùng Windows File Server on-premises 20TB, chi phí bảo trì cao, backup không đáng tin cậy. Cần di chuyển lên cloud với downtime tối thiểu.
Triển khai Azure File Sync trên file server hiện tại. Đồng bộ toàn bộ 20TB lên Azure file share (sync ban đầu). Bật cloud tiering: giữ 20% free space, tier dữ liệu >90 ngày không truy cập. Server on-prem trở thành cache nhanh.
Cài Azure File Sync agent trên Windows Server 2019. Tạo Storage Sync Service region Southeast Asia (để đảm bảo data residency VN). Snapshot daily lúc 23:00 qua Azure Backup policy. Nhân viên không thay đổi workflow — vẫn dùng \\server\share như cũ.
Giảm 60% dung lượng on-prem nhờ cloud tiering. Backup tự động trên Azure — không còn rủi ro mất dữ liệu. Tốc độ truy cập dữ liệu "hot" không giảm vì vẫn từ cache local. Chi phí lưu trữ giảm 40% so với SAN on-premises.
Tình huống 2: Chuỗi phòng khám — Chia sẻ dữ liệu đa chi nhánh
Chuỗi 8 phòng khám tại Hà Nội và TP.HCM cần chia sẻ template tài liệu y tế, form bệnh nhân, protocol điều trị giữa các chi nhánh. Dữ liệu phải đồng nhất và cập nhật real-time.
Một Azure file share trung tâm cho tài liệu chung. Azure File Sync với 8 server endpoints (mỗi chi nhánh một Windows Server). Mọi thay đổi tại chi nhánh HN đồng bộ xuống 7 chi nhánh còn lại trong vòng vài phút.
Snapshot tự động mỗi 4 giờ để phục hồi nếu có sai sót. Cloud tiering tắt cho folder template (luôn giữ local để truy cập nhanh). Azure AD Kerberos authentication cho bác sĩ đăng nhập bằng M365 account. Tag DataClassification=Medical trên share.
Nhất quán tài liệu 100% giữa 8 chi nhánh. Bác sĩ mới onboard nhận đúng phiên bản protocol mới nhất. Khi cập nhật form → 8 chi nhánh đều có ngay, không cần gửi email đính kèm file. Compliance HIPAA-ready với audit trail đầy đủ.
Tình huống 3: Studio sản xuất nội dung — Lift & Shift workload NAS
Studio quảng cáo tại Hà Nội đang dùng NAS lưu raw footage video, project file After Effects, Premiere. NAS gần đầy 80TB, cần mở rộng nhanh mà không mua thêm phần cứng.
Azure Files Premium (SSD) cho project đang active (đảm bảo IOPS cao cho render). Azure Files Standard cho archive project hoàn thành. Azure File Sync với cloud tiering: project >6 tháng tự động tier lên cloud, giải phóng local SSD cho project mới.
Premium FileStorage account cho share "active-projects" (100 TiB quota). Standard storage account cho share "archive". File Sync agent trên render farm Windows Server. Snapshot daily trước render session. NFS 4.1 mount trên Linux render nodes.
Mở rộng storage không giới hạn mà không mua NAS mới. Render speed không giảm nhờ Premium SSD tier. Project archive vẫn accessible — mở stub file là tự động recall từ Azure. Chi phí chỉ trả theo dung lượng thực dùng.