使用 Azure 文件同步,即可将组织的文件共享集中在 Azure 文件中,同时又不失本地文件服务器的灵活性、性能和兼容性。 Azure 文件同步可将 Windows Server 转换为 Azure 文件共享的快速缓存。 可以使用 Windows Server 上可用的任意协议本地访问数据,包括 SMB、NFS 和 FTPS。 并且可以根据需要在世界各地具有多个缓存。
至少有一个受支持的 Windows Server 实例与 Azure 文件同步进行同步。有关受支持的 Windows Server 版本和建议的系统资源的详细信息,请参阅 Windows 文件服务器注意事项。
可选:如果打算对 Windows Server 故障转移群集使用 Azure 文件同步,则必须先配置“通用文件服务器”角色,然后再在群集中的每个节点上安装 Azure 文件同步代理。 有关如何在故障转移集群上配置“通用文件服务器”角色的详细信息,请参阅部署双节点群集文件服务器。
注意
Azure 文件同步支持的唯一场景是使用群集磁盘的 Windows Server 故障转移群集。 有关 Azure 文件同步,请参阅故障转移群集。
尽管可以使用 Azure 门户进行云管理,但高级注册服务器功能是通过 PowerShell cmdlet 提供的,这些 cmdlet 预期在 PowerShell 5.1 或 PowerShell 6+ 中运行于本地。 Windows Server 2016 及更高版本默认提供 PowerShell 5.1。 在 Windows Server 2012 R2 上,可通过查看 $PSVersionTable 对象的“PSVersion”属性值来验证是否正在运行 PowerShell 5.1.* 或以上版本:
$PSVersionTable.PSVersion
与 Windows Server 2012 R2 的全新安装一样,如果你的 PSVersion 值低于 5.1.*,可通过下载并安装 Windows Management Framework (WMF) 5.1 进行升级。 需下载和安装的 Windows Server 2012 R2 的相应包为 Win8.1AndW2K12R2-KB*******-x64.msu。
至少有一个受支持的 Windows Server 实例与 Azure 文件同步进行同步。有关受支持的 Windows Server 版本和建议的系统资源的详细信息,请参阅 Windows 文件服务器注意事项。
可选:如果打算对 Windows Server 故障转移群集使用 Azure 文件同步,则必须先配置“通用文件服务器”角色,然后再在群集中的每个节点上安装 Azure 文件同步代理。 有关如何在故障转移集群上配置“通用文件服务器”角色的详细信息,请参阅部署双节点群集文件服务器。
注意
Azure 文件同步支持的唯一场景是使用群集磁盘的 Windows Server 故障转移群集。 有关 Azure 文件同步,请参阅故障转移群集。
PowerShell 5.1 或 PowerShell 6+。 可以在任何受支持的系统(包括非 Windows 系统)上使用 Azure 文件同步的 Az PowerShell 模块,但服务器注册 cmdlet 必须始终在要注册的 Windows 服务器实例上运行(这可以直接完成或通过 PowerShell 远程完成)。 Windows Server 2016 及更高版本默认提供 PowerShell 5.1。 在 Windows Server 2012 R2 上,可通过查看 $PSVersionTable 对象的“PSVersion”属性值来验证是否正在运行 PowerShell 5.1.* 或以上版本:
$PSVersionTable.PSVersion
与 Windows Server 2012 R2 的全新安装一样,如果你的 PSVersion 值低于 5.1.*,可通过下载并安装 Windows Management Framework (WMF) 5.1 进行升级。 需下载和安装的 Windows Server 2012 R2 的相应包为 Win8.1AndW2K12R2-KB*******-x64.msu。
The installed extension 'storagesync' is experimental and not covered by customer support. Please use with discretion.
尽管可以使用 Azure CLI 进行云管理,但高级注册服务器功能是通过 PowerShell cmdlet 提供的,这些 cmdlet 预期在 PowerShell 5.1 或 PowerShell 6+ 中运行于本地。 Windows Server 2016 及更高版本默认提供 PowerShell 5.1。 在 Windows Server 2012 R2 上,可通过查看 $PSVersionTable 对象的“PSVersion”属性值来验证是否正在运行 PowerShell 5.1.* 或以上版本:
$PSVersionTable.PSVersion
与 Windows Server 2012 R2 的全新安装一样,如果你的 PSVersion 值低于 5.1.*,可通过下载并安装 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 -Environment AzureChinaCloud
}
# 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 服务器与 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, and Windows Server 2019")
}
# 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
}