Azure ARM:使用访问密钥从存储帐户创建 Linux VM
Azure ARM: Create Linux VM from storage account using access keys
是否可以使用 ARM 模板在 Azure 中创建虚拟机 (Ubuntu Linux),我将在其中将 .vhd 文件存储在存储帐户中,同时部署在单独的 Azure 中资源组(客户端)将使用访问密钥访问存储帐户以部署 VM。
我使用以下命令将 VHD 复制到我的 RG 中的存储帐户。
az storage blob copy start --destination-blob $destinationVHDFileName
--destination-container $storageContainerName --account-name $storageAccountName
--account-key $storageAccountKey --source-uri $sas
如果要使用自己的 vhd 文件创建 Vm,可以使用 VHD 文件创建 Azure 托管映像,然后使用该映像创建 VM。更多详情请参考here和此处
例如
- 创建 Azure 托管映像
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"images_testimage_name": {
"defaultValue": "testimage1",
"type": "String"
},
"blobUri": {
"defaultValue": "<your vhd file url>",
"type": "String"
},
"location": {
"defaultValue": "",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Compute/images",
"apiVersion": "2019-07-01",
"name": "[parameters('images_testimage_name')]",
"location": "[parameters('location')]",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"diskSizeGB": 30,
"blobUri": "[parameters('blobUri')]",
"caching": "ReadWrite",
"storageAccountType": "Premium_LRS"
},
"dataDisks": [],
"zoneResilient": true
},
"hyperVGeneration": "V1"
}
}
]
}
- 创建虚拟机
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {},
"resources": [
... other resource
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2020-06-01",
"location": "[parameters('location')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"imageReference": {
"id": "<the resource id of the image you create in step1>"
}
},
... other configurations
}
}
]
}
是否可以使用 ARM 模板在 Azure 中创建虚拟机 (Ubuntu Linux),我将在其中将 .vhd 文件存储在存储帐户中,同时部署在单独的 Azure 中资源组(客户端)将使用访问密钥访问存储帐户以部署 VM。
我使用以下命令将 VHD 复制到我的 RG 中的存储帐户。
az storage blob copy start --destination-blob $destinationVHDFileName
--destination-container $storageContainerName --account-name $storageAccountName
--account-key $storageAccountKey --source-uri $sas
如果要使用自己的 vhd 文件创建 Vm,可以使用 VHD 文件创建 Azure 托管映像,然后使用该映像创建 VM。更多详情请参考here和此处
例如
- 创建 Azure 托管映像
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"images_testimage_name": {
"defaultValue": "testimage1",
"type": "String"
},
"blobUri": {
"defaultValue": "<your vhd file url>",
"type": "String"
},
"location": {
"defaultValue": "",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Compute/images",
"apiVersion": "2019-07-01",
"name": "[parameters('images_testimage_name')]",
"location": "[parameters('location')]",
"properties": {
"storageProfile": {
"osDisk": {
"osType": "Linux",
"osState": "Generalized",
"diskSizeGB": 30,
"blobUri": "[parameters('blobUri')]",
"caching": "ReadWrite",
"storageAccountType": "Premium_LRS"
},
"dataDisks": [],
"zoneResilient": true
},
"hyperVGeneration": "V1"
}
}
]
}
- 创建虚拟机
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {},
"resources": [
... other resource
{
"name": "[parameters('virtualMachineName')]",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2020-06-01",
"location": "[parameters('location')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('virtualMachineSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
"imageReference": {
"id": "<the resource id of the image you create in step1>"
}
},
... other configurations
}
}
]
}