2016-02-10 15 views

Trả lời

5

Nó không thể được thực hiện nghĩa đen trong cổng. Bạn sẽ phải sử dụng PowerShell.

  1. Tạo bộ đếm lưu trữ. Ví dụ trong cổng.

  2. Tải lên VHD to azure. Để làm điều này, hãy chạy dòng sau trong PowerShell sau khi đăng nhập với Login-AzureRmAccount (thay đổi các thông số giữa <> và đường dẫn đến vhd trên đĩa cứng của bạn):

    Add-AzurermVhd -Destination "https://<StorageAccountName>.blob.core.windows.net/<containerName>/<vhdname>.vhd" -LocalFilePath "D:\Virtual Machines\myharddisk.vhd" -ResourceGroupName "<ResourceGroupName" -Overwrite 
    
  3. Tạo một mẫu ARM. Nhiều khả năng bạn có thể làm. Ví dụ chọn một mẫu từ Azure Quickstart templates, ví dụ 101

Những gì tôi đã làm là:

  • Tạo một dự án mới trong Visual Studio 2015.
  • Chọn dự án sau: Cloud -> Azure Resource Group
  • Chọn mẫu sau: Windows Virtual Machine

  • Đã thay đổi một số thông số và xóa tất cả nội dung không cần thiết. Bây giờ nó là gì: Tạo một Máy ảo Windows bằng cách sử dụng vhd đã tải lên dưới dạng đĩa cứng. Hiện tại, nó đang sử dụng tệp tham số json và một số biến phải được đặt trong WindowsVirtualMachine.json Đây có thể là mã nguồn được tái cấu trúc. nhưng bây giờ nó sẽ làm những gì cần thiết.

Đối với mẫu này bạn phải có cấu trúc thư mục sau (giống như Visual Studio tạo ra nó)

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

Triển khai-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. Thực thi kịch bản PowerShell Mở ra một lệnh Powershell và thực thi kịch bản ps1. Bạn chỉ phải chuyển vị trí mà bạn muốn tạo vm như: (bạn nên đã đăng nhập với Login-AzureRmAccount)

    Trước khi chạy thay đổi tham số trong cả hai tệp json!
    .\Deploy-AzureResourceGroup.ps1 "West Europe"

Việc khai thác gỗ nên nói với bạn rằng VM được tạo thành công.

+0

Điều đó đã hoàn thành công việc một cách hoàn hảo. Rất cám ơn – naylormat

+0

chúa giêsu, tạo một dự án trong studio trực quan để triển khai một vm trong xanh, bạn thực sự có rất nhiều thời gian trên đôi tay của bạn – 4c74356b41

3

Hôm nay (tháng 10 năm 2016) nó vẫn không thể được thực hiện trong cổng mới.

Nhưng cho đầy đủ: Bạn có thể làm điều đó trong cổng cũ (https://manage.windowsazure.com):

Nhấn New - Tính toán - Virtual Machine - Từ Gallery. Ở bên trái, hãy chọn HÌNH ẢNH CỦA TÔI hoặc DISKS CỦA TÔI và chọn VHD bạn muốn sử dụng. Làm theo hướng dẫn như bình thường.

Các vấn đề liên quan