【问题标题】:How to create data disks for azure virtual machines?如何为 Azure 虚拟机创建数据磁盘?
【发布时间】:2017-07-21 19:10:31
【问题描述】:

我在使用以下 json 模板创建虚拟机时向虚拟机添加了多个数据磁盘。

"variables": {  
"diskArray": [  
{  
"name": "datadisk1",
"lun": 0,   
"vhd": {  
"uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/','datadisk1.vhd')]"  
        },  
        "createOption": "Empty",    
        "caching": "ReadWrite",    
        "diskSizeGB": 300    
      },    
      {    
        "name": "datadisk2",
        "lun": 1,
        "vhd": {
          "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk2.vhd')]"    
        },  
        "createOption": "Empty",    
        "caching": "ReadWrite",    
        "diskSizeGB": 200  
      },  
      {   
        "name": "datadisk3",  
        "lun": 2,  
        "vhd": {  
          "uri": "[concat('http://', variables('storageAccountName'),'.blob.core.windows.net/vhds/', 'datadisk3.vhd')]"  
        },  
        "createOption": "Empty",  
        "caching": "ReadWrite",  
        "diskSizeGB": 100  
      }  
]    
  },    
.....    
.....   
"resources": [  
    {  
      "apiVersion": "2015-06-15",  
      "type": "Microsoft.Compute/virtualMachines",  
      "name": "[concat(parameters('VmPrefix'), copyindex(1))]",  
      "copy": {  
        "name": "Datanode",  
        "count": "[variables('vmcount')]"  
      },  
      "location": "[resourceGroup().location]",  
      "properties": {  
         ......  
         ......  
        "storageProfile": {  
          "imageReference": {  
            ........  
          },  
          "dataDisks":   "[take(variables('diskArray'),parameters('numDataDisks'))]",  
          "osDisk": {  
            .......  
          }  
        }  
    }  
}  
]  

此代码在创建单个虚拟机时工作正常,但在创建多个虚拟机时,机器无法创建。这是因为为第一台机器的数据磁盘创建的 vhd 与其他机器相同。

有没有办法创建具有不同名称的 vhd? 尝试传递副本索引,但不起作用。

【问题讨论】:

    标签: json powershell azure msdn


    【解决方案1】:

    当然有,我将粘贴一个指向模板的链接并解释它是如何工作的。这是link

    因此,为了做到这一点,您必须将 copyindex(或类似的东西)添加到磁盘名称中,其中一种方法是使用嵌套模板,该模板将返回一个包含磁盘的对象,并且在调用模板时,您可以使用 copyindex 作为它的参数。

    This is 在其中创建嵌套部署以创建磁盘对象。
    here 你使用输出来创建磁盘。

    【讨论】:

    • 在运行上述示例 json 时,我收到以下错误:New-AzureRmResourceGroupDeployment:对象引用未设置为对象的实例。在 line:1 char:13 + $response = New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroup ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ + CategoryInfo : CloseError: (:) [New-AzureRmResourceGroupDeployment], NullReferenceException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand
    • 但是虚拟机是用数据盘正确创建的。
    • 好吧,我不确定你做错了什么,对我来说这很好,如果这符合你的要求,请接受这个作为答案;)我刚刚测试了这个部署它工作得很好。 New-AzureRmResourceGroupDeployment -Name test -ResourceGroupName zxc -TemplateUri https://raw.githubusercontent.com/4c74356b41/armotron/master/ml-vm-ml-dd.json
    • 将 Azure power-shell 模块更新到最新版本 3.6.0 解决了我的问题,我已经将此标记为答案,因为已成功使用数据磁盘创建了虚拟机。
    猜你喜欢
    • 2014-09-09
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    相关资源
    最近更新 更多