本文介紹使用 Azure Resource Manager 模板預(yù)配虛擬機(jī)時(shí)托管與非托管磁盤之間的差異。 這有助于將現(xiàn)有模板從使用非托管磁盤更新為使用托管磁盤。 我們將使用101-vm-simple-windows模板作為參考指南。 如果想要直接對(duì)它們進(jìn)行比較,可以同時(shí)看到使用托管磁盤的模板和以前使用非托管磁盤的版本。
非托管磁盤模板的格式設(shè)置
首先,了解如何部署非托管磁盤。 創(chuàng)建非托管磁盤時(shí),需要一個(gè)存儲(chǔ)帳戶用來保留 VHD 文件。 可新建一個(gè)存儲(chǔ)帳戶或使用已存在的帳戶。 本文將說明如何新建存儲(chǔ)帳戶。 為實(shí)現(xiàn)此目的,資源塊中需要如下所示的存儲(chǔ)帳戶資源。
復(fù)制
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "2016-01-01",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"properties": {}
}
在虛擬機(jī)對(duì)象內(nèi),存儲(chǔ)帳戶上需要具有一個(gè)依賴項(xiàng),確保它創(chuàng)建在虛擬機(jī)之前。 隨后在storageProfile部分中,指定 VHD 位置的完整 URI,用于引用存儲(chǔ)帳戶并且 OS 磁盤和任何數(shù)據(jù)磁盤都需要它。
復(fù)制
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {...},
"osProfile": {...},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"osDisk": {
"name": "osdisk",
"vhd": {
"uri": "[concat(reference(resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))).primaryEndpoints.blob, 'vhds/osdisk.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
},
"dataDisks": [
{
"name": "datadisk1",
"diskSizeGB": 1023,
"lun": 0,
"vhd": {
"uri": "[concat(reference(resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))).primaryEndpoints.blob, 'vhds/datadisk1.vhd')]"
},
"createOption": "Empty"
}
]
},
"networkProfile": {...},
"diagnosticsProfile": {...}
}
}
托管磁盤模板的格式設(shè)置
若使用 Azure 托管磁盤,磁盤將成為頂級(jí)資源,不再需要用戶創(chuàng)建存儲(chǔ)帳戶。 托管磁盤在2016-04-30-previewAPI 版本中首次公開,并在所有后續(xù) API 版本中可用,現(xiàn)在是默認(rèn)磁盤類型。 以下各部分將講解默認(rèn)設(shè)置,并詳細(xì)介紹如何進(jìn)一步自定義磁盤。
Note
建議使用2016-04-30-preview以后的 API 版本,因?yàn)樵?016-04-30-preview和2017-03-30之間存在重大更改。
默認(rèn)托管磁盤設(shè)置
若要?jiǎng)?chuàng)建帶托管磁盤的 VM,無需再創(chuàng)建存儲(chǔ)帳戶資源,可如下所示更新虛擬機(jī)資源。 特別要注意,apiVersion反映2017-03-30,并且osDisk和dataDisks不再為 VHD 引用特定 URI。 如果部署時(shí)未指定其他屬性,磁盤將使用標(biāo)準(zhǔn) LRS 存儲(chǔ)。 如果未指定任何名稱,則 OS 磁盤采用格式_OsDisk_1_,每個(gè)數(shù)據(jù)磁盤采用格式_disk<#>_。 默認(rèn)情況下,Azure 磁盤加密處于禁用狀態(tài);緩存對(duì)于 OS 磁盤為“讀/寫”,對(duì)于數(shù)據(jù)磁盤則為“無”。 你可能會(huì)注意到以下示例中仍然存在一個(gè)存儲(chǔ)帳戶依賴項(xiàng),但這僅用于診斷的存儲(chǔ),磁盤存儲(chǔ)并不需要。
復(fù)制
{
"apiVersion": "2017-03-30",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {...},
"osProfile": {...},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"lun": 0,
"createOption": "Empty"
}
]
},
"networkProfile": {...},
"diagnosticsProfile": {...}
}
}
使用頂級(jí)托管磁盤資源
在虛擬機(jī)對(duì)象中指定磁盤配置的另一種選擇是,創(chuàng)建頂級(jí)磁盤資源,并在虛擬機(jī)創(chuàng)建過程中進(jìn)行附加。 例如,可如下所示創(chuàng)建磁盤資源作為數(shù)據(jù)磁盤使用。
復(fù)制
{
"type": "Microsoft.Compute/disks",
"name": "[concat(variables('vmName'),'-datadisk1')]",
"apiVersion": "2017-03-30",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard_LRS"
},
"properties": {
"creationData": {
"createOption": "Empty"
},
"diskSizeGB": 1023
}
}
隨后可在該 VM 對(duì)象內(nèi)引用此要附加的磁盤對(duì)象。 創(chuàng)建 VM 時(shí),通過指定在managedDisk屬性中創(chuàng)建的托管磁盤的資源 ID,允許附加磁盤。 請(qǐng)注意,VM 資源的apiVersion設(shè)置為2017-03-30。 另請(qǐng)注意,我們已在磁盤資源上創(chuàng)建了一個(gè)依賴項(xiàng),確保它在創(chuàng)建 VM 之前已成功創(chuàng)建。
復(fù)制
{
"apiVersion": "2017-03-30",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]",
"[resourceId('Microsoft.Compute/disks/', concat(variables('vmName'),'-datadisk1'))]"
],
"properties": {
"hardwareProfile": {...},
"osProfile": {...},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
},
"dataDisks": [
{
"lun": 0,
"name": "[concat(variables('vmName'),'-datadisk1')]",
"createOption": "attach",
"managedDisk": {
"id": "[resourceId('Microsoft.Compute/disks/', concat(variables('vmName'),'-datadisk1'))]"
}
}
]
},
"networkProfile": {...},
"diagnosticsProfile": {...}
}
}
通過使用托管磁盤的 VM 創(chuàng)建托管可用性集
若要通過使用托管磁盤的 VM 創(chuàng)建托管可用性集,請(qǐng)將sku對(duì)象添加到可用性集資源中,并將name屬性設(shè)置為Aligned。 這可確保每個(gè) VM 的磁盤彼此充分隔離,避免出現(xiàn)單點(diǎn)故障。 另請(qǐng)注意,可用性集資源的apiVersion設(shè)置為2017-03-30。
復(fù)制
{
"apiVersion": "2017-03-30",
"type": "Microsoft.Compute/availabilitySets",
"location": "[resourceGroup().location]",
"name": "[variables('avSetName')]",
"properties": {
"PlatformUpdateDomainCount": 3,
"PlatformFaultDomainCount": 2
},
"sku": {
"name": "Aligned"
}
}
其他方案和自定義項(xiàng)
若要查找有關(guān) REST API 規(guī)范的完整信息,請(qǐng)查看創(chuàng)建托管磁盤 REST API 文檔。 該文檔介紹了其他方案以及可通過模板部署提交到 API 的默認(rèn)值和可接受的值。
后續(xù)步驟
有關(guān)使用托管磁盤的完整模板,請(qǐng)?jiān)L問以下 Azure 快速入門存儲(chǔ)庫鏈接。
請(qǐng)?jiān)L問文章Azure 托管磁盤概述,詳細(xì)了解托管磁盤。
訪問文檔Microsoft.Compute/virtualMachines 模板參考,查看虛擬機(jī)資源的模板參考文檔。
訪問文檔Microsoft.Compute/disks 模板參考,查看虛擬機(jī)資源的模板參考文檔。
立即訪問http://market.azure.cn