2016-02-10 9 views

Odpowiedz

5

Nie można tego zrobić dosłownie na portalu. Będziesz musiał użyć powershell.

  1. Utwórz ilość miejsca. Na przykład w portalu.

  2. Prześlij VHD na lazur. Aby to zrobić, należy uruchomić następującą linię w PowerShell po zalogowaniu się z Login-AzureRmAccount (zmiany parametrów pomiędzy <> a ścieżka do VHD na twardym dysku):

    Add-AzurermVhd -Destination "https://<StorageAccountName>.blob.core.windows.net/<containerName>/<vhdname>.vhd" -LocalFilePath "D:\Virtual Machines\myharddisk.vhd" -ResourceGroupName "<ResourceGroupName" -Overwrite 
    
  3. Utwórz szablon ARM. Wiele możliwości, co możesz zrobić. Na przykład wybrać szablon z Azure Quickstart templates np 101

Co mam zrobić to:

  • Utworzono nowy projekt w Visual Studio 2015.
  • Wybierz następujący projekt: Chmura -> Azure Resource Group
  • Wybierz następujący szablon: Maszyna wirtualna Windows

  • Zmieniono niektóre parametry i usunięto wszystkie niepotrzebne rzeczy. Teraz należy: Utwórz maszynę wirtualną systemu Windows, używając przesłanego dysku vhd jako dysku twardego. Używa teraz pliku parametrów json, a także niektóre zmienne muszą być ustawione w WindowsVirtualMachine.json To może być refaktoryzowane ofcourse. ale na razie zrobi to, co jest potrzebne.

Dla tej próbki trzeba mieć następującą strukturę katalogów (podobnie jak Visual Studio tworzy go)

ProjectDirectory/Scripts/Deploy-AzureResourceGroup.ps1 
ProjectDirectory/Templates/WindowsVirtualMachine.json 
ProjectDirectory/Templates/WindowsVirtualMachine.parameters.json 

Deploy-AzureResourceGroup.ps1

#Requires -Version 3.0 
#Requires -Module AzureRM.Resources 
#Requires -Module Azure.Storage 

Param(
    [string] [Parameter(Mandatory=$true)] $ResourceGroupLocation, 
    [string] $ResourceGroupName = 'CreateImage',  
    [string] $TemplateFile = '..\Templates\WindowsVirtualMachine.json', 
    [string] $TemplateParametersFile = '..\Templates\WindowsVirtualMachine.parameters.json' 
) 

Import-Module Azure -ErrorAction SilentlyContinue 

try { 
    [Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("VSAzureTools-$UI$($host.name)".replace(" ","_"), "2.8") 
} catch { } 

Set-StrictMode -Version 3 

$OptionalParameters = New-Object -TypeName Hashtable 
$TemplateFile = [System.IO.Path]::Combine($PSScriptRoot, $TemplateFile) 
$TemplateParametersFile = [System.IO.Path]::Combine($PSScriptRoot, $TemplateParametersFile) 


# Create or update the resource group using the specified template file and template parameters file 
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop 

New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) ` 
            -ResourceGroupName $ResourceGroupName ` 
            -TemplateFile $TemplateFile ` 
            -TemplateParameterFile $TemplateParametersFile ` 
            @OptionalParameters ` 
            -Force -Verbose 

WindowsVirtualMachine.json

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": {  
    "dnsNameForPublicIP": { 
     "type": "string", 
     "minLength": 1, 
     "metadata": { 
     "description": "Globally unique DNS Name for the Public IP used to access the Virtual Machine." 
     } 
    } 
    }, 
    "variables": { 
    "OSDiskName": "<vhdNameWithoutExtension>", 
    "vhdStorageContainerName": "<containerName>", 
    "storageAccountName": "<StorageAccountName>", 
    "nicName": "myVMNic", 
    "addressPrefix": "10.0.0.0/16", 
    "subnetName": "Subnet", 
    "subnetPrefix": "10.0.0.0/24", 
    "vhdStorageType": "Standard_LRS", 
    "publicIPAddressName": "myPublicIP", 
    "publicIPAddressType": "Dynamic", 
    "vhdStorageName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]", 
    "vmName": "MyWindowsVM", 
    "vmSize": "Standard_A2", 
    "virtualNetworkName": "MyVNET", 
    "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]", 
    "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]" 
    }, 
    "resources": [ 
    { 
     "type": "Microsoft.Storage/storageAccounts", 
     "name": "[variables('vhdStorageName')]", 
     "apiVersion": "2015-06-15", 
     "location": "[resourceGroup().location]", 
     "tags": { 
     "displayName": "StorageAccount" 
     }, 
     "properties": { 
     "accountType": "[variables('vhdStorageType')]" 
     } 
    }, 
    { 
     "apiVersion": "2015-06-15", 
     "type": "Microsoft.Network/publicIPAddresses", 
     "name": "[variables('publicIPAddressName')]", 
     "location": "[resourceGroup().location]", 
     "tags": { 
     "displayName": "PublicIPAddress" 
     }, 
     "properties": { 
     "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 
     "dnsSettings": { 
      "domainNameLabel": "[parameters('dnsNameForPublicIP')]" 
     } 
     } 
    }, 
    { 
     "apiVersion": "2015-06-15", 
     "type": "Microsoft.Network/virtualNetworks", 
     "name": "[variables('virtualNetworkName')]", 
     "location": "[resourceGroup().location]", 
     "tags": { 
     "displayName": "VirtualNetwork" 
     }, 
     "properties": { 
     "addressSpace": { 
      "addressPrefixes": [ 
      "[variables('addressPrefix')]" 
      ] 
     }, 
     "subnets": [ 
      { 
      "name": "[variables('subnetName')]", 
      "properties": { 
       "addressPrefix": "[variables('subnetPrefix')]" 
      } 
      } 
     ] 
     } 
    }, 
    { 
     "apiVersion": "2015-06-15", 
     "type": "Microsoft.Network/networkInterfaces", 
     "name": "[variables('nicName')]", 
     "location": "[resourceGroup().location]", 
     "tags": { 
     "displayName": "NetworkInterface" 
     }, 
     "dependsOn": [ 
     "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 
     "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 
     ], 
     "properties": { 
     "ipConfigurations": [ 
      { 
      "name": "ipconfig1", 
      "properties": { 
       "privateIPAllocationMethod": "Dynamic", 
       "publicIPAddress": { 
       "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 
       }, 
       "subnet": { 
       "id": "[variables('subnetRef')]" 
       } 
      } 
      } 
     ] 
     } 
    }, 
    { 
     "apiVersion": "2015-06-15", 
     "type": "Microsoft.Compute/virtualMachines", 
     "name": "[variables('vmName')]", 
     "location": "[resourceGroup().location]", 
     "tags": { 
     "displayName": "VirtualMachine" 
     }, 
     "dependsOn": [ 
     "[concat('Microsoft.Storage/storageAccounts/', variables('vhdStorageName'))]", 
     "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 
     ], 
     "properties": { 
     "hardwareProfile": { 
      "vmSize": "[variables('vmSize')]" 
     },  
     "storageProfile": {   
      "osDisk": { 
      "name": "osdisk", 
      "osType": "Windows", 
      "vhd": { 
       "uri": "[concat('http://', variables('storageAccountName'), '.blob.core.windows.net/', variables('vhdStorageContainerName'), '/', variables('OSDiskName'), '.vhd')]" 
      }, 
      "caching": "ReadWrite", 
      "createOption": "Attach" 
      } 
     }, 
     "networkProfile": { 
      "networkInterfaces": [ 
      { 
       "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 
      } 
      ] 
     } 
     }  
    } 
    ] 
} 

WindowsVirtualMachine.parameters.json

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": {  
     "dnsNameForPublicIP": { 
      "value": "<someUniqueNameForYourDnsName>" 
     } 
    } 
} 
  1. Wykonaj skrypt powershell Otwórz polecenia PowerShell, a następnie wykonać skrypt PS1. Musisz tylko przekazać lokalizację, w której chcesz, aby vm zostało utworzone jak: (powinieneś być już zalogowany z Login-AzureRmAccount)

    Przed uruchomieniem zmień parametry w obu plikach json!
    .\Deploy-AzureResourceGroup.ps1 "West Europe"

Rejestrowanie powinien powiedzieć, że VM jest tworzony pomyślnie.

+0

To doskonale spełniło tę funkcję. Wielkie dzięki – naylormat

+0

Jesus, stwórz projekt w visual studio, aby wdrożyć vm na lazur, naprawdę masz dużo czasu na twoich rękach – 4c74356b41

3

Dziś (październik 2016) nadal nie można tego zrobić w nowym portalu.

Jednak dla kompletności: Można to zrobić w starym portalu (https://manage.windowsazure.com):

Kliknij Nowy - Compute - Virtual Machine - Z Galerii. Po lewej stronie wybierz opcję OBRAZY WŁASNE lub MOJE dyski i wybierz dysk VHD, którego chcesz użyć. Postępuj zgodnie z instrukcjami, jak zwykle.

Powiązane problemy