我想创建一个VM Scale集,并使用快照作为Windows VM的基础。由于Set-AzureRmVmssStorageProfile仅接受图像,因此我的第一个尝试是通过使用将快照转换为图像:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -SnapshotId $snapshot.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
但是在这种情况下,创建的图像没有源Blob URI:
什么给我错误:
New-AzureRmVmss:URI Microsoft.Azure.Commands.Compute.Automation.Models.PSImage看起来不是正确的Blob URI。
关于Azure的部署命令:
$vmss = New-AzureRmVmssConfig -Location $loc -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" `
-Image $ImgRef -OsDiskOsType Windows -OsDiskName "C"
Set-AzureRmVmssOSProfile -ComputerNamePrefix $vmNamePrefix -AdminUsername $adminUsername -AdminPassword $adminPassword -VirtualMachineScaleSet $vmss
New-AzureRmVmss -ResourceGroupName $currentrg -Name $vmssName -VirtualMachineScaleSet $vmss -Verbose -ErrorAction Stop;
还有另一种方法来创建图像或设置源Blob uri吗? 还是可以使用快照来创建VM规模集?
-编辑1-
根据Charles Xu的提示,我将图像创建更改为首先创建dik,但是仍然遇到相同的错误。新代码是:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$storageType = 'Standard_LRS'
$diskName = "myDisk"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $rgName -DiskName $diskName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -ManagedDiskId $disk.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
答案 0 :(得分:1)
您可以从Azure VM创建映像。例如,您可以通过PowerShell从Windows VM创建Windows映像,请参见Create and use a custom image for virtual machine scale sets with Azure PowerShell。当图像确定后,只需按以下方式创建VMSS:
New-AzureRmVmss `
-ResourceGroupName "myResourceGroup" `
-Location "EastUS" `
-VMScaleSetName "myScaleSet" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-PublicIpAddressName "myPublicIPAddress" `
-LoadBalancerName "myLoadBalancer" `
-UpgradePolicyMode "Automatic" `
-ImageName "yourImage"
此外,快照还可以,但是您应该首先从快照创建映像。然后从映像创建VMSS。使用命令New-AzureRmImage
,该图像应该是托管图像,因此您看不到URI。只需在命令中使用托管图像ID,如下所示:
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
仅讨论如何创建图像,我建议您使用打包器,并有一个示例here。
更新
我认为您的自定义图片已准备好。像这样的PowerShell脚本:
#Get the custom image
$image = Get-AzureRmImage -ResourceGroupName charlesTerraform -ImageName myPackerImage
# Get the existing Vnet
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName charlesTerraform -Name pakcerVnet
#IP configuration
$ipName = "ipConfig"
#create the IP configuration
$ipConfig = New-AzureRmVmssIpConfig -Name $ipName -LoadBalancerBackendAddressPoolsId $null -SubnetId $vnet.Subnets[0].Id
#create vmss configuration
$vmss = New-AzureRmVmssConfig -Location "East US" -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
##Add the network interface configuration to the scale set configuration
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
# set the stroage profile
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId $image.Id -OsDiskOsType Linux
#set the os profile
Set-AzureRmVmssOSProfile -ComputerNamePrefix "Test" -AdminUsername "azureuser" -AdminPassword "azureuser@2018" -VirtualMachineScaleSet $vmss
#create the vmss
New-AzureRmVmss -ResourceGroupName charlesTerraform -Name TestVmss -VirtualMachineScaleSet $vmss
答案 1 :(得分:0)
人。那么,如何通过自定义快照创建“规模集虚拟机”。这可能吗,或者一个缩放比例集只能有一个基本映像,并且该缩放比例集下的所有虚拟机只能重新镜像到相同的基准?