我正在尝试从 Azure 上的自定义映像部署 VM。我正在使用门户和 Azure CLI。
当我从市场上的产品创建虚拟机时,一切都很顺利。当我捕获虚拟机的映像(经过释放和通用化过程)并尝试从该映像部署虚拟机时,由于“无计划”错误,创建虚拟机时失败。
我一直在进行故障排除,似乎我需要一个模板和参数 json 文件来指定如何部署,但这方面的文档很少,我不确定如何配置这些文件以及其中的哪一部分是“计划”。我可以使用现有的 VM/资源组并下载 template.json 和 paramater.json 文件,但尝试使用这些文件创建新的 VM 会失败。
有谁有这方面的经验或者知道哪里有足够的文档吗?
以下是 template.json 文件的示例:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
},
"networkSecurityGroupName": {
"type": "string"
},
"networkSecurityGroupRules": {
"type": "array"
},
"subnetName": {
"type": "string"
},
"virtualNetworkId": {
"type": "string"
},
"publicIpAddressName": {
"type": "string"
},
"publicIpAddressType": {
"type": "string"
},
"publicIpAddressSku": {
"type": "string"
},
"virtualMachineName": {
"type": "string"
},
"virtualMachineRG": {
"type": "string"
},
"osDiskType": {
"type": "string"
},
"virtualMachineSize": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "secureString"
},
"diagnosticsStorageAccountName": {
"type": "string"
},
"diagnosticsStorageAccountId": {
"type": "string"
}
},
"variables": {
"nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]",
"vnetId": "[parameters('virtualNetworkId')]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
},
"resources": [
{
"name": "[parameters('networkInterfaceName')]",
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2018-10-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]",
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]"
}
}
}
],
"networkSecurityGroup": {
"id": "[variables('nsgId')]"
}
}
},
{
"name": "[parameters('networkSecurityGroupName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2018-08-01",
"location": "[parameters('location')]",
"properties": {
"securityRules": "[parameters('networkSecurityGroupRules')]"
}
},
{
"name": "[parameters('publicIpAddressName')]",
"type": "Microsoft.Network/publicIpAddresses",
"apiVersion": "2018-08-01",
"location": "[parameters('location')]",
"properties": {
"publicIpAllocationMethod": "[parameters('publicIpAddressType')]"
},
"sku": {
"name": "[parameters('publicIpAddressSku')]"
}
},
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2018-06-01",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "[parameters('osDiskType')]"
}
},
"imageReference": {
"id": "/subscriptions/56640100-5e0e-4f37-9c73-d716e7306962/resourceGroups/Test-RG/providers/Microsoft.Compute/images/Test-VM-image-20190423094722"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('virtualMachineName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[concat('https://', parameters('diagnosticsStorageAccountName'), '.blob.core.windows.net/')]"
}
}
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
}
}
}
以下是 parameters.json 文件的示例:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"value": "westus"
},
"networkInterfaceName": {
"value": "test-vm726"
},
"networkSecurityGroupName": {
"value": "TestVMnsg114"
},
"networkSecurityGroupRules": {
"value": []
},
"subnetName": {
"value": "default"
},
"virtualNetworkId": {
"value": "/subscriptions/56640100-5e0e-4f37-9c73-d716e7306962/resourceGroups/Test-RG/providers/Microsoft.Network/virtualNetworks/Test-RG-vnet"
},
"publicIpAddressName": {
"value": "TestVMip568"
},
"publicIpAddressType": {
"value": "Dynamic"
},
"publicIpAddressSku": {
"value": "Basic"
},
"virtualMachineName": {
"value": "Test-VM"
},
"virtualMachineRG": {
"value": "Test-RG"
},
"osDiskType": {
"value": "Premium_LRS"
},
"virtualMachineSize": {
"value": "Standard_B2s"
},
"adminUsername": {
"value": "clear"
},
"adminPassword": {
"value": null
},
"diagnosticsStorageAccountName": {
"value": "testcustomacc282828"
},
"diagnosticsStorageAccountId": {
"value": "/subscriptions/56640100-5e0e-4f37-9c73-d716e7306962/resourceGroups/Test-RG/providers/Microsoft.Storage/storageAccounts/testcustomacc282828"
}
}
}
答案1
尝试添加如下计划信息:
"imageReference": {
"id": "/subscriptions/56640100-5e0e-4f37-9c73-d716e7306962/resourceGroups/Test-RG/providers/Microsoft.Compute/images/Test-VM-image-20190423094722",
"publisher": "string",
"offer": "string",
"sku": "string",
"version": "string"
},
即使它是一个自定义图像,如果它是从市场图像构建的,它仍然会具有与之绑定的计划信息。
https://docs.microsoft.com/en-us/azure/templates/microsoft.compute/2019-03-01/virtualmachines