我在使用PowerShell使用自定义映像部署vmss时遇到问题。以下是我的powershell部署代码:
#New-AzureRmResourceGroup -Location southeastasia -Name arkgenegroup1
# Resource group name from above
$rg = "myvmss"
$location = "southeastasia"
# Create a config object
$vmssConfig = New-AzureRmVmssConfig -Location $location -SkuCapacity 2 -SkuName Standard_A0 -UpgradePolicyMode Automatic
# Reference a virtual machine image from the gallery
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmssConfig -OsDiskCreateOption FromImage -ManagedDisk StandardLRS -OsDiskCaching "None" -OsDiskOsType Linux -ImageReferenceId (Get-AzureRmImage -ImageName image200817 -ResourceGroupName $rg).id
# Set up information for authenticating with the virtual machine
Set-AzureRmVmssOsProfile $vmssConfig -AdminUsername admin -AdminPassword adminpass -ComputerNamePrefix myvmss
# Create the virtual network resources
## Basics
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name "my-subnet" -AddressPrefix 10.0.0.0/24
$vnet = New-AzureRmVirtualNetwork -Name "my-network" -ResourceGroupName $rg -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
## Load balancer
$publicIP = New-AzureRmPublicIpAddress -Name "PublicIP" -ResourceGroupName $rg -Location $location -AllocationMethod Static -DomainNameLabel "myuniquedomain"
$frontendIP = New-AzureRmLoadBalancerFrontendIpConfig -Name "LB-Frontend" -PublicIpAddress $publicIP
$backendPool = New-AzureRmLoadBalancerBackendAddressPoolConfig -Name "LB-backend"
$probe = New-AzureRmLoadBalancerProbeConfig -Name "HealthProbe" -Protocol Tcp -Port 80 -IntervalInSeconds 15 -ProbeCount 2
$inboundNATRule1= New-AzureRmLoadBalancerRuleConfig -Name "webserver" -FrontendIpConfiguration $frontendIP -Protocol Tcp -FrontendPort 80 -BackendPort 80 -IdleTimeoutInMinutes 15 -Probe $probe -BackendAddressPool $backendPool
$inboundNATPool1 = New-AzureRmLoadBalancerInboundNatPoolConfig -Name "RDP" -FrontendIpConfigurationId $frontendIP.Id -Protocol TCP -FrontendPortRangeStart 53380 -FrontendPortRangeEnd 53390 -BackendPort 3389
New-AzureRmLoadBalancer -ResourceGroupName $rg -Name "myLB" -Location $location -FrontendIpConfiguration $frontendIP -LoadBalancingRule $inboundNATRule1 -InboundNatPool $inboundNATPool1 -BackendAddressPool $backendPool -Probe $probe
## IP address config
$ipConfig = New-AzureRmVmssIpConfig -Name "my-ipaddress" -LoadBalancerBackendAddressPoolsId $backendPool.Id -SubnetId $vnet.Subnets[0].Id -LoadBalancerInboundNatPoolsId $inboundNATPool1.Id
# Attach the virtual network to the IP object
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmssConfig -Name "network-config" -Primary $true -IPConfiguration $ipConfig
# Create the scale set with the config object (this step might take a few minutes)
New-AzureRmVmss -ResourceGroupName $rg -Name "myvmss" -VirtualMachineScaleSet $vmssConfig
错误代码
New-AzureRmVmss : Long running operation failed with status 'Failed'.
ErrorCode: DiskProcessingError
ErrorMessage: One or more errors occurred while preparing VM disks. See disk instance view for details.
StartTime: 8/21/2017 4:59:40 PM
EndTime: 8/21/2017 5:00:02 PM
OperationID: xxxxxxx-fda7-4f37-acbb-xxxxxxxx
Status: Failed
At line:1 char:1
+ New-AzureRmVmss -ResourceGroupName $rg -Name "myvmss" -VirtualMa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmVmss], ComputeCloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Common.ComputeCloudException,Microsoft.Azure.Commands.Compute.Automation.NewAzureRmVmss
我似乎无法弄清楚究竟是什么导致了问题,同样的图像可以用来创建独立的VM。
答案 0 :(得分:0)
Get-AzureRmImage -ImageName image200817 -ResourceGroupName $ rg
此图像是否由Azure VM创建?
如果是,我们应该使用waagent
命令删除机器特定的文件和数据。 SSH到您的VM然后键入以下命令:
sudo waagent -deprovision+user
注意:强>
仅在要作为图像捕获的VM上运行此命令。 它不能保证图像清除所有敏感图像 信息或适合重新分配。 +用户参数 还会删除上次配置的用户帐户。如果你想保留 VM中的帐户凭据,只需使用-deprovision即可离开用户 帐户到位。
运行此命令完成后,我们可以使用CLI创建VM映像,我们可以按照以下步骤操作:
1.取消分配VM
az vm deallocate \
--resource-group myResourceGroup \
--name myVM
2.将VM标记为通用
az vm generalize \
--resource-group myResourceGroup \
--name myVM
3.创建VM的图像
az image create \
--resource-group myResourceGroup \
--name myImage --source myVM
完成这些脚本运行后,我们可以使用您的powershell脚本部署带有该图像的VMSS。
有关创建虚拟机或VHD映像的详细信息,请参阅此article。