我想在 Azure 中创建两个不应相互连接的虚拟机。我创建了第一个虚拟机,并在其创建过程中创建了一个可用性集。
现在,当我创建第二个虚拟机时,我不会在可用性集的下拉列表中获得作为第一个虚拟机的一部分创建的可用性集。
但是,如果我尝试将第二个虚拟机作为第一个虚拟机的一部分进行连接,那么我可以看到作为第一个虚拟机的一部分创建的可用性集。
虚拟机是否必须相互连接才能将它们添加到同一可用性集?这是仅来自 azure 门户的限制吗?有使用 powershell 的解决方法吗?
更新:
如果我们连接两个虚拟机,那么我们可以获得可用性集的好处。但是,同时两个虚拟机都成为同一云服务的一部分,因此由不支持粘性会话的 azure 进行负载平衡。
我的场景是我有相同的前端,需要支持粘性会话。因此我不想将它们相互联系起来。但是,我希望获得可用性集的好处,如可用性集一文中提到的那样。
那么我可以为两个彼此未连接的相同虚拟机设置可用性集吗?
“可用性集”一词意味着您希望在一个服务组中引入一个或多个虚拟机,以便在停机期间最大限度地提高可用性。因此,您在 Azure 门户上看到的行为是正确的,但是您可能对可用性集有一些误解。您可以在此处阅读有关“可用性集”的更多信息。
因此,当您尝试连接第二个虚拟机作为第一个虚拟机的一部分时,您确实会看到可用性集,因为这样您希望您的虚拟机使用第一个虚拟机的设置,并将另一个虚拟机添加到同一组中以最大化可用性。第二个虚拟机成为第一个虚拟机的一部分。
当您创建一个独立的虚拟机(调用是第二个或第三个或任何一个)时,您实际上是在创建一个全新的虚拟机,它将独立于您可能拥有或没有的任何其他虚拟机运行,这就是为什么您看不到“可用性集”相反,您可以基于此新虚拟机创建新的“可用性集”。
Get-AzureVM -ServiceName "savilltech101" -Name "WebSrv3" | Set-AzureAvailabilitySet -AvailabilitySetName "IIS" | Update-AzureVM
我曾经通过 Az PowerShell 模块重新创建虚拟机并将其链接到 AVS。
重新创建后需要重新启用用于日志记录的存储帐户。 另请检查备份(恢复服务保管库)。
对于 Linux VM,将最后一个参数从
-Windows
更改为 -Linux
Add-AzVMAVS.ps1
# Set variables
$resourceGroup = "<>"
$vmName = "<>"
$newAvailSetName = "<>"
# Get the details of the VM to be moved to the Availability Set
$originalVM = Get-AzVM `
-ResourceGroupName $resourceGroup `
-Name $vmName
# Create new availability set if it does not exist
$availSet = Get-AzAvailabilitySet `
-ResourceGroupName $resourceGroup `
-Name $newAvailSetName `
-ErrorAction Ignore
if (-Not $availSet) {
$availSet = New-AzAvailabilitySet `
-Location $originalVM.Location `
-Name $newAvailSetName `
-ResourceGroupName $resourceGroup `
-PlatformFaultDomainCount 2 `
-PlatformUpdateDomainCount 2 `
-Sku Aligned
}
# Remove the original VM
Remove-AzVM -ResourceGroupName $resourceGroup -Name $vmName
# Create the basic configuration for the replacement VM.
$newVM = New-AzVMConfig `
-VMName $originalVM.Name `
-VMSize $originalVM.HardwareProfile.VmSize `
-AvailabilitySetId $availSet.Id
# For a Linux VM, change the last parameter from -Windows to -Linux
Set-AzVMOSDisk `
-VM $newVM -CreateOption Attach `
-ManagedDiskId $originalVM.StorageProfile.OsDisk.ManagedDisk.Id `
-Name $originalVM.StorageProfile.OsDisk.Name `
-Windows
# Add Data Disks
foreach ($disk in $originalVM.StorageProfile.DataDisks) {
Add-AzVMDataDisk -VM $newVM `
-Name $disk.Name `
-ManagedDiskId $disk.ManagedDisk.Id `
-Caching $disk.Caching `
-Lun $disk.Lun `
-DiskSizeInGB $disk.DiskSizeGB `
-CreateOption Attach
}
# Add NIC(s) and keep the same NIC as primary
foreach ($nic in $originalVM.NetworkProfile.NetworkInterfaces) {
if ($nic.Primary -eq "True") {
Add-AzVMNetworkInterface `
-VM $newVM `
-Id $nic.Id -Primary
}
else {
Add-AzVMNetworkInterface `
-VM $newVM `
-Id $nic.Id
}
}
# Recreate the VM
New-AzVM `
-ResourceGroupName $resourceGroup `
-Location $originalVM.Location `
-VM $newVM `
-DisableBginfoExtension