天天看點

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

在Azure China用自定義鏡像建立Azure VM Scale Set

在此感謝世紀互聯的工程師Johnny Lee和Lan,你們給了我很大的幫助。因為Azure China的官網沒有給出完整的步驟,是以我在這裡把完整的步驟總結一下,希望對大家有所幫助。

Azure Global有一篇介紹如何用自定義鏡像建立Azure VM Scale Set的文章。因為裡面用到的"type": "Microsoft.Compute/images" 部分,我自己沒在Azure China上跑通,是以這一部分靠其他大神繼續探索吧。

https://docs.microsoft.com/zh-cn/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-mvss-custom-image

好的,現在讓我們看看如何在Azure China裡用自定義Image 建立 Azure VM Scale Set

第一步:從Azure Portal建立虛拟機

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

虛拟機建立好了,Azure 除了幫我們建立虛拟機之外,還建立了許多别的東西

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

第二步 : 連接配接到虛拟機,做一些自己需要的定制化,比如,我在根目錄下建一個txt檔案

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set
在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

第三步: 在虛拟機上運作SysPrep.exe

可參照官網文檔,在此不再贅述了,唯一要強調的是不要忘記勾選“Generalize” checkbox。

https://www.azure.cn/documentation/articles/virtual-machines-windows-generalize-vhd/

第四步 : 等虛拟機完全關機後,運作PowerShell指令,建立虛拟機鏡像

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

可參考官方文檔 https://www.azure.cn/documentation/articles/virtual-machines-windows-capture-image/,我自己用的指令是

Login-AzureRmAccount –EnvironmentName AzureChinaCloud

Select-AzureRmSubscription -SubscriptionId YourSubscriptionId

Stop-AzureRmVM -ResourceGroupName 'liqiangtest' -Name 'imagevm'

Set-AzureRmVM -ResourceGroupName 'liqiangtest' -Name 'imagevm' -Generalized

Save-AzureRmVMImage -ResourceGroupName 'liqiangtest' -VMName 'imagevm' -DestinationContainerName 'myvhds' -VHDNamePrefix 'template' -Path d:\SampleTemplate.json

第五步:等上述指令運作完之後,打開d:\SampleTemplate.json,就可以看到那個鏡像的Url了。

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

第六步 : 通過VS2017釋出VM Scale Set

建立一個ARG項目

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

選擇官方的模闆

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

通路https://github.com/dafoyiming/azure-quick-start-china/tree/meat/201-vmss-windows-customerimage-autoscale-existing-vnet,把azuredeploy.json和azuredeploy.parameters.json下載下傳下來,并用他們的内容并替換WindowsVirtualMachineScaleSet.json和WindowsVirtualMachineScaleSet.parameters.json的内容

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

 輕按兩下WindowsVirtualMachineScaleSet.parameters.json,填入必須的内容

那個Url,就是我們前面在d:\SampleTemplate.json裡那個Vhd的Url。Subnet的話可以用我們在建立虛拟機時建立的虛拟網。SubSiteResourceId的話,可以用虛拟網的ResourceId拼上subnets/default(因為我的子網名叫default)

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set
在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set
在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

右擊Project,點選Deploy-》New-》Deploy,然後就靜靜等待吧,20分鐘,Maybe

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

顯示我們建立成功。回到Azure Portal,在新建立的VM Scale Set中找到Public IP。然後用遠端桌面連接配接public ip:50000,在我的case中連接配接139.219.232.229:50000。端口50000表示第一個Instance,50001是第二個instance,以此類推。。。

注:連不上的話,不要着急,有可能你的VM Scale Set正在updating,等幾分鐘後再連。或者連一下50001試試。

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set
在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

連上後,打開C槽,可以看到有一個建立的Txt檔案已經存在了。Happy Ending。。。

在Azure China用自定義鏡像建立Azure VM Scale Set在Azure China用自定義鏡像建立Azure VM Scale Set

轉載于:https://www.cnblogs.com/huojian32/p/6928974.html