Azure的磁盘存储是保存在存储账户中的Page Blob。由于Azure Storage Account的各种限制,在设计VM的磁盘存储时,要符合Azure磁盘存储账户的最佳实践,请参考:http://www.cnblogs.com/hengwei/p/6377598.html
目前Global已经发布了Managed Disk,就是把各种Storage Account的限制封装起来。用户在使用VM Disk时,不用再考虑各种Storage Account的限制。
在非Managed Disk情况下,需要考虑Storage Account:
在Managed Disk情况下,不需要再考虑Storage Account了:
本文将探讨,如何采用Managed Disk创建VM,已经如何将Unmanaged Disk转换成Managed Disk。
一、采用Managed Disk创建VM
-
在Portal上创建Managed Disk的VM
在Portal上创建Managed Disk的VM和创建普通的VM相似,只是在选择存储信息的时候,选择Managed Disk选项就OK了。具体如下:
- VM基本信息
- 选择VM Size
- 配置可选功能
其中和存储相关的亮相:1. Disk,选择Managed Disk,2. 诊断,选择普通的存储账户。
一路确定下,Managed Disk的VM就创建好了。
创建完成后,可以看到VM和其Disk的状态:
在VM内,观察磁盘,
[root@hwmdtest ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 32.2 GB, 32214351872 bytes, 62918656 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000c7b1d Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 62914559 30944256 83 Linux Command (m for help): ^C 进行IOPS的测试: [root@hwmdtest ~]# ./iops.py /dev/sda /dev/sda, 32.21 G, sectorsize=512B, #threads=32, pattern=random: 512 B blocks: 560.3 IO/s, 286.9 kB/s ( 2.3 Mbit/s) 1 kB blocks: 476.4 IO/s, 487.8 kB/s ( 3.9 Mbit/s) 2 kB blocks: 415.7 IO/s, 851.4 kB/s ( 6.8 Mbit/s) 4 kB blocks: 299.1 IO/s, 1.2 MB/s ( 9.8 Mbit/s) 8 kB blocks: 289.4 IO/s, 2.4 MB/s ( 19.0 Mbit/s) 16 kB blocks: 294.2 IO/s, 4.8 MB/s ( 38.6 Mbit/s) 32 kB blocks: 291.1 IO/s, 9.5 MB/s ( 76.3 Mbit/s) 65 kB blocks: 286.5 IO/s, 18.8 MB/s (150.2 Mbit/s) 131 kB blocks: 210.5 IO/s, 27.6 MB/s (220.7 Mbit/s) 262 kB blocks: 192.3 IO/s, 50.4 MB/s (403.2 Mbit/s) 524 kB blocks: 105.2 IO/s, 55.2 MB/s (441.4 Mbit/s) 1 MB blocks: 56.7 IO/s, 59.4 MB/s (475.6 Mbit/s) 2 MB blocks: 31.6 IO/s, 66.2 MB/s (529.6 Mbit/s) 4 MB blocks: 19.4 IO/s, 81.5 MB/s (651.9 Mbit/s) 8 MB blocks: 15.9 IO/s, 133.3 MB/s ( 1.1 Gbit/s) 16 MB blocks: 7.7 IO/s, 129.5 MB/s ( 1.0 Gbit/s)
大约在500IOPS左右。
-
用Azure CLI创建VM
用CLI创建一台CentOS的VM:
az vm create -n hwmdcli --resource-group hwmd --admin-username hengwei
--admin-password xxxxxxxx --authentication-type password
--storage-sku Standard_LRS --size Standard_D1 --subnet default
--vnet-name hwmd-vnet --image CentOS {- Finished .. "fqdns": "", "id": "/subscriptions/xxxx/resourceGroups/hwmd/providers/Microsoft.Compute/virtualMachines/hwmdcli", "location": "eastasia", "macAddress": "00-0D-3A-81-C9-7F", "powerState": "VM running", "privateIpAddress": "10.1.0.5", "publicIpAddress": "52.229.175.38", "resourceGroup": "hwmd" }
二、磁盘的转换
-
VM从Unmanaged Disk转换成Managed Disk
创建一台Unmanaged Disk的VM:hwumd。然后用Azure CLI对VM进行转换:
-
Deallocate VM
az vm deallocate -g hwmd -n hwumd {/ Finished .. "endTime": "2017-06-12T08:07:49.459038+00:00", "error": null, "name": "222f9f03-b23e-4359-ba07-4195840b68de", "startTime": "2017-06-12T08:05:48.453632+00:00", "status": "Succeeded" }
-
Convert Disk
az vm convert -g hwmd -n hwumd {| Finished .. "endTime": "2017-06-12T08:14:23.519972+00:00", "error": null, "name": "cbe7b1ae-339d-415a-b4e7-c93c37ea7872", "startTime": "2017-06-12T08:13:31.748733+00:00", "status": "Succeeded" }
- 此时可以看到Disk已经转换成Managed Disk:
-
az vm show -g hwmd -n hwumd { ...... "osDisk": { "caching": "ReadWrite", "createOption": "fromImage", "diskSizeGb": 31, "encryptionSettings": null, "image": null, "managedDisk": { "id": "/subscriptions/……/resourceGroups/hwmd/providers/Microsoft.Compute/disks/hwumd_hwumd", "resourceGroup": "hwmd", "storageAccountType": "Standard_LRS" }, "name": "hwumd_hwumd", "osType": "Linux", "vhd": null } }, ...... }
-
2. 普通的Managed Disk转换成Premium的Managed Disk
-
-
首先Deallocate VM
az vm deallocate -g hwmd -n hwumd {| Finished .. "endTime": "2017-06-12T08:29:53.044297+00:00", "error": null, "name": "629d3b3e-78f7-4fb4-b6bb-aa4785c71123", "startTime": "2017-06-12T08:27:46.205233+00:00", "status": "Succeeded" }
-
Resize VM
az vm resize -g hwmd -n hwumd --size Standard_DS2 {- Finished .. …… "osDisk": { "caching": "ReadWrite", "createOption": "fromImage", "diskSizeGb": null, "encryptionSettings": null, "image": null, "managedDisk": { "id": "/subscriptions/……/resourceGroups/hwmd/providers/Microsoft.Compute/disks/hwumd_hwumd", "resourceGroup": "hwmd", "storageAccountType": null }, "name": "hwumd_hwumd", "osType": "Linux", "vhd": null } }, …… }
-
改变Disk的类型到Premium
az disk update -g hwmd -n hwumd_hwumd --sku Premium_LRS { "accountType": "Premium_LRS", "creationData": { "createOption": "Import", "imageReference": null, "sourceResourceId": null, "sourceUri": "https://hwmddiag954.blob.core.windows.net/vhds/hwumd20170612152358.vhd", "storageAccountId": null }, "diskSizeGb": 31, "encryptionSettings": null, "id": "/subscriptions/……/resourceGroups/hwmd/providers/Microsoft.Compute/disks/hwumd_hwumd", "location": "eastasia", "name": "hwumd_hwumd", "osType": null, "ownerId": "/subscriptions/……/resourceGroups/hwmd/providers/Microsoft.Compute/virtualMachines/hwumd", "provisioningState": "Succeeded", "resourceGroup": "hwmd", "tags": null, "timeCreated": "2017-06-12T08:13:37.322385+00:00", "type": "Microsoft.Compute/disks" }
-
重新启动VM
此时VM已经升级到DS2的高级存储类型的VM了。
-
三. 总结
通过简单的Azure Cli,可以把磁盘转换成Managed Disk。转成Managed Disk的好处是不需要再关心存储账户的各种限制。
另外,VM变成Premium的DS系列后,可以挂载普通或者高级的磁盘。实现下图的各种挂载磁盘选项: