如何将同一 VNET 下的虚拟机从经典部署模型迁移到 Azure Resource Manager

适用场景

用户拥有多个云服务但是在同一个 VNET 下,希望将这些虚拟机从经典部署模型(以下简称:ASM)迁移到 Azure Resource Manager(以下简称:ARM)。

Note

如果您未使用 VNET,希望将同一个云服务下的虚拟机从 ASM 模式迁移到 ARM 模式,您可以参考这篇文章:如何将同一个云服务下的虚拟机从 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}Note:注册迁移服务为一次性操作,注册完成后以后迁移时无需再次注册,但是如果您在未注册前尝试迁移,会收到报错说该订阅未注册迁移服务#最后登陆到经典模式中需要迁移的虚拟机所在订阅下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"<订阅名称>"

检查 ARM 下您订阅里的配额,确保需要迁移的虚拟机有足够的配额可以使用:

复制

#您可以根据虚拟机所在的区域选择 China North 或者 China EastPSC:\windows\system32>Get-AzureRmVMUsage -Location"China East"Name                            CurrentValueLimitUnit----                            ------------- -----  ----Availability Sets22000CountTotalRegional Cores39100CountVirtual Machines1710000CountVirtual MachineScaleSets12000CountStandard Dv2 Family Cores4100CountStandard FS Family Cores16100CountStandard A0-A7 Family Cores11100CountStandardDFamily 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

将同一个 VNET 下的虚拟机从 ASM 迁移到 ARM 上

PowerShell复制

#将 ASM 下 VNET 的名称赋值给变量方便后面调用PS C:\windows\system32>$vnetName=""#验证 VNET 是否符合迁移条件PS C:\windows\system32>Move-AzureVirtualNetwork-Validate-VirtualNetworkName$vnetNameOperationId        :7faa1832-931c-44f9-81b8-68cfa4a4aeedResult            : 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...}#检查验证中的告警信息PS C:\windows\system32>$validate=Move-AzureVirtualNetwork-Validate-VirtualNetworkName$vnetNamePS C:\windows\system32>$validate.ValidationMessagesResourceType      : DeploymentResourceName      : <资源组名称>Category          : InformationMessage            : VM <虚拟机名称>inDeployment <资源组名称> within Cloud Service <云服务名称> is eligibleformigration.VirtualMachineName : <虚拟机名称>ResourceType      : DeploymentResourceName      : <资源组名称>Category          : WarningMessage            : VM <虚拟机名称>inHostedService <云服务名称> contains Extension BGInfo version1.* which is an XML                extension. XML extensions are not supportedinAzure Resource Manager. It is recommended to                uninstall it from the VM. Alternatively, it will be automatically uninstalled during migration.VirtualMachineName : <虚拟机名称>ResourceType      : VirtualNetworkResourceName      : Category          : InformationMessage            : Virtual Network is eligibleformigration.VirtualMachineName :ResourceType      : DeploymentResourceName      : <资源组名称>Category          : InformationMessage            : Deployment <资源组名称>inCloud Service <云服务名称> is eligibleformigration.VirtualMachineName :ResourceType      : DeploymentResourceName      : <资源组名称>Category          : InformationMessage            : VM <虚拟机名称>inDeployment <资源组名称> within Cloud Service <云服务名称> is eligibleformigration.VirtualMachineName : <虚拟机名称>ResourceType      : DeploymentResourceName      : <资源组名称>Category          : WarningMessage            : VM <虚拟机名称>inHostedService <云服务名称> contains Extension BGInfo version1.* which is an XML                extension. XML extensions are not supportedinAzure Resource Manager. It is recommended to                uninstall it from the VM. Alternatively, it will be automatically uninstalled during migration.VirtualMachineName : <虚拟机名称>#上述验证通过后接下来执行迁移准备操作PS C:\windows\system32>Move-AzureVirtualNetwork-Prepare-VirtualNetworkName$vnetNameOperationDescription    OperationId                          OperationStatus

Move-AzureVirtualNetwork 8470416e-987f-4171-9e3f-65263a99e41d Succeeded

如果在迁移准备操作中出现了报错,或者您想取消本次迁移操作,可以使用下面命令进行取消

PS C:\windows\system32> Move-AzureVirtualNetwork -Abort -VirtualNetworkName $vnetName

OperationDescription OperationId OperationStatus

Move-AzureVirtualNetwork fde6fc72-7cb8-4cb5-a6e0-01a519509e18 Succeeded

如果迁移准备步骤操作成功,那么可以执行下述命令来生效迁移操作

PS C:\windows\system32> Move-AzureVirtualNetwork -Commit -VirtualNetworkName $vnetName

OperationDescription OperationId OperationStatus

Move-AzureVirtualNetwork 1ce54778-bbcf-403d-b971-a13993484212 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 盘和数据盘中的虚拟机镜像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$storageAccountNameOperationId        :68f3501e-f965-4732-aae5-a1da5b58103bResult            : Validation Passed. Please see ValidationMessages objectfora list of resources that will be migrated.ValidationMessages : {<存储账号名称>}PS C:\windows\system32>$val=Move-AzureStorageAccount-Validate-StorageAccountName$storageAccountNamePS C:\windows\system32>$val.ValidationMessagesResourceType      : StorageResourceName      : <存储账号名称>Category          : InformationMessage            : Storage Account tcportalvhdsgrnnb3k173zr is eligibleformigration.VirtualMachineName :#上述验证通过后接下来执行迁移准备操作PS C:\windows\system32>Move-AzureStorageAccount-Prepare-StorageAccountName$storageAccountNameOperationDescription    OperationId                          OperationStatus----------------------------------------------Move-AzureStorageAccount4086a517-a14a-4360-97aa-2714543dd345 Succeeded#如果在迁移准备操作中出现了报错,或者您想取消本次迁移操作,可以使用下面命令进行取消PS C:\windows\system32>Move-AzureStorageAccount-Abort-StorageAccountName$storageAccountNameOperationDescription    OperationId                          OperationStatus----------------------------------------------Move-AzureStorageAccount8473i405-b3fg-7942-345h-8236hdy63i2f Succeeded#如果迁移准备步骤操作成功,那么可以执行下述命令来生效迁移操作PS C:\windows\system32>Move-AzureStorageAccount-Commit-StorageAccountName$storageAccountNameOperationDescription    OperationId                          OperationStatus----------------------------------------------Move-AzureStorageAccountcf4e80b3-8e26-4d65-96f2-98dda2266d49 Succeeded 立即访问http://market.azure.cn

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,524评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,869评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,813评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,210评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,085评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,117评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,533评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,219评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,487评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,582评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,362评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,218评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,589评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,899评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,176评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,503评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,707评论 2 335

推荐阅读更多精彩内容