将邻近放置组中运行的 Azure 虚拟机复制到另一个区域Replicate Azure virtual machines running in Proximity Placement Groups to another region

本文介绍如何将邻近放置组中运行的虚拟机复制、故障转移和故障恢复到次要区域。This article describes how to replicate, failover and failback virtual machines running in a Proximity Placement Group to a secondary region.

邻近放置组是一种 Azure 虚拟机逻辑分组功能,可用于降低与应用程序关联的 VM 间网络延迟。Proximity Placement Groups is an Azure Virtual Machine logical grouping capability that you can use to decrease the inter-VM network latency associated with your applications. 当 VM 部署在相同的邻近放置组中时,它们彼此的物理位置会尽可能接近。When the VMs are deployed within the same proximity placement group, they are physically located as close as possible to each other. 邻近放置组尤其有助于满足对延迟敏感的工作负载的要求。Proximity placement groups are particularly useful to address the requirements of latency-sensitive workloads.

邻近放置组中的灾难恢复Disaster recovery with Proximity Placement Groups

在典型场景中,你可能会在邻近放置组中运行虚拟机,以避免在应用程序的各个层之间出现网络延迟。In a typical scenario, you may have your virtual machines running in a proximity placement group to avoid the network latency between the various tiers of your application. 虽然这样可以最大程度减少应用程序的网络延迟,但建议使用 Site Recovery 保护这些应用程序免受任何区域级别故障。While this can provide your application optimal network latency, you would like to protect these applications using Site Recovery for any region level failure. 发生故障转移时,Site Recovery 将数据从一个 Azure 区域复制到另一个 Azure 区域,并调出灾难恢复区域中的计算机。Site Recovery replicates the data from one region to another Azure region and brings up the machines in disaster recovery region in an event of failover.

注意事项Considerations

  • 最佳做法是将虚拟机故障转移/故障恢复到邻近放置组。The best effort will be to failover/failback the virtual machines into a proximity placement group. 但是,如果 VM 在故障转移/故障恢复期间无法在邻近放置组中调出,则故障转移/故障恢复仍将发生,并且系统将在邻近放置组之外创建虚拟机。However, if VM is unable to be brought up inside Proximity Placement during failover/failback, then failover/failback will still happen, and virtual machines will be created outside of a proximity placement group.
  • 如果将某个可用性集固定到邻近放置组,且可用性集中的 VM 在故障转移/故障恢复时具有分配约束,则系统将在可用性集和邻近放置组之外创建虚拟机。If an Availability Set is pinned to a Proximity Placement Group and during failover/failback VMs in the availability set have an allocation constraint, then the virtual machines will be created outside of both the availability set and proximity placement group.
  • 非托管磁盘不支持适用于邻近放置组的 Site Recovery。Site Recovery for Proximity Placement Groups is not supported for unmanaged disks.

备注

Azure Site Recovery 不支持从 Hyper-V 的托管磁盘到 Azure 方案的故障回复。Azure Site Recovery does not support failback from managed disks for Hyper-V to Azure scenarios. 因此,不支持从 Azure 中的邻近放置组到 Hyper-V 的故障回复。Hence, failback from Proximity Placement Group in Azure to Hyper-V is not supported.

先决条件Prerequisites

  1. 确保已有 Azure PowerShell Az 模块。Make sure that you have the Azure PowerShell Az module. 如需进安装或升级 Azure PowerShell,请遵循此安装和配置 Azure PowerShell 指南If you need to install or upgrade Azure PowerShell, follow this Guide to install and configure Azure PowerShell.
  2. 最小的 Azure PowerShell Az 版本应为 4.1.0。The minimum Azure PowerShell Az version should be 4.1.0. 若要检查当前版本,请使用以下命令 -To check the current version, use the below command -
    Get-InstalledModule -Name Az
    

为邻近放置组中的虚拟机设置 Site RecoverySet up Site Recovery for Virtual Machines in Proximity Placement Group

备注

确保你随时可以使用目标邻近放置组的唯一 ID。Make sure that you have the unique ID of target Proximity Placement Group handy. 如果要创建新的邻近放置组,请查看此处的命令;如果使用的是现有邻近放置组,请使用此处的命令。If you're creating a new Proximity Placement Group, then check the command here and if you're using an existing Proximity Placement Group, then use the command here.

Azure 到 AzureAzure to Azure

  1. 登录到 Azure 帐户并设置订阅。Sign in to your account and set your subscription.

  2. 此处所述获取你计划复制的虚拟机的详细信息。Get the details of the virtual machine you're planning to replicate as mentioned here.

  3. 创建恢复服务保管库并设置保管库上下文。Create your recovery services vault and set the vault context.

  4. 准备保管库以开始复制虚拟机。Prepare the vault to start replication virtual machine. 这涉及到为主区域和恢复区域创建 service fabric 对象This involves creating a service fabric object for both primary and recovery regions.

  5. 为主结构和恢复结构创建 Site Recovery 保护容器。Create a Site Recovery protection container, for both the primary and recovery fabrics.

  6. 创建复制策略。Create a replication policy.

  7. 按照此处所述,使用这些步骤创建主保护容器和恢复保护容器之间的保护容器映射,以及用于故障恢复的保护容器映射。Create a protection container mapping between primary and recovery protection container using these steps and a protection container mapping for failback as mentioned here.

  8. 通过这些步骤创建缓存存储帐户。Create cache storage account by following these steps.

  9. 按照此处所述,创建所需的网络映射。Create the required network mappings as mentioned here.

  10. 若要复制包含托管磁盘的 Azure 虚拟机,请使用以下 PowerShell cmdlet:To replicate Azure virtual machine with managed disks, use the below PowerShell cmdlet -

#Get the resource group that the virtual machine must be created in when failed over.
$RecoveryRG = Get-AzResourceGroup -Name "a2ademorecoveryrg" -Location "chinanorth2"

#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 $ChinaEastCacheStorageAccount.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 $ChinaEastCacheStorageAccount.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 $CeToCnPCMapping -AzureToAzureDiskReplicationConfiguration $diskconfigs -RecoveryResourceGroupId $RecoveryRG.ResourceId -RecoveryProximityPlacementGroupId $targetPpg.Id

成功启动复制操作后,虚拟机数据将复制到恢复区域。Once the start replication operation succeeds, virtual machine data is replicated to the recovery region.

复制过程首先在恢复区域中初始植入虚拟机复制磁盘的副本。The replication process starts by initially seeding a copy of the replicating disks of the virtual machine in the recovery region. 此阶段中称为初始复制阶段。This phase is called the initial replication phase.

初始复制完成后,复制过程将转移到差异同步阶段。After initial replication completes, replication moves to the differential synchronization phase. 此时,虚拟机受到保护,可对其执行测试故障转移操作。At this point, the virtual machine is protected, and a test failover operation can be performed on it. 初始复制完成后,表示虚拟机的复制项的复制状态将转换为“受保护”状态。The replication state of the replicated item representing the virtual machine goes to the Protected state after initial replication completes.

获取虚拟机对应的复制保护项的详细信息,监视该虚拟机的复制状态和复制运行状况。Monitor the replication state and replication health for the virtual machine by getting details of the replication protected item corresponding to it.

Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $PrimaryProtContainer | Select FriendlyName, ProtectionState, ReplicationHealth
  1. 要执行测试故障转移、进行验证,然后清理测试故障转移,请按照这些步骤操作。To do a test failover, validate and cleanup test failover, follow these steps.
  2. 要进行故障转移,请按照此处所述步骤操作。To failover, follow the steps as mentioned here.
  3. 若要重新进行保护并故障回复到源区域,请使用下面的 PowerShell cmdlet:To reprotect and failback to the source region, use the below PowerShell cmdlet -
#Create Cache storage account for replication logs in the primary region
$ChinaNorthCacheStorageAccount = New-AzStorageAccount -Name "a2acachestoragechinanorth" -ResourceGroupName "A2AdemoRG" -Location 'China North' -SkuName Standard_LRS -Kind Storage

#Use the recovery protection container, new cache storage account in China North and the source region VM resource group 
Update-AzRecoveryServicesAsrProtectionDirection -ReplicationProtectedItem $ReplicationProtectedItem -AzureToAzure -ProtectionContainerMapping $CnToCePCMapping -LogStorageAccountId $ChinaNorthCacheStorageAccount.Id -RecoveryResourceGroupID $sourceVMResourcegroup.ResourceId -RecoveryProximityPlacementGroupId $vm.ProximityPlacementGroup.Id
  1. 要禁用复制,请按照此处步骤操作。To disable replication, follow the steps here.

VMware 到 AzureVMware to Azure

  1. 确保准备好本地 VMware 服务器,以便能够灾难恢复到 Azure。Make sure that you prepare your on-premises VMware servers for disaster recovery to Azure.
  2. 登录到你的帐户,并按照此处的规定设置订阅。Sign in to your account and set your subscription as specified here.
  3. 设置恢复服务保管库并设置保管库上下文Set up a Recovery Services Vault and set vault context.
  4. 验证保管库注册。Validate your vault registration.
  5. 创建复制策略。Create a replication policy.
  6. 添加 vCenter 服务器并发现虚拟机,然后创建存储帐户以进行复制。Add a vCenter server and discover virtual machines and create storage accounts for replication.
  7. 若要复制 VMware 虚拟机,请查看此处的详细信息,并执行以下 PowerShell cmdlet:To replicate VMware Virtual Machines, check the details here and follow the below 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
  1. 可使用 Get-ASRReplicationProtectedItem cmdlet 检查虚拟机的复制状态和复制运行状况。You can check the replication state and replication health of the virtual machine with the Get-ASRReplicationProtectedItem cmdlet.
Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $ProtectionContainer | Select FriendlyName, ProtectionState, ReplicationHealth
  1. 按照 此处的步骤配置故障转移设置。Configure the failover settings by following the steps here.
  2. 运行测试故障转移。Run a test failover.
  3. 使用这些步骤故障转移到 Azure。Failover to Azure using these steps.

Hyper-V 到 AzureHyper-V to Azure

  1. 确保准备好本地 Hyper-V 服务器,以便能够灾难恢复到 Azure。Make sure that you prepare your on-premises Hyper-V servers for disaster recovery to Azure.

  2. 登录到 Azure。Sign in to Azure.

  3. 设置保管库并设置恢复服务保管库上下文。Set up your vault and set the Recovery Services Vault context.

  4. 创建 Hyper-V 站点。Create a Hyper-V Site.

  5. 安装提供程序和代理。Install the provider and agent.

  6. 创建复制策略。Create a replication policy.

  7. 通过以下步骤启用复制:Enable replication by using the below steps -

    a.a. 检索与要保护的 VM 相对应的可保护项,如下所示:Retrieve the protectable item that corresponds to the VM you want to protect, as follows:

    $VMFriendlyName = "Fabrikam-app"          #Name of the VM
    $ProtectableItem = Get-AzRecoveryServicesAsrProtectableItem -ProtectionContainer $protectionContainer -FriendlyName $VMFriendlyName
    

    b.b. 保护 VM。Protect the VM. 如果要保护的 VM 有多个附加磁盘,则需使用 OSDiskName 参数指定操作系统磁盘。If the VM you're protecting has more than one disk attached to it, specify the operating system disk by using the OSDiskName parameter.

    $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.Id
    

    c.c. 等待 VM 在完成初始复制后进入受保护状态。Wait for the VMs to reach a protected state after the initial replication. 这可能需要一段时间,具体取决于诸如要复制的数据量和 Azure 的可用上游带宽等因素。This can take a while, depending on factors such as the amount of data to be replicated, and the available upstream bandwidth to Azure. 进入受保护状态后,更新作业状态和 StateDescription,如下所示:When a protected state is in place, the job State and StateDescription are updated as follows:

    $DRjob = Get-AzRecoveryServicesAsrJob -Job $DRjob
    $DRjob | Select-Object -ExpandProperty State
    
    $DRjob | Select-Object -ExpandProperty StateDescription
    

    d.d. 更新各种恢复属性(例如 VM 角色大小),以及进行故障转移后需要将 VM NIC 连接到的 Azure 网络。Update recovery properties (such as the VM role size) and the Azure network to which to attach the VM NIC after failover.

    $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
    
  8. 运行测试故障转移Run a test failover.

后续步骤Next steps

要执行重新保护以及 VMware 到 Azure 的故障恢复,请按照此处所述步骤进行操作。To perform reprotect and failback for VMware to Azure, follow the steps outlined here.

要执行 Hyper-V 到 Azure 的故障转移,请按照此处所述步骤操作;要执行故障恢复,请按照此处所述步骤操作。To perform failover for Hyper-V to Azure follow the steps outlined here and to perform failback, follow the steps outlined here.

有关详细信息,请参阅 Site Recovery 中的故障转移For more information, see Failover in Site Recovery.