本文介绍如何将邻近放置组中运行的虚拟机复制、故障转移和故障恢复到次要区域。
邻近放置组是一种 Azure 虚拟机逻辑分组功能,可用于降低与应用程序关联的 VM 间网络延迟。 当 VM 部署在相同的邻近放置组中时,它们彼此的物理位置会尽可能接近。 邻近放置组尤其有助于满足对延迟敏感的工作负载的要求。
邻近放置组中的灾难恢复
在典型场景中,你可能会在邻近放置组中运行虚拟机,以避免在应用程序的各个层之间出现网络延迟。 虽然这样可以最大程度减少应用程序的网络延迟,但建议使用 Site Recovery 保护这些应用程序免受任何区域级别故障。 发生故障转移时,Site Recovery 将数据从一个 Azure 区域复制到另一个 Azure 区域,并调出灾难恢复区域中的计算机。
注意事项
- 最佳做法是将虚拟机故障转移/故障恢复到邻近放置组。 但是,如果 VM 在故障转移/故障恢复期间无法在邻近放置组中调出,则故障转移/故障恢复仍将发生,并且系统将在邻近放置组之外创建虚拟机。
- 如果将某个可用性集固定到邻近放置组,且可用性集中的 VM 在故障转移/故障恢复时具有分配约束,则系统将在可用性集和邻近放置组之外创建虚拟机。
- 非托管磁盘不支持适用于邻近放置组的 Site Recovery。
Note: Azure Site Recovery 不支持从 Hyper-V 的托管磁盘到 Azure 方案的故障回复。 因此,不支持从 Azure 中的邻近放置组到 Hyper-V 的故障回复。
通过门户为邻近组中的 Vm 设置灾难恢复
Azure 到 Azure 通过门户
你可以选择通过 "VM 灾难恢复" 页启用虚拟机的复制,或转到预先创建的保管库并导航到 "Site Recovery" 部分,然后启用复制。 让我们看看如何通过这两种方法在 PPG 内为 Vm 设置 Site Recovery:
-
如何在 DR 区域中选择 PPG,同时通过 IaaS VM DR 边栏选项卡启用复制:
- 请参阅虚拟机。 在左侧边栏选项卡上的 "操作" 下,选择 "灾难恢复"
- 在 "基本信息" 选项卡中,选择要将 VM 复制到的 DR 区域。 中转到 "高级设置"
- 在此处,可以看到 VM 的邻近度放置组,以及在 DR 区域中选择 PPG 的选项。 如果选择使用此默认选项,Site Recovery 还可以选择使用它为你创建的新的邻近位置组。 你可以选择所需的邻近位置组,然后再进入 "查看 + 开始复制",最后启用复制。
-
如何在 DR 区域中选择 PPG,同时通过保管库边栏选项卡启用复制:
- 中转到恢复服务保管库,并中转到 "Site Recovery" 选项卡
- 单击 "+ Enable Site Recovery",然后在 Azure 虚拟机下选择 "1:启用复制" (,因为你希望复制 Azure VM)
- 在 "源" 选项卡中填写必填字段,然后单击 "下一步"
- 在 "虚拟机" 选项卡中选择要为其启用复制的 Vm 列表,并单击 "下一步"
- 在此处,可以看到用于在 DR 区域中选择 PPG 的选项。 如果选择使用此默认选项,Site Recovery 还将为你提供使用它为你创建的新 PPG 的选项。 可以随意选择所需的 PPG,然后继续启用复制。
请注意,在为 VM 启用复制后,可以轻松更新 DR 区域中的 PPG 选择。
- 请先前往虚拟机,然后在 "操作" 下,选择 "灾难恢复",然后在左侧边栏选项卡
- 中转到 "计算和网络" 边栏选项卡,并单击页面顶部的 "编辑"
- 你可以看到用于编辑多个目标设置的选项,包括目标 PPG。 选择要将 VM 故障转移到的 PPG,然后单击 "保存"。
通过门户将 VMware 到 Azure
为 VM 启用复制后,可以设置目标 VM 的邻近位置组。 请确保根据你的要求在目标区域中单独创建 PPG。 然后,在为 VM 启用复制后,可以轻松地在 DR 区域中更新 PPG 选择。
-
从保管库中选择虚拟机,并在左侧边栏选项卡上的 "操作" 下选择 "灾难恢复"
-
中转到 "计算和网络" 边栏选项卡,并单击页面顶部的 "编辑"
-
你可以看到用于编辑多个目标设置的选项,包括目标 PPG。 选择要将 VM 故障转移到的 PPG,然后单击 "保存"。
通过门户将 hyper-v 到 Azure
为 VM 启用复制后,可以设置目标 VM 的邻近位置组。 请确保根据你的要求在目标区域中单独创建 PPG。 然后,在为 VM 启用复制后,可以轻松地在 DR 区域中更新 PPG 选择。
-
从保管库中选择虚拟机,并在左侧边栏选项卡上的 "操作" 下选择 "灾难恢复"
-
中转到 "计算和网络" 边栏选项卡,并单击页面顶部的 "编辑"
-
你可以看到用于编辑多个目标设置的选项,包括目标 PPG。 选择要将 VM 故障转移到的 PPG,然后单击 "保存"。
通过 PowerShell 为邻近位置组中的 Vm 设置灾难恢复
先决条件
-
确保已有 Azure PowerShell Az 模块。 如需进安装或升级 Azure PowerShell,请遵循此安装和配置 Azure PowerShell 指南。
-
最小的 Azure PowerShell Az 版本应为 4.1.0。 若要检查当前版本,请使用以下命令 -
Get-InstalledModule -Name Az
为邻近放置组中的虚拟机设置 Site Recovery
Note: 确保你随时可以使用目标邻近放置组的唯一 ID。 如果要创建新的邻近放置组,请查看此处的命令;如果使用的是现有邻近放置组,请使用此处的命令。
Azure 到 Azure
- 登录到 Azure 帐户并设置订阅。
- 按此处所述获取你计划复制的虚拟机的详细信息。
- 创建恢复服务保管库并设置保管库上下文。
- 准备保管库以开始复制虚拟机。 这涉及到为主区域和恢复区域创建 service fabric 对象。
- 为主结构和恢复结构创建 Site Recovery 保护容器。
- 创建复制策略。
- 按照此处所述,使用这些步骤创建主保护容器和恢复保护容器之间的保护容器映射,以及用于故障恢复的保护容器映射。
- 通过这些步骤创建缓存存储帐户。
- 按照此处所述,创建所需的网络映射。
- 若要复制包含托管磁盘的 Azure 虚拟机,请使用以下 PowerShell cmdlet:
#Get the resource group that the virtual machine must be created in when failed over.
$RecoveryRG = Get-AzResourceGroup -Name "a2ademorecoveryrg" -Location "West US 2"
#Specify replication properties for each disk of the VM that is to be replicated (create disk replication configuration)
#Make sure to replace the variables $OSdiskName with OS disk name.
#OS Disk
$OSdisk = Get-AzDisk -DiskName $OSdiskName -ResourceGroupName "A2AdemoRG"
$OSdiskId = $OSdisk.Id
$RecoveryOSDiskAccountType = $OSdisk.Sku.Name
$RecoveryReplicaDiskAccountType = $OSdisk.Sku.Name
$OSDiskReplicationConfig = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -ManagedDisk -LogStorageAccountId $EastUSCacheStorageAccount.Id -DiskId $OSdiskId -RecoveryResourceGroupId $RecoveryRG.ResourceId -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType -RecoveryTargetDiskAccountType $RecoveryOSDiskAccountType
#Make sure to replace the variables $datadiskName with data disk name.
#Data disk
$datadisk = Get-AzDisk -DiskName $datadiskName -ResourceGroupName "A2AdemoRG"
$datadiskId1 = $datadisk[0].Id
$RecoveryReplicaDiskAccountType = $datadisk[0].Sku.Name
$RecoveryTargetDiskAccountType = $datadisk[0].Sku.Name
$DataDisk1ReplicationConfig = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -ManagedDisk -LogStorageAccountId $EastUSCacheStorageAccount.Id -DiskId $datadiskId1 -RecoveryResourceGroupId $RecoveryRG.ResourceId -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType -RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType
#Create a list of disk replication configuration objects for the disks of the virtual machine that are to be replicated.
$diskconfigs = @()
$diskconfigs += $OSDiskReplicationConfig, $DataDisk1ReplicationConfig
#Start replication by creating replication protected item. Using a GUID for the name of the replication protected item to ensure uniqueness of name.
$TempASRJob = New-AzRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $VM.Id -Name (New-Guid).Guid -ProtectionContainerMapping $EusToWusPCMapping -AzureToAzureDiskReplicationConfiguration $diskconfigs -RecoveryResourceGroupId $RecoveryRG.ResourceId -RecoveryProximityPlacementGroupId $targetPpg.Id
为多个数据磁盘启用复制时,请使用以下 PowerShell cmdlet -
#Get the resource group that the virtual machine must be created in when failed over.
$RecoveryRG = Get-AzResourceGroup -Name "a2ademorecoveryrg" -Location "West US 2"
#Specify replication properties for each disk of the VM that is to be replicated (create disk replication configuration)
#Make sure to replace the variables $OSdiskName with OS disk name.
#OS Disk
$OSdisk = Get-AzDisk -DiskName $OSdiskName -ResourceGroupName "A2AdemoRG"
$OSdiskId = $OSdisk.Id
$RecoveryOSDiskAccountType = $OSdisk.Sku.Name
$RecoveryReplicaDiskAccountType = $OSdisk.Sku.Name
$OSDiskReplicationConfig = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -ManagedDisk -LogStorageAccountId $EastUSCacheStorageAccount.Id -DiskId $OSdiskId -RecoveryResourceGroupId $RecoveryRG.ResourceId -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType -RecoveryTargetDiskAccountType $RecoveryOSDiskAccountType
$diskconfigs = @()
$diskconfigs.Add($OSDiskReplicationConfig)
#Data disk
# Add data disks
Foreach( $disk in $VM.StorageProfile.DataDisks)
{
$datadisk = Get-AzDisk -DiskName $datadiskName -ResourceGroupName "A2AdemoRG"
$dataDiskId1 = $datadisk[0].Id
$RecoveryReplicaDiskAccountType = $datadisk[0].Sku.Name
$RecoveryTargetDiskAccountType = $datadisk[0].Sku.Name
$DataDisk1ReplicationConfig = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -ManagedDisk -LogStorageAccountId $EastUSCacheStorageAccount.Id `
-DiskId $dataDiskId1 -RecoveryResourceGroupId $RecoveryRG.ResourceId -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType `
-RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType
$diskconfigs.Add($DataDisk1ReplicationConfig)
}
#Start replication by creating replication protected item. Using a GUID for the name of the replication protected item to ensure uniqueness of name.
$TempASRJob = New-AzRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $VM.Id -Name (New-Guid).Guid -ProtectionContainerMapping $EusToWusPCMapping -AzureToAzureDiskReplicationConfiguration $diskconfigs -RecoveryResourceGroupId $RecoveryRG.ResourceId -RecoveryProximityPlacementGroupId $targetPpg.Id
当通过 PPG 启用区域到区域复制时,启动复制的命令将与 PowerShell cmdlet 进行交换-
$TempASRJob = New-AzRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $VM.Id -Name (New-Guid).Guid -ProtectionContainerMapping $EusToWusPCMapping -AzureToAzureDiskReplicationConfiguration $diskconfigs -RecoveryResourceGroupId $RecoveryRG.ResourceId -RecoveryProximityPlacementGroupId $targetPpg.Id -RecoveryAvailabilityZone "2"
成功启动复制操作后,虚拟机数据将复制到恢复区域。
复制过程首先在恢复区域中初始植入虚拟机复制磁盘的副本。 此阶段中称为初始复制阶段。
初始复制完成后,复制过程将转移到差异同步阶段。 此时,虚拟机受到保护,可对其执行测试故障转移操作。 初始复制完成后,表示虚拟机的复制项的复制状态将转换为“受保护”状态。
获取虚拟机对应的复制保护项的详细信息,监视该虚拟机的复制状态和复制运行状况。
Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $PrimaryProtContainer | Select FriendlyName, ProtectionState, ReplicationHealth
- 要执行测试故障转移、进行验证,然后清理测试故障转移,请按照这些步骤操作。
- 要进行故障转移,请按照此处所述步骤操作。
- 要进行重新保护并故障恢复到源区域,请使用下面的 PowerShell cmdlet -
#Create Cache storage account for replication logs in the primary region
$WestUSCacheStorageAccount = New-AzStorageAccount -Name "a2acachestoragewestus" -ResourceGroupName "A2AdemoRG" -Location 'West US' -SkuName Standard_LRS -Kind Storage
#Use the recovery protection container, new cache storage account in West US and the source region VM resource group
Update-AzRecoveryServicesAsrProtectionDirection -ReplicationProtectedItem $ReplicationProtectedItem -AzureToAzure -ProtectionContainerMapping $WusToEusPCMapping -LogStorageAccountId $WestUSCacheStorageAccount.Id -RecoveryResourceGroupID $sourceVMResourcegroup.ResourceId -RecoveryProximityPlacementGroupId $vm.ProximityPlacementGroup.Id
- 要禁用复制,请按照此处步骤操作。
通过 PowerShell 将 VMware 到 Azure
- 确保准备好本地 VMware 服务器,以便能够灾难恢复到 Azure。
- 登录到你的帐户,并按照此处的规定设置订阅。
- 设置恢复服务保管库并设置保管库上下文。
- 验证保管库注册。
- 创建复制策略。
- 添加 vCenter 服务器并发现虚拟机,然后创建存储帐户以进行复制。
- 要复制 VMware 虚拟机,请在此处查看详细信息,并遵循以下 PowerShell cmdlet -
#Get the target resource group to be used
$ResourceGroup = Get-AzResourceGroup -Name "VMwareToAzureDrPs"
#Get the target virtual network to be used
$RecoveryVnet = Get-AzVirtualNetwork -Name "ASR-vnet" -ResourceGroupName "asrrg"
#Get the protection container mapping for replication policy named ReplicationPolicy
$PolicyMap = Get-AzRecoveryServicesAsrProtectionContainerMapping -ProtectionContainer $ProtectionContainer | where PolicyFriendlyName -eq "ReplicationPolicy"
#Get the protectable item corresponding to the virtual machine CentOSVM1
$VM1 = Get-AzRecoveryServicesAsrProtectableItem -ProtectionContainer $ProtectionContainer -FriendlyName "CentOSVM1"
# Enable replication for virtual machine CentOSVM1 using the Az.RecoveryServices module 2.0.0 onwards to replicate to managed disks
# The name specified for the replicated item needs to be unique within the protection container. Using a random GUID to ensure uniqueness
$Job_EnableReplication1 = New-AzRecoveryServicesAsrReplicationProtectedItem -VMwareToAzure -ProtectableItem $VM1 -Name (New-Guid).Guid -ProtectionContainerMapping $PolicyMap -ProcessServer $ProcessServers[1] -Account $AccountHandles[2] -RecoveryResourceGroupId $ResourceGroup.ResourceId -logStorageAccountId $LogStorageAccount.Id -RecoveryAzureNetworkId $RecoveryVnet.Id -RecoveryAzureSubnetName "Subnet-1" -RecoveryProximityPlacementGroupId $targetPpg.Id
- 可使用 Get-ASRReplicationProtectedItem cmdlet 检查虚拟机的复制状态和复制运行状况。
Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $ProtectionContainer | Select FriendlyName, ProtectionState, ReplicationHealth
通过 PowerShell 将 hyper-v 到 Azure
-
确保准备好本地 Hyper-V 服务器,以便能够灾难恢复到 Azure。
-
登录到 Azure。
-
创建 Hyper-V 站点。
-
安装提供程序和代理。
-
创建复制策略。
-
使用以下步骤启用复制 -
a. 检索与要保护的 VM 相对应的可保护项,如下所示:
$VMFriendlyName = "Fabrikam-app" #Name of the VM $ProtectableItem = Get-AzRecoveryServicesAsrProtectableItem -ProtectionContainer $protectionContainer -FriendlyName $VMFriendlyNameb. 保护 VM。 如果要保护的 VM 有多个附加磁盘,则需使用 OSDiskName 参数指定操作系统磁盘。
$OSType = "Windows" # "Windows" or "Linux" $DRjob = New-AzRecoveryServicesAsrReplicationProtectedItem -ProtectableItem $VM -Name $VM.Name -ProtectionContainerMapping $ProtectionContainerMapping -RecoveryAzureStorageAccountId $StorageAccountID -OSDiskName $OSDiskNameList[$i] -OS $OSType -RecoveryResourceGroupId $ResourceGroupID -RecoveryProximityPlacementGroupId $targetPpg.Idc. 等待 VM 在完成初始复制后进入受保护状态。 这可能需要一段时间,具体取决于诸如要复制的数据量和 Azure 的可用上游带宽等因素。 进入受保护状态后,更新作业状态和 StateDescription,如下所示:
$DRjob = Get-AzRecoveryServicesAsrJob -Job $DRjob $DRjob | Select-Object -ExpandProperty State $DRjob | Select-Object -ExpandProperty StateDescriptiond. 更新各种恢复属性(例如 VM 角色大小),以及进行故障转移后需要将 VM NIC 连接到的 Azure 网络。
$nw1 = Get-AzVirtualNetwork -Name "FailoverNw" -ResourceGroupName "MyRG" $VMFriendlyName = "Fabrikam-App" $rpi = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $protectionContainer -FriendlyName $VMFriendlyName $UpdateJob = Set-AzRecoveryServicesAsrReplicationProtectedItem -InputObject $rpi -PrimaryNic $VM.NicDetailsList[0].NicId -RecoveryNetworkId $nw1.Id -RecoveryNicSubnetName $nw1.Subnets[0].Name $UpdateJob = Get-AzRecoveryServicesAsrJob -Job $UpdateJob $UpdateJob | Select-Object -ExpandProperty state Get-AzRecoveryServicesAsrJob -Job $job | Select-Object -ExpandProperty state -
运行测试故障转移。
后续步骤
要执行重新保护以及 VMware 到 Azure 的故障恢复,请按照此处所述步骤进行操作。
要执行 Hyper-V 到 Azure 的故障转移,请按照此处所述步骤操作;要执行故障恢复,请按照此处所述步骤操作。
有关详细信息,请参阅 Site Recovery 中的故障转移。
历史资料。此文对应 2022-08-12 的中文文档快照,适用产品版本和命令行为以原文为准。
来源与署名:Microsoft 和文档贡献者(原始作者元数据 Sharmistha-Rai)。固定版本原文。文档采用 CC BY 4.0,示例代码采用 MIT 授权。本站将 Markdown 转为 HTML,规范化链接,移除外部媒体、发布器占位标签和导航标记。
