使用 Azure 檔案同步,將組織的檔案共用集中在 Azure 檔案儲存體服務中,同時保有內部部署檔案伺服器的彈性、效能及相容性。 Azure 檔案同步會將 Windows Server 轉換成 Azure 檔案共用的快速快取。 您可以使用 Windows Server 上可用的任何通訊協定來從本機存取資料,包括 SMB、NFS 和 FTPS。 您可以在世界各地,盡可能多地擁有您所需的快取數量。
如果您的 PSVersion 值小於 5.1.* (大部分的 Windows Server 2012 R2 全新安裝都會發生此類情況),您需要下載並安裝 Windows Management Framework (WMF) 5.1 以輕鬆升級。 可為 Windows Server 2012 R2 下載和安裝的適當套件為 Win8.1AndW2K12R2-KB*******-x64.msu。
至少一個支援的 Windows Server 執行個體與 Azure 檔案同步進行同步處理。如需 Windows Server 支援版本和建議系統資源的詳細資訊,請參閱 Windows 檔案伺服器考量。
選用:如果您想要搭配 Windows 伺服器容錯移轉叢集使用 Azure 檔案同步,必須先設定一般用途的檔案伺服器角色,才能在叢集中的每個節點上安裝 Azure 檔案同步代理程式。 如需如何在容錯移轉叢集上設定檔案伺服器一般用途角色的詳細資訊,請參閱 部署雙節點叢集檔案伺服器。
注意
Azure 檔案同步唯一支援的案例是使用叢集磁碟的 Windows Server 容錯移轉叢集。 請參閱 Azure 檔案同步的容錯移轉叢集。
PowerShell 5.1 或 PowerShell 6+。 您可以在任何支援的系統 (包括非 Windows 系統) 上使用 Az PowerShell 模組進行 Azure 檔案同步,不過,伺服器註冊 Cmdlet 一律須在您註冊的 Windows Server 執行個體上執行 (此動作可直接完成,或透過 PowerShell 遠端處理來完成)。 預設情況下,Windows Server 2016 及更新版本上隨附 PowerShell 5.1。 在 Windows Server 2012 R2 上,您可以查看 $PSVersionTable 物件的 PSVersion 屬性值,以確認您執行的至少是 PowerShell 5.1.*:
$PSVersionTable.PSVersion
如果您的 PSVersion 值小於 5.1.* (大部分的 Windows Server 2012 R2 全新安裝都會發生此類情況),您需要下載並安裝 Windows Management Framework (WMF) 5.1 以輕鬆升級。 可為 Windows Server 2012 R2 下載和安裝的適當套件為 Win8.1AndW2K12R2-KB*******-x64.msu。
如果您的 PSVersion 值小於 5.1.* (大部分的 Windows Server 2012 R2 全新安裝都會發生此類情況),您需要下載並安裝 Windows Management Framework (WMF) 5.1 以輕鬆升級。 可為 Windows Server 2012 R2 下載和安裝的適當套件為 Win8.1AndW2K12R2-KB*******-x64.msu。
在 [Internet Explorer 增強式安全性設定] 對話方塊中,針對 [系統管理員] 和 [使用者] 選取 [關閉]:
若要停用 [Internet Explorer 增強式安全性設定],請從提升權限的 PowerShell 工作階段中執行下列命令:
$installType = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\").InstallationType
# This step is not required for Server Core
if ($installType -ne "Server Core") {
# Disable Internet Explorer Enhanced Security Configuration
# for Administrators
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" -Name "IsInstalled" -Value 0 -Force
# Disable Internet Explorer Enhanced Security Configuration
# for Users
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" -Name "IsInstalled" -Value 0 -Force
# Force Internet Explorer closed, if open. This is required to fully apply the setting.
# Save any work you have open in the IE browser. This will not affect other browsers,
# including Microsoft Edge.
Stop-Process -Name iexplore -ErrorAction SilentlyContinue
}
$hostType = (Get-Host).Name
if ($installType -eq "Server Core" -or $hostType -eq "ServerRemoteHost") {
Connect-AzAccount -UseDeviceAuthentication
}
else {
Connect-AzAccount
}
# this variable holds the Azure region you want to deploy
# Azure File Sync into
$region = '<Az_Region>'
# Check to ensure Azure File Sync is available in the selected Azure
# region.
$regions = @()
Get-AzLocation | ForEach-Object {
if ($_.Providers -contains "Microsoft.StorageSync") {
$regions += $_.Location
}
}
if ($regions -notcontains $region) {
throw [System.Exception]::new("Azure File Sync is either not available in the selected Azure Region or the region is mistyped.")
}
# the resource group to deploy the Storage Sync Service into
$resourceGroup = '<RG_Name>'
# Check to ensure resource group exists and create it if doesn't
$resourceGroups = @()
Get-AzResourceGroup | ForEach-Object {
$resourceGroups += $_.ResourceGroupName
}
if ($resourceGroups -notcontains $resourceGroup) {
New-AzResourceGroup -Name $resourceGroup -Location $region
}
$storageSyncName = "<my_storage_sync_service>"
$storageSync = New-AzStorageSyncService -ResourceGroupName $resourceGroup -Name $storageSyncName -Location $region
依照 Azure 入口網站或 PowerShell 的指示操作。
安裝 Azure 檔案同步代理程式
Azure 檔案同步代理程式是可下載的套件,可讓 Windows Server 和 Azure 檔案共用進行同步處理。
# Gather the OS version
$osver = [System.Environment]::OSVersion.Version
# Download the appropriate version of the Azure File Sync agent for your OS.
if ($osver.Equals([System.Version]::new(10, 0, 20348, 0))) {
Invoke-WebRequest `
-Uri https://aka.ms/afs/agent/Server2022 `
-OutFile "StorageSyncAgent.msi"
} elseif ($osver.Equals([System.Version]::new(10, 0, 17763, 0))) {
Invoke-WebRequest `
-Uri https://aka.ms/afs/agent/Server2019 `
-OutFile "StorageSyncAgent.msi"
} elseif ($osver.Equals([System.Version]::new(10, 0, 14393, 0))) {
Invoke-WebRequest `
-Uri https://aka.ms/afs/agent/Server2016 `
-OutFile "StorageSyncAgent.msi"
} elseif ($osver.Equals([System.Version]::new(6, 3, 9600, 0))) {
Invoke-WebRequest `
-Uri https://aka.ms/afs/agent/Server2012R2 `
-OutFile "StorageSyncAgent.msi"
} else {
throw [System.PlatformNotSupportedException]::new("Azure File Sync is only supported on Windows Server 2012 R2, Windows Server 2016, Windows Server 2019 and Windows Server 2022")
}
# Install the MSI. Start-Process is used to PowerShell blocks until the operation is complete.
# Note that the installer currently forces all PowerShell sessions closed - this is a known issue.
Start-Process -FilePath "StorageSyncAgent.msi" -ArgumentList "/quiet" -Wait
# Note that this cmdlet will need to be run in a new session based on the above comment.
# You may remove the temp folder containing the MSI and the EXE installer
Remove-Item -Path ".\StorageSyncAgent.msi" -Recurse -Force
依照 Azure 入口網站或 PowerShell 的指示操作。
向儲存體同步服務註冊 Windows Server
向儲存體同步服務註冊 Windows Server 會在您的伺服器 (或叢集) 與儲存體同步服務之間建立信任關係。 一部伺服器只能向一個儲存體同步服務註冊,但可以與其他關聯至相同儲存體同步服務的伺服器和 Azure 檔案共用同步。
注意
伺服器註冊會使用您的 Azure 認證來建立儲存體同步服務和 Windows Server 之間的信任關係;但是,之後伺服器會建立並使用自有的身分識別,只要伺服器維持註冊狀態,且目前的共用存取簽章權杖 (儲存體 SAS) 有效,此身分識別就會是有效的。 如果伺服器未註冊,新的 SAS 權杖就無法發行至伺服器,並會因此移除伺服器存取您 Azure 檔案共用的能力,進而停止任何同步。
$serverEndpointPath = "<your-server-endpoint-path>"
$cloudTieringDesired = $true
$volumeFreeSpacePercentage = <your-volume-free-space>
# Optional property. Choose from: [NamespaceOnly] default when cloud tiering is enabled. [NamespaceThenModifiedFiles] default when cloud tiering is disabled. [AvoidTieredFiles] only available when cloud tiering is disabled.
$initialDownloadPolicy = "NamespaceOnly"
$initialUploadPolicy = "Merge"
# Optional property. Choose from: [Merge] default for all new server endpoints. Content from the server and the cloud merge. This is the right choice if one location is empty or other server endpoints already exist in the sync group. [ServerAuthoritative] This is the right choice when you seeded the Azure file share (e.g. with Data Box) AND you are connecting the server location you seeded from. This enables you to catch up the Azure file share with the changes that happened on the local server since the seeding.
if ($cloudTieringDesired) {
# Ensure endpoint path is not the system volume
$directoryRoot = [System.IO.Directory]::GetDirectoryRoot($serverEndpointPath)
$osVolume = "$($env:SystemDrive)\"
if ($directoryRoot -eq $osVolume) {
throw [System.Exception]::new("Cloud tiering cannot be enabled on the system volume")
}
# Create server endpoint
New-AzStorageSyncServerEndpoint `
-Name $registeredServer.FriendlyName `
-SyncGroup $syncGroup `
-ServerResourceId $registeredServer.ResourceId `
-ServerLocalPath $serverEndpointPath `
-CloudTiering `
-VolumeFreeSpacePercent $volumeFreeSpacePercentage `
-InitialDownloadPolicy $initialDownloadPolicy `
-InitialUploadPolicy $initialUploadPolicy
} else {
# Create server endpoint
New-AzStorageSyncServerEndpoint `
-Name $registeredServer.FriendlyName `
-SyncGroup $syncGroup `
-ServerResourceId $registeredServer.ResourceId `
-ServerLocalPath $serverEndpointPath `
-InitialDownloadPolicy $initialDownloadPolicy
}