1. 程式人生 > >把ASM下的HDD VM轉換成ARM下Managed Disk的SSD VM

把ASM下的HDD VM轉換成ARM下Managed Disk的SSD VM

cor commit compute pre ndt mysq deploy nac 通過

在ASM下,要把HDD的VM轉換成SSD的VM步驟非常復雜。需要手工把Disk從普通存儲賬戶復制到高級存儲賬戶。再通過這個Disk創建VM。

目前在有了ASM到ARM的遷移工具,以及Managed Disk後,這個工作就簡單了。

下面將介紹如何實現從ASM的HDD VM遷移到ARM模式下的Managed Disk的SSD VM。

一 ASM下的VM遷移到ARM下

1 Cli版本

這個工作,可以用powershell或Azure xplate cli,我采用的cli:

C:\Users\hengwei>azure
info:             _    _____   _ ___ ___
info: /_\ |_ / | | | _ \ __| info: _ ___/ _ \__/ /| |_| | / _|___ _ _ info: (___ /_/ \_\/___|\___/|_|_\___| _____) info: (_______ _ _) _ ______ _)_ _ info: (______________ _ ) (___ _ _) info: info: Microsoft Azure: Microsofts Cloud Platform info: info: Tool version 0.10
.13

版本是0.10.13.

2 查看VNet和VM信息

C:\Users\hengwei>azure network vnet list
info:    Executing command network vnet list
+ Looking up the virtual network sites
data:    Name    Location    Affinity group  State    Address space   Subnets count  VPN Gateway address
data:    ------  ----------  --------------  -------  --------------  -------------  -------------------
data:    hwfgfw  China East                  Created  
10.0.0.0/8 1 data: hws2p China East Created 192.168.1.0/24 1 info: network vnet list command OK

C:\Users\hengwei>azure vm list
info:    Executing command vm list
+ Getting virtual machines
data:    Name        Status              Location    DNS Name                     IP Address
data:    ----------  ------------------  ----------  ---------------------------  -----------
data:    mp-ngfwf-1  StoppedDeallocated  China East  mp-ngfwf-1.chinacloudapp.cn
data:    hws2p       ReadyRole           China East  hws2p01.chinacloudapp.cn     192.168.1.4
info:    vm list command OK

3 遷移

遷移分三步:

C:\Users\hengwei>azure network vnet  validate-migration hws2p
info:    Executing command network vnet validate-migration
data:    Information                     : Virtual Network hws2p is eligible for migration.
data:    Information                     : Deployment hws2p in Cloud Service hws2p01 is eligible for migration.
data:    Information                     : VM hws2p in Deployment hws2p within Cloud Service hws2p01 is eligible for migration.
info:    network vnet validate-migration command OK

C:\Users\hengwei>azure network vnet prepare-migration hws2p
info:    Executing command network vnet prepare-migration
info:    network vnet prepare-migration command OK

C:\Users\hengwei>azure network vnet commit-migration hws2p
info:    Executing command network vnet commit-migration
info:    network vnet commit-migration command OK

此時Vnet和VM都已經遷移到ARM模式下了。

二 把ARM模式下的VM轉換成Managed Disk

1 CLI版本

這個工作的Azure采用的是Azure CLI2.0版本

[email protected]:~# az --version
azure-cli (2.0.7)

2 查看VM

[email protected]:~# az vm list -o table
Name       ResourceGroup     Location
---------  ----------------  ----------
hwmdt      HWNAVS            chinanorth
hwcisco    CISCOROUTER       chinaeast
hwazcopy   HWAZCOPY          chinaeast
hwmt       HWMT              chinaeast
hwmt02     HWMT              chinaeast
hws2p      HWS2P01-MIGRATED  chinaeast
hwmysql01  HWWAF             chinaeast
hwwaf02    HWWAF             chinaeast
hwwaf03    HWWAF             chinaeast

3 轉換Disk

[email protected]:~# az vm convert -n hws2p -g hws2p01-migrated
 | Running ..
{| Finished ..
  "endTime": "2017-06-23T10:45:42.174661+00:00",
  "error": null,
  "name": "fa343688-ba91-447b-b531-5ff983866f9a",
  "startTime": "2017-06-23T10:44:57.245702+00:00",
  "status": "Succeeded"
}

此時,Disk已經是Managed Disk了。

4 查看disk信息

[email protected]:~# az disk list -o table
AccountType      DiskSizeGb  Location    Name                                    OwnerId                                                                                                                                ProvisioningState    ResourceGroup     TimeCreated                       OsType
-------------  ------------  ----------  --------------------------------------  -------------------------------------------------------------------------------------------------------------------------------------  -------------------  ----------------  --------------------------------  --------
Standard_LRS             31  chinaeast   hws2p_hws2p-hws2p-0-201706231030480950  /subscriptions/xxxx/resourceGroups/hws2p01-Migrated/providers/Microsoft.Compute/virtualMachines/hws2p  Succeeded            HWS2P01-MIGRATED  2017-06-23T10:45:15.240624+00:00

三 把VM的型號轉換成DS系列,把Disk轉換成SSD

1 VM型號轉換

[email protected]:~# az vm resize -n hws2p -g hws2p01-migrated --size Standard_DS1
 - Running ..

 \ Running ..
{/ Finished ..
  "availabilitySet": null,
  "diagnosticsProfile": null,
  "hardwareProfile": {
    "vmSize": "Standard_DS1"
  },
  "id": "/subscriptions/xxxx/resourceGroups/hws2p01-migrated/providers/Microsoft.Compute/virtualMachines/hws2p",
  "instanceView": null,
  "licenseType": null,
  "location": "chinaeast",
  "name": "hws2p",
  "networkProfile": {
    "networkInterfaces": [
      {
        "id": "/subscriptions/xxxx/resourceGroups/hws2p01-Migrated/providers/Microsoft.Network/networkInterfaces/hws2p-PrimaryNic",
        "primary": true,
        "resourceGroup": "hws2p01-Migrated"
      }
    ]
  },
  "osProfile": null,
  "plan": null,
  "provisioningState": "Succeeded",
  "resourceGroup": "hws2p01-migrated",
  "resources": null,
  "storageProfile": {
    "dataDisks": [],
    "imageReference": null,
    "osDisk": {
      "caching": "ReadWrite",
      "createOption": "attach",
      "diskSizeGb": null,
      "encryptionSettings": null,
      "image": null,
      "managedDisk": {
        "id": "/subscriptions/xxxx/resourceGroups/hws2p01-Migrated/providers/Microsoft.Compute/disks/hws2p_hws2p-hws2p-0-201706231030480950",
        "resourceGroup": "hws2p01-Migrated",
        "storageAccountType": null
      },
      "name": "hws2p_hws2p-hws2p-0-201706231030480950",
      "osType": "Linux",
      "vhd": null
    }
  },
  "tags": null,
  "type": "Microsoft.Compute/virtualMachines",
  "vmId": "3d7b7a7f-6271-4fa5-9f94-88711eb9db43"
}

2 Disk轉換成SSD

az disk update -g hws2p01-Migrated -n hws2p_hws2p-hws2p-0-201706231030480950 --sku Premium_LRS
{
  "accountType": "Premium_LRS",
  "creationData": {
    "createOption": "Import",
    "imageReference": null,
    "sourceResourceId": null,
    "sourceUri": "https://2mportalvhdsg0nfxclb1p0q.blob.core.chinacloudapi.cn/vhds/hws2p01-hws2p-2017-06-23.vhd",
    "storageAccountId": null
  },
  "diskSizeGb": 31,
  "encryptionSettings": null,
  "id": "/subscriptions/xxxx/resourceGroups/hws2p01-Migrated/providers/Microsoft.Compute/disks/hws2p_hws2p-hws2p-0-201706231030480950",
  "location": "chinaeast",
  "name": "hws2p_hws2p-hws2p-0-201706231030480950",
  "osType": null,
  "ownerId": "/subscriptions/xxxx/resourceGroups/hws2p01-Migrated/providers/Microsoft.Compute/virtualMachines/hws2p",
  "provisioningState": "Succeeded",
  "resourceGroup": "hws2p01-Migrated",
  "tags": null,
  "timeCreated": "2017-06-23T10:45:15.240624+00:00",
  "type": "Microsoft.Compute/disks"
}

3 查看Disk信息

[email protected]:~# az disk list -o table
AccountType      DiskSizeGb  Location    Name                                    OwnerId                                                                                                                                ProvisioningState    ResourceGroup     TimeCreated                       OsType
-------------  ------------  ----------  --------------------------------------  -------------------------------------------------------------------------------------------------------------------------------------  -------------------  ----------------  --------------------------------  --------
Premium_LRS              31  chinaeast   hws2p_hws2p-hws2p-0-201706231030480950  /subscriptions/xxxx/resourceGroups/hws2p01-Migrated/providers/Microsoft.Compute/virtualMachines/hws2p  Succeeded            HWS2P01-MIGRATED  2017-06-23T10:45:15.240624+00:00

已經是SSD的硬盤了。

四總結

通過ASM->ARM的轉換工具,可以方便的把ASM的VM遷移到ARM。

通過命令行方便的把disk遷移到Managed Disk。

在ARM中,可以在關機的狀態下resize VM到ssd類型的機器。

通過命令行,方便的把HDD的Disk轉換成SSD的Disk。

把ASM下的HDD VM轉換成ARM下Managed Disk的SSD VM