您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Azure CLI 将 IaaS 资源从经典部署模型迁移到 Azure 资源管理器部署模型Migrate IaaS resources from classic to Azure Resource Manager by using Azure CLI

以下步骤演示如何使用 Azure 命令行接口 (CLI) 命令将基础结构即服务 (IaaS) 资源从经典部署模型迁移到 Azure 资源管理器部署模型。These steps show you how to use Azure command-line interface (CLI) commands to migrate infrastructure as a service (IaaS) resources from the classic deployment model to the Azure Resource Manager deployment model. 本文中的操作需要 Azure CLI 1.0The article requires the Azure CLI 1.0. 由于 Azure CLI 2.0 仅适用于 Azure 资源管理器资源,因此它不能用于此迁移。Since Azure CLI 2.0 is only applicable for Azure Resource Manager resources, it cannot be used for this migration.

备注

此处描述的所有操作都是幂等的。All the operations described here are idempotent. 如果遇到功能不受支持或配置错误以外的问题,建议重试准备、中止或提交操作。If you have a problem other than an unsupported feature or a configuration error, we recommend that you retry the prepare, abort, or commit operation. 然后平台将重试操作。The platform will then try the action again.


下面是一个流程图,用于确定在迁移过程中需要执行步骤的顺序Here is a flowchart to identify the order in which steps need to be executed during a migration process

Screenshot that shows the migration steps

步骤 1:准备迁移Step 1: Prepare for migration

下面是建议在将 IaaS 资源从经典部署模型迁移到 Resource Manager 部署模型时遵循的一些最佳实践:Here are a few best practices that we recommend as you evaluate migrating IaaS resources from classic to Resource Manager:

  • 请参阅不受支持的配置或功能的列表Read through the list of unsupported configurations or features. 如果虚拟机使用不受支持的配置或功能,建议等到我们宣布支持该功能/配置时再进行迁移。If you have virtual machines that use unsupported configurations or features, we recommend that you wait for the feature/configuration support to be announced. 或者,可以删除该功能或移出该配置,以利迁移进行(如果这样做符合要求)。Alternatively, you can remove that feature or move out of that configuration to enable migration if it suits your needs.
  • 如果通过自动化脚本来部署目前的基础结构和应用程序,则可尝试使用这些脚本进行迁移,以便创建类似的测试性设置。If you have automated scripts that deploy your infrastructure and applications today, try to create a similar test setup by using those scripts for migration. 也可以使用 Azure 门户设置示例环境。Alternatively, you can set up sample environments by using the Azure portal.

重要

目前不支持将应用程序网关从经典部署迁移到 Resource Manager。Application Gateways are not currently supported for migration from classic to Resource Manager. 要迁移带应用程序网关的经典虚拟网络,请先删除该网关,然后运行准备操作来移动网络。To migrate a classic virtual network with an Application gateway, remove the gateway before running a Prepare operation to move the network. 完成迁移后,在 Azure 资源管理器中重新连接该网关。After you complete the migration, reconnect the gateway in Azure Resource Manager.

无法自动迁移其他订阅中连接到 ExpressRoute 线路的 ExpressRoute 网关。ExpressRoute gateways connecting to ExpressRoute circuits in another subscription cannot be migrated automatically. 此类情况下,请删除 ExpressRoute 网关、迁移虚拟网络并重新创建网关。In such cases, remove the ExpressRoute gateway, migrate the virtual network and recreate the gateway. 有关详细信息,请参阅将 ExpressRoute 线路和关联的虚拟网络从经典部署模型迁移到 Resource Manager 部署模型Please see Migrate ExpressRoute circuits and associated virtual networks from the classic to the Resource Manager deployment model for more information.

步骤 2:设置订阅并注册提供程序Step 2: Set your subscription and register the provider

对于迁移方案,需要针对经典部署模型和 Resource Manager 部署模型设置环境。For migration scenarios, you need to set up your environment for both classic and Resource Manager. 安装 Azure CLI选择订阅Install Azure CLI and select your subscription.

登录到帐户。Sign-in to your account.

azure login

使用以下命令选择 Azure 订阅。Select the Azure subscription by using the following command.

azure account set "<azure-subscription-name>"

备注

注册是一次性步骤,但必须在尝试迁移之前完成。Registration is a one time step but it needs to be done once before attempting migration. 如果不注册,会看到以下错误消息Without registering you'll see the following error message

BadRequest : Subscription is not registered for migration.BadRequest : Subscription is not registered for migration.

使用以下命令向迁移资源提供程序注册。Register with the migration resource provider by using the following command. 请注意,在某些情况下,此命令会超时。但是,注册会成功。Note that in some cases, this command times out. However, the registration will be successful.

azure provider register Microsoft.ClassicInfrastructureMigrate

请等五分钟让注册完成。Please wait five minutes for the registration to finish. 可以使用以下命令来检查审批状态。You can check the status of the approval by using the following command. 请确保在继续操作之前,RegistrationState 为 RegisteredMake sure that RegistrationState is Registered before you proceed.

azure provider show Microsoft.ClassicInfrastructureMigrate

现在请将 CLI 切换到 asm 模式。Now switch CLI to the asm mode.

azure config mode asm

步骤 3:确保在当前部署或 VNET 的 Azure 区域中有足够的 Azure 资源管理器虚拟机 vCPUStep 3: Make sure you have enough Azure Resource Manager Virtual Machine vCPUs in the Azure region of your current deployment or VNET

要执行此步骤,需要切换到 arm 模式。For this step you'll need to switch to arm mode. 使用以下命令执行此操作。Do this with the following command.

azure config mode arm

可以使用以下 CLI 命令检查 Azure 资源管理器中目前的 vCPU 数量。You can use the following CLI command to check the current number of vCPUs you have in Azure Resource Manager. 若要了解有关 vCPU 配额的详细信息,请参阅限制和 Azure 资源管理器To learn more about vCPU quotas, see Limits and the Azure Resource Manager

azure vm list-usage -l "<Your VNET or Deployment's Azure region"

验证完此步骤后,可以切换回 asm 模式。Once you're done verifying this step, you can switch back to asm mode.

azure config mode asm

步骤 4:选项 1 - 迁移云服务中的虚拟机Step 4: Option 1 - Migrate virtual machines in a cloud service

使用以下命令获取云服务列表,并选取要迁移的云服务。Get the list of cloud services by using the following command, and then pick the cloud service that you want to migrate. 请注意,如果云服务中的 VM 在虚拟网络中或者具有 Web/辅助角色,将收到错误消息。Note that if the VMs in the cloud service are in a virtual network or if they have web/worker roles, you will get an error message.

azure service list

运行以下命令,从详细输出中获取云服务的部署名称。Run the following command to get the deployment name for the cloud service from the verbose output. 在大多数情况下,部署名称与云服务名称相同。In most cases, the deployment name is the same as the cloud service name.

azure service show <serviceName> -vv

首先,使用以下命令验证用户是否可以迁移云服务:First, validate if you can migrate the cloud service using the following commands:

azure service deployment validate-migration <serviceName> <deploymentName> new "" "" ""

准备迁移云服务中的虚拟机。Prepare the virtual machines in the cloud service for migration. 可以从两个选项中进行选择。You have two options to choose from.

如果想要将 VM 迁移到平台所创建的虚拟网络上,请使用以下命令。If you want to migrate the VMs to a platform-created virtual network, use the following command.

azure service deployment prepare-migration <serviceName> <deploymentName> new "" "" ""

如果想要迁移到 Resource Manager 部署模型中的现有虚拟网络,请使用以下命令。If you want to migrate to an existing virtual network in the Resource Manager deployment model, use the following command.

azure service deployment prepare-migration <serviceName> <deploymentName> existing <destinationVNETResourceGroupName> <subnetName> <vnetName>

准备操作成功后,可以查看详细输出,以获取 VM 的迁移状态,并确保其处于 Prepared 状态。After the prepare operation is successful, you can look through the verbose output to get the migration state of the VMs and ensure that they are in the Prepared state.

azure vm show <vmName> -vv

使用 CLI 或 Azure 门户查看准备好的资源的配置。Check the configuration for the prepared resources by using either CLI or the Azure portal. 如果尚未做好迁移准备,因此想要回到旧的状态,请使用以下命令。If you are not ready for migration and you want to go back to the old state, use the following command.

azure service deployment abort-migration <serviceName> <deploymentName>

如果准备好的配置看起来没问题,则可继续进行,使用以下命令提交资源。If the prepared configuration looks good, you can move forward and commit the resources by using the following command.

azure service deployment commit-migration <serviceName> <deploymentName>

步骤 4:选项 2 - 迁移虚拟网络中的虚拟机Step 4: Option 2 - Migrate virtual machines in a virtual network

选取要迁移的虚拟网络。Pick the virtual network that you want to migrate. 请注意,如果虚拟网络包含的 Web/辅助角色或 VM 的配置不受支持,将收到验证错误消息。Note that if the virtual network contains web/worker roles or VMs with unsupported configurations, you will get a validation error message.

使用以下命令获取订阅中的所有虚拟网络。Get all the virtual networks in the subscription by using the following command.

azure network vnet list

输出将如下所示:The output will look something like this:

命令行屏幕截图,其中整个虚拟网络名称已突出显示。

在上面的示例中,virtualNetworkName 是完整名称 "Group classicubuntu16 classicubuntu16"In the above example, the virtualNetworkName is the entire name "Group classicubuntu16 classicubuntu16".

首先,请使用以下命令验证用户是否可以迁移虚拟网络:First, validate if you can migrate the virtual network using the following command:

azure network vnet validate-migration <virtualNetworkName>

使用以下命令来准备要迁移的所选虚拟网络。Prepare the virtual network of your choice for migration by using the following command.

azure network vnet prepare-migration <virtualNetworkName>

使用 CLI 或 Azure 门户查看准备好的虚拟机的配置。Check the configuration for the prepared virtual machines by using either CLI or the Azure portal. 如果尚未做好迁移准备,因此想要回到旧的状态,请使用以下命令。If you are not ready for migration and you want to go back to the old state, use the following command.

azure network vnet abort-migration <virtualNetworkName>

如果准备好的配置看起来没问题,则可继续进行,使用以下命令提交资源。If the prepared configuration looks good, you can move forward and commit the resources by using the following command.

azure network vnet commit-migration <virtualNetworkName>

步骤 5:迁移存储帐户Step 5: Migrate a storage account

完成虚拟机迁移之后,建议迁移存储帐户。Once you're done migrating the virtual machines, we recommend you migrate the storage account.

使用以下命令来准备要迁移的存储帐户Prepare the storage account for migration by using the following command

azure storage account prepare-migration <storageAccountName>

使用 CLI 或 Azure 门户查看准备就绪的存储帐户的配置。Check the configuration for the prepared storage account by using either CLI or the Azure portal. 如果尚未做好迁移准备,因此想要回到旧的状态,请使用以下命令。If you are not ready for migration and you want to go back to the old state, use the following command.

azure storage account abort-migration <storageAccountName>

如果准备好的配置看起来没问题,则可继续进行,使用以下命令提交资源。If the prepared configuration looks good, you can move forward and commit the resources by using the following command.

azure storage account commit-migration <storageAccountName>

后续步骤Next steps