適用場景
用戶希望將特定云服務下的所有虛擬機從經典部署模型(以下簡稱:ASM)遷移到 Azure Resource Manager(以下簡稱:ARM)昆稿。
Note
如果云服務下使用 VNET 也希望將虛擬機從 ASM 模式遷移到 ARM 模式几苍,您可以參考這篇文章:如何將同一個 VNET 下的虛擬機從 ASM 遷移到 ARM 上
解決方案
首先烁巫,我們登陸到需要遷移的虛擬機所在的訂閱下郑趁,注冊遷移服務:
PowerShell復制
#登陸到需要遷移的虛擬機所在的訂閱下PS C:\windows\system32>Login-AzureRmAccount–Environment AzureChinaCloudEnvironment? ? ? ? ? : AzureChinaCloudAccount? ? ? ? ? ? ? : XXX@mcpod.partner.onmschina.cnTenantId? ? ? ? ? ? ? :xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxSubscriptionId? ? ? ? :xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxSubscriptionName? ? ? : <訂閱名稱>CurrentStorageAccount :#如果您需要遷移某個特定訂閱下的虛擬機,需要手動進行指定PS C:\windows\system32>Select-AzureRmSubscription–SubscriptionName"<訂閱名稱>"#注冊遷移服務PS C:\windows\system32>Register-AzureRmResourceProvider-ProviderNamespaceMicrosoft.ClassicInfrastructureMigrate#遷移服務注冊一般需要 5 分鐘左右误算,您可以通過下述命令查看完成情況束倍,PS C:\windows\system32>Get-AzureRmResourceProvider-ProviderNamespaceMicrosoft.ClassicInfrastructureMigrateProviderNamespace : Microsoft.ClassicInfrastructureMigrateRegistrationState : RegisteredResourceTypes? ? : {classicInfrastructureResources}Locations? ? ? ? : {China North, China East}#最后登陸到經典模式中需要遷移的虛擬機所在訂閱下PS C:\windows\system32>Add-AzureAccount-EnvironmentAzureChinaCloudId? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Type Subscriptions? ? ? ? ? ? ? ? ? ? ? ? Tenants--------------------------XXX@mcpod.partner.onmschina.cn Userxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx }#如果您需要遷移某個特定訂閱下的虛擬機,需要手動進行指定Select-AzureSubscription–SubscriptionName"<訂閱名稱>"
Note
注冊遷移服務為一次性操作乱顾,注冊完成后以后遷移時無需再次注冊侈询,但是如果您在未注冊前嘗試遷移,會收到報錯說該訂閱未注冊遷移服務糯耍。
檢查 ARM 模式下您訂閱里的配額扔字,確保需要遷移的虛擬機有足夠的配額可以使用:
PowerShell復制
#您可以根據(jù)虛擬機所在的區(qū)域選擇 China North 或者 China EastPS C:\windows\system32>Get-AzureRmVMUsage-Location"China East"Name? ? ? ? ? ? ? ? ? ? ? ? ? ? Current Value Limit? Unit--------------------------Availability Sets22000CountTotal Regional Cores39100CountVirtual Machines1710000CountVirtual Machine Scale Sets12000CountStandard Dv2 Family Cores4100CountStandard FS Family Cores16100CountStandard A0-A7 Family Cores11100CountStandard D Family Cores1100CountStandard Av2 Family Cores2100CountStandard DSv2 Family Cores4100CountStandard DS Family Cores1100CountBasic A Family Cores0100CountStandard A8-A11 Family Cores0100CountStandard G Family Cores0100CountStandard GS Family Cores0100CountStandard F Family Cores0100CountStandard NV Family Cores00CountStandard NC Family Cores00CountStandard H Family Cores00CountStandard LS Family Cores0100CountStandard Dv2 Promo Family Cores0100CountStandard DSv2 Promo Family Cores0100CountStandard MS Family Cores00CountStandard Dv3 Family Cores0100CountStandard DSv3 Family Cores0100CountStandard Ev3 Family Cores0100CountStandard ESv3 Family Cores0100CountStandard Storage Managed Disks010000CountPremium Storage Managed Disks010000Count
將同一個云服務下的虛擬機從 ASM 遷移到 ARM 上:
PowerShell復制
#查詢云服務并找出您想要遷移的云服務,此處以 1vnet2cs02 為例PS C:\windows\system32>Get-AzureService|ft ServicenameServiceName-----------1vent2cs041vnet2cs011vnet2cs021vnet2cs03#獲取部署名稱PS C:\windows\system32>$serviceName="1vnet2cs02"PS C:\windows\system32>$deployment=Get-AzureDeployment-ServiceName$serviceNamePS C:\windows\system32>$deploymentName=$deployment.DeploymentNameResult? ? ? ? ? ? : Validation Passed with warnings. Please see ValidationMessages objectfora list of resources? ? ? ? ? ? ? ? ? ? that will be migrated and additional detail on the warnings.ValidationMessages : {test4as, test01, test01, test01...}
選擇 1:將 VM 遷移到一個新建的虛擬網絡中:
PowerShell復制
#驗證云服務PS C:\windows\system32>Move-AzureService-Validate-ServiceName$serviceName` -DeploymentName$deploymentName-CreateNewVirtualNetworkOperationId? ? ? ? :119a8709-4160-4122-859d-a1bc2dc8c603Result? ? ? ? ? ? : Validation Passed. Please see ValidationMessages objectfora list of resources that will be migrated.ValidationMessages : {cs03, cs03, cs03}#上述驗證通過后接下來執(zhí)行遷移準備操作PS C:\windows\system32>Move-AzureService-Prepare-ServiceName$serviceName`>>-DeploymentName$deploymentName-CreateNewVirtualNetworkOperationDescription OperationId? ? ? ? ? ? ? ? ? ? ? ? ? OperationStatus----------------------------------------------Move-AzureService7a6931ef-6f42-47dc-8d99-0929fbdc5658 Succeeded#如果遷移準備步驟操作成功温技,那么可以執(zhí)行下述命令來生效遷移操作PS C:\windows\system32>Move-AzureService-Commit-ServiceName$serviceName-DeploymentName$deploymentNameOperationDescription OperationId? ? ? ? ? ? ? ? ? ? ? ? ? OperationStatus----------------------------------------------Move-AzureServicee88c11c0-21d4-46c0-abb0-700c324b21ba Succeeded
選擇 2:將 VM 遷移到一個已有的虛擬網絡中:
PowerShell復制
#準備已有虛擬網絡的相關信息PS C:\windows\system32>$existingVnetRGName="<虛擬網絡所在的資源組名稱>"PS C:\windows\system32>$vnetName="<虛擬網絡名稱>"PS C:\windows\system32>$subnetName="<子網名稱>"#驗證云服務PS C:\windows\system32>Move-AzureService-Validate-ServiceName$serviceName`>>-DeploymentName$deploymentName-UseExistingVirtualNetwork-VirtualNetworkResourceGroupName$existingVnetRGName-VirtualNetworkName$vnetName-SubnetName$subnetName#上述驗證通過后接下來執(zhí)行遷移準備操作PS C:\windows\system32>Move-AzureService-Prepare-ServiceName$serviceName-DeploymentName$deploymentName`>>-UseExistingVirtualNetwork-VirtualNetworkResourceGroupName$existingVnetRGName`>>-VirtualNetworkName$vnetName-SubnetName$subnetNameOperationDescription OperationId? ? ? ? ? ? ? ? ? ? ? ? ? OperationStatus----------------------------------------------Move-AzureService9c9e01a6-183e-4884-b51d-04f25112934e Succeeded#如果遷移準備步驟操作成功革为,那么可以執(zhí)行下述命令來生效遷移操作PS C:\windows\system32>Move-AzureService-Commit-ServiceName$serviceName-DeploymentName$deploymentNameOperationDescription OperationId? ? ? ? ? ? ? ? ? ? ? ? ? OperationStatus----------------------------------------------Move-AzureServicec803cc0d-1446-4922-bcb1-af1330828c69 Succeeded
遷移虛擬機所在的存儲賬號:
PowerShell復制
#檢查存儲賬號下是否有未被遷移的虛擬機的 VHD 存在PS C:\windows\system32>$storageAccountName="<存儲賬號名稱>"PS C:\windows\system32>Get-AzureDisk|where-Object{$_.MediaLink.Host.Contains($storageAccountName)} |Select-Object-ExpandPropertyAttachedTo-Property`>>? DiskName |Format-List-PropertyRoleName, DiskName#檢查存儲賬號下是否有已分離的虛擬機磁盤,如有需要進行刪除舵鳞,如果您仍然需要這些磁盤可以將其復制到其他存儲賬號中PS C:\windows\system32>Get-AzureDisk|where-Object{$_.MediaLink.Host.Contains($storageAccountName)} |Where-Object-PropertyAttachedTo-EQ$null|Format-List-Property DiskNameDiskName : disktest#刪除磁盤PS C:\windows\system32>Remove-AzureDisk-DiskName"disktest"OperationDescription OperationId? ? ? ? ? ? ? ? ? ? ? ? ? OperationStatus----------------------------------------------Remove-AzureDisk9661659d-3bcf-4e6e-bdc4-cce7c8d7a1e0 Succeeded#刪除存儲賬號中 OS 盤和數(shù)據(jù)盤中的虛擬機鏡像PS C:\windows\system32>Get-AzureVmImage|Where-Object{$_.OSDiskConfiguration.MediaLink-ne$null-and$_.OSDiskConfiguration.MediaLink.Host.Contains($storageAccountName)`>>? ? ? ? ? ? ? ? ? ? ? ? ? ? } |Select-Object-PropertyImageName, ImageLabelImageName? ? ? ? ? ? ? ? ? ImageLabel-------------------captureTest-20160902-436096PS C:\windows\system32>Get-AzureVmImage|Where-Object{$_.DataDiskConfigurations-ne$null`>>-and($_.DataDiskConfigurations |Where-Object{$_.MediaLink-ne$null-and$_.MediaLink.Host.Contains($storageAccountName)}).Count-gt0`>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } |Select-Object-PropertyImageName, ImageLabelPS C:\windows\system32>Remove-AzureVMImage-ImageName"captureTest-20160902-436096"OperationDescription OperationId? ? ? ? ? ? ? ? ? ? ? ? ? OperationStatus----------------------------------------------Remove-AzureVMImageb8f1c164-147a-4d98-9805-432dcd3b7105 Succeeded
復制
#驗證存儲賬號是否符合遷移條件
PS C:\windows\system32> Move-AzureStorageAccount -Validate -StorageAccountName $storageAccountName
OperationId? ? ? ? : 68f3501e-f965-4732-aae5-a1da5b58103b
Result? ? ? ? ? ? : Validation Passed. Please see ValidationMessages object for a list of resources that will be migrated.
ValidationMessages : {<存儲賬號名稱>}
PS C:\windows\system32> $val=Move-AzureStorageAccount -Validate -StorageAccountName $storageAccountName
PS C:\windows\system32> $val.ValidationMessages
ResourceType? ? ? : Storage
ResourceName? ? ? : <存儲賬號名稱>
Category? ? ? ? ? : Information
Message? ? ? ? ? ? : Storage Account tcportalvhdsgrnnb3k173zr is eligible for migration.
VirtualMachineName :
#上述驗證通過后接下來執(zhí)行遷移準備操作
PS C:\windows\system32> Move-AzureStorageAccount -Prepare -StorageAccountName $storageAccountName
OperationDescription? ? OperationId? ? ? ? ? ? ? ? ? ? ? ? ? OperationStatus
--------------------? ? -----------? ? ? ? ? ? ? ? ? ? ? ? ? ---------------
Move-AzureStorageAccount 4086a517-a14a-4360-97aa-2714543dd345 Succeeded
#如果在遷移準備操作中出現(xiàn)了報錯震檩,或者您想取消本次遷移操作,可以使用下面命令進行取消
PS C:\windows\system32> Move-AzureStorageAccount -Abort -StorageAccountName $storageAccountName
OperationDescription? ? OperationId? ? ? ? ? ? ? ? ? ? ? ? ? OperationStatus
--------------------? ? -----------? ? ? ? ? ? ? ? ? ? ? ? ? ---------------
Move-AzureStorageAccount 8473i405-b3fg-7942-345h-8236hdy63i2f Succeeded
#如果遷移準備步驟操作成功蜓堕,那么可以執(zhí)行下述命令來生效遷移操作
PS C:\windows\system32> Move-AzureStorageAccount -Commit -StorageAccountName $storageAccountName
OperationDescription? ? OperationId? ? ? ? ? ? ? ? ? ? ? ? ? OperationStatus
--------------------? ? -----------? ? ? ? ? ? ? ? ? ? ? ? ? ---------------
Move-AzureStorageAccount cf4e80b3-8e26-4d65-96f2-98dda2266d49 Succeeded
```立即訪問http://market.azure.cn