使用 Powershell 具有自定义镜像的 Azure VMSS 返回错误 : DiskProcessingError

标签 azure cloud azure-virtual-machine

我在通过 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

我似乎无法弄清楚到底是什么导致了问题,相同的镜像可以用于创建独立的虚拟机。

最佳答案

我已经在我的实验室测试了它,你的脚本对我有用,这是我的结果: enter image description here

Get-AzureRmImage -ImageName image200817 -ResourceGroupName $rg

此镜像是由 Azure VM 创建的吗?

如果是,我们应该使用waagent命令删除机器特定的文件和数据。通过 SSH 连接到您的虚拟机,然后键入以下命令:

sudo waagent -deprovision+user

注意:

Only run this command on a VM that you intend to capture as an image. It does not guarantee that the image is cleared of all sensitive information or is suitable for redistribution. The +user parameter also removes the last provisioned user account. If you want to keep account credentials in the VM, just use -deprovision to leave the user account in place.

运行此命令完成后,我们可以使用 CLI 来创建 VM 镜像,我们可以按照以下步骤操作:

1.解除分配虚拟机

   az vm deallocate \
    --resource-group myResourceGroup \
    --name myVM

2.将虚拟机标记为通用

az vm generalize \
  --resource-group myResourceGroup \
  --name myVM

3.创建虚拟机镜像

az image create \
  --resource-group myResourceGroup \
  --name myImage --source myVM

这些脚本运行完成后,我们可以使用您的 powershell 脚本使用该镜像部署 VMSS。

有关创建虚拟机或VHD镜像的更多信息,请参阅此article .

关于使用 Powershell 具有自定义镜像的 Azure VMSS 返回错误 : DiskProcessingError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45800085/

相关文章:

Azure 虚拟机陷入启动模式

azure - 从 VM 内部确定 VM 位于哪个 Azure 区域

postgresql - Azure PostgreSQL 突然使用所有存储

t-sql - 使用 TSQL 获取 SQL Azure 数据库版本和 Service_Objective

azure - 部署到云时,未将对象引用设置为对象实例错误

Azure 云域 Controller 通过 Azure Connect 为移动桌面提供服务?

azure - 是否可以将 Azure VM 从托管磁盘转换为非托管磁盘?

.net - 我们可以将 WEBSITE_LOAD_USER_PROFILE=1 添加到 web.config 中吗

sql-server - Azure 托管标识是否支持本地 MS SQL 数据库?

google-app-engine - 云每月定价计算器