gpt4 book ai didi

azure - 如何使用 Azure 资源管理器从自定义镜像创建 VM

转载 作者:行者123 更新时间:2023-12-03 03:09:05 24 4
gpt4 key购买 nike

我已经使用 Azure 经典门户有一段时间了,我能够从自定义镜像创建 VM,不会出现任何问题。现在我正在尝试使用新门户,当我去创建新虚拟机时,我没有看到使用图像的选项。如何从我的一个镜像创建虚拟机?

最佳答案

具体操作方法如下...假设您的资源组已创建并且我的基础设施配置如下 -

custom template uri path- https://myvmstore.blob.core.windows.net/vhds/CustomVHD.vhd  
RG Name - myVMsRG
VNet Name - myVNET
VmName = mytestvm
userImageStorageAccountName = myvmstore
adminUsername = adminuser
adminPassword = PassWord123#
osDiskVhdUri = https://myvmstore.blob.core.windows.net/vhds/CustomVHD.vhd
dnsLabelPrefix = mytestvm
osType = Windows
vmSize = Standard_D2
newOrExistingVnet = existing
newOrExistingVnetName = myVNET
newOrExistingSubnetName = mySubnet

首先你需要 json 模板。我已经为自己配置了这种格式。您可以复制相同的代码并以名称deployvm.json保存在D盘中。注意:如果您的 VNET 名称与 myVNET 不同,请在模板中的相同位置进行硬编码。

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"customVmName": {
"type": "string",
"metadata": {
"description": "This is the name of the your VM"
}
},
"userImageStorageAccountName": {
"type": "string",
"metadata": {
"description": "This is the name of the your storage account"
}
},
"osDiskVhdUri": {
"type": "string",
"metadata": {
"description": "Uri of the your user image"
}
},
"dnsLabelPrefix": {
"type": "string",
"metadata": {
"description": "DNS Label for the Public IP. Must be lowercase. It should match with the following regular expression: ^[a-z][a-z0-9-]{1,61}[a-z0-9]$ or it will raise an error."
}
},
"adminUserName": {
"type": "string",
"metadata": {
"description": "User Name for the Virtual Machine"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine"
}
},
"osType": {
"type": "string",
"allowedValues": [
"Windows",
"Linux"
],
"metadata": {
"description": "This is the OS that your VM will be running"
}
},
"vmSize": {
"type": "string",
"metadata": {
"description": "This is the size of your VM"
}
},
"newOrExistingVnet": {
"allowedValues": [ "new", "existing" ],
"type": "string",
"metadata": {
"description": "Select if this template needs a new VNet or will reference an existing VNet"
}
},
"newOrExistingVnetName": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "New or Existing VNet Name"
}
},
"newOrExistingSubnetName": {
"type": "string",
"defaultValue": "Subnet1",
"metadata": {
"description": "Subnet Name"
}
}
},
"variables": {
"publicIPAddressName": "[parameters('customVmName')]",
"vmName": "[parameters('customVmName')]",
"nicName": "[parameters('customVmName')]",
"publicIPAddressType": "Dynamic",
"apiVersion": "2015-06-15",
"vnetID": "[resourceId('myVNET', 'Microsoft.Network/virtualNetworks', parameters('newOrExistingVnetName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/', parameters('newOrExistingSubnetName'))]",
},
"resources": [
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
}
}
},
{
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "[variables('apiVersion')]",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"osDisk": {
"name": "[concat(variables('vmName'),'-osDisk')]",
"osType": "[parameters('osType')]",
"caching": "ReadWrite",
"createOption": "FromImage",
"image": {
"uri": "[parameters('osDiskVhdUri')]"
},
"vhd": {
"uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', parameters('userImageStorageAccountName')), variables('apiVersion')).primaryEndpoints.blob, 'vhds/',variables('vmName'), uniquestring(resourceGroup().id), 'osDisk.vhd')]"
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": "true",
"storageUri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', parameters('userImageStorageAccountName')), variables('apiVersion')).primaryEndpoints.blob)]"
}
}
}
}
]
}

现在使用下面的 powershell 代码来创建您的虚拟机-

$paramList = 
@{
"Params1" = @{ customVmName = "mytestvm" ; userImageStorageAccountName = "myvmstore" ; adminUsername = "adminuser" ; adminPassword = "PassWord123#" ; osDiskVhdUri = "https://myvmstore.blob.core.windows.net/vhds/CustomVHD.vhd" ; dnsLabelPrefix = "mytestvm" ; osType ="Windows" ; vmSize = "Standard_D2" ; newOrExistingVnet = "existing" ; newOrExistingVnetName = "myVPN" ; newOrExistingSubnetName = "mySubnet"}
}

foreach ($keys in $paramList.Keys)
{
$paramvalues = $paramList.$keys
New-AzureRmResourceGroupDeployment -ResourceGroupName "myVMsRG" -TemplateFile "D:\deployvm.json" -TemplateParameterObject $paramValues
}

引用-https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-from-user-image

关于azure - 如何使用 Azure 资源管理器从自定义镜像创建 VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41172441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com