将现有 VM 追溯加入 VNet (Azure)

Retroactively joining existing VMs to a VNet (Azure)

我在 Azure 中配置了两个经典 VM。它们存在于不同的资源组中,我现在想将它们加入到一个 VNet 中。我怎么做?我无法准确找到与此相关的文档,并且由于我的应用程序是实时的,所以我想尽量减少停机时间(或者最好完全消除停机时间)。

无法 现有 VM 移动到 VNET。不过,您可以做一些事情。

您可以 remove/delete 现有的 VM/VMs,这样做,您将得到 VM/VMs 的 VHD/VHDs。您现在可以继续使用相同的 VHD 创建新的 VM/VMs。

话虽如此,但无法将已创建的 VM 移动到 VNET。 VM 可以在创建时加入 VNET。

希望对您有所帮助!

此致, 朴雅卡

您的虚拟机在不同的资源组中,我宁愿说您的虚拟机在不同的云服务中,因为您的虚拟机是经典虚拟机。您没有说明它们是否在同一网络中,所以我假设它们在不同的 vNet 中。在这种情况下,无需将 VM 迁移到不同的云服务。您只需要将其中一个 VM 的 vNet 更改为与另一个相同。

您可以使用 powershell 脚本轻松做到这一点-

$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 

如果您的 VM 是 ARM VM,您也可以使用不同的方法。参考这个问题-