首页 > 解决方案 > Azure ARM:使用访问密钥从存储帐户创建 Linux VM

问题描述

是否可以使用 ARM 模板在 Azure 中创建虚拟机(Ubuntu Linux),我将在其中将 .vhd 文件存储在存储帐户中,并且在单独的 Azure 资源组(客户端)中部署时,将使用 access 访问存储帐户部署 VM 的密钥。

我使用以下命令将 VHD 复制到我的 RG 中的存储帐户。

az storage blob copy ​ start ​ --destination-blob​ $destinationVHDFileName
--destination-container​ $storageContainerName ​ --account-name​ $storageAccountName
--account-key​ $storageAccountKey ​ --source-uri​ $sas 

标签: azureazure-resource-manager

解决方案


如果要使用自己的 vhd 文件创建 Vm,可以使用 VHD 文件创建 Azure 托管映像,然后使用该映像创建 VM。有关更多详细信息,请参阅此处和此处

例如

  1. 创建 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"
            }
        }
    ]
}
  1. 创建虚拟机
{
    "$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
            }
        }
    ]
}

推荐阅读