【问题标题】:Move a Microsoft Azure VM to a Different Subnet Within a vNet将 Microsoft Azure VM 移动到 vNet 中的不同子网
【发布时间】:2017-01-16 06:20:50
【问题描述】:

我们不能使用 azure new 门户或 azure classic 门户将 Microsoft Azure VM 移动到 vNet 中的不同子网吗?如果无法通过门户网站,那么该怎么做?那么如何在创建后编辑 VM 的属性,例如移动到不同的子网等?

【问题讨论】:

标签: azure azure-virtual-machine azure-cloud-services azure-virtual-network azureportal


【解决方案1】:

可以通过新门户。首先,我想问您使用的是经典 VM 还是资源管理器 VM。如果您使用最后一个,您可以通过更改配置设置轻松地在子网之间切换。 转到您的网络接口 > Ip 配置,然后单击 Nic 名称(见下图)

将打开一个新选项卡,您可以更改 nic 的子网。

【讨论】:

    【解决方案2】:

    如果您的虚拟机是经典虚拟机,则使用 azure powershell cmdlet 将其移动到不同的 vNet 非常容易。这是代码-

    $vmName  = "xxxxx"
    $srcServiceName  = "xxxxx"
    $newVNet = "xxxxx"
    
    # export vm config file
    $workingDir = (Get-Location).Path
    $sourceVm = Get-AzureVM –ServiceName $srcServiceName –Name $vmName
    $global:vmConfigurationPath = $workingDir + "\exportedVM.xml"
    $sourceVm | Export-AzureVM -Path $vmConfigurationPath
    
    # remove vm keeping the vhds and spin new vm using old configuration file but in a  new vNet
    Remove-azurevm –ServiceName $srcServiceName –Name $vmName
    $vmConfig = Import-AzureVM -Path $vmConfigurationPath 
    New-AzureVM -ServiceName $srcServiceName  -VMs $vmConfig -VNetName $newVNet -WaitForBoot
    

    【讨论】:

    【解决方案3】:

    如果无法通过门户网站,那么该怎么做?那么如何在创建后编辑 VM 的属性,例如移动到不同的子网等?

    可以使用 Powershell 完成。简而言之,它包含 3 个步骤:

    1. 获取 VM (NIC) 配置
    2. 编辑虚拟机 (NIC) 配置
    3. 更新已编辑的配置

    注意:不支持在不同 VNET 之间移动 VM。要将 VM 移动到另一个 VNET,目前唯一的解决方案是使用相同的 vhd 文件重新创建 VM。

    这是一个很好的分步指南:

    How to change Subnet and Virtual Network for Azure Virtual Machines (ASM & ARM)

    【讨论】:

      猜你喜欢
      • 2019-03-01
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多