【问题标题】:Azure ARM: Create Linux VM from storage account using access keysAzure ARM:使用访问密钥从存储帐户创建 Linux VM
【发布时间】:2021-04-06 20:28:17
【问题描述】:

是否可以使用 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 

【问题讨论】:

    标签: azure azure-resource-manager


    【解决方案1】:

    如果要使用自己的 vhd 文件创建 Vm,可以使用 VHD 文件创建 Azure 托管映像,然后使用该映像创建 VM。更多详情请参考here和这里

    例如

    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
                }
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-06
      • 2019-07-28
      • 1970-01-01
      • 2020-08-21
      • 2018-02-09
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多