《Windows Azure Platform 系列文章目录》
在很多时候,我们需要根据现有VHD文件,创建ARM VM。在这里笔者简单介绍一下相关的Azure PowerShell
这里介绍如何通过现有Linux OS Disk文件,新建ARM Linux VM。
请大家先安装Azure PowerShell:
https://azure.microsoft.com/zh-cn/downloads/
运行以下命令:
Add-AzureRmAccount -EnvironmentName AzureChinaCloud Select-AzureRmSubscription -SubscriptionName 'My Subscription'| Select-AzureRmSubscription #需要手动创建虚拟网络
$resourceGroupName = "MyResourceGroup"
$virtualNetworkName = "MyVNet" $locationName = "China East"
$virtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Name $virtualNetworkName #需要指定虚拟机的OS Disk VHD位置
$destinationVhd = "https://myvm.blob.core.chinacloudapi.cn/vhds/MQBJVM0220170425113153.vhd" #新建network interface
#$publicIPAddress = "MyNewPIP"
#$publicIp = New-AzureRmPublicIpAddress -Name $publicIPAddress -ResourceGroupName $ResourceGroupName -Location $locationName -AllocationMethod Dynamic #虚拟机名称
$vmName = "Web-VM01"
$vmSize = "Standard_D2_V2" #新建Network Security Group:
# Create an inbound network security group rule for port 3389
$nsgRuleSSH = New-AzureRmNetworkSecurityRuleConfig -Name default-allow-ssh -Protocol Tcp `
-Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * `
-DestinationPortRange 22 -Access Allow $nsgName = $vmName + "-nsg" # Create a network security group
$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroupName -Location $locationName -Name $nsgName -SecurityRules $nsgRuleSSH #虚拟机创建虚拟网络的第一个子网里
$nicName = $vmName + "-nic"
$networkInterface = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName -Name $nicName -Location $locationName -SubnetId $virtualNetwork.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id #新建可用性组
$avbSetName = "Web-AvbSet"
#$availabilitySet = New-AzureRmAvailabilitySet -ResourceGroupName $resourceGroupName -Name $avbSetName -Location $locationName $osDiskName = $vmName + "-OSDisk" $vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize -AvailabilitySetID $availabilitySet.Id
$vmConfig = Set-AzureRmVMOSDisk -VM $vmConfig -Name $osDiskName -VhdUri $destinationVhd -CreateOption Attach -Linux
$vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $networkInterface.Id #创建新的Azure虚拟机
$vm = New-AzureRmVM -VM $vmConfig -Location $locationName -ResourceGroupName $resourceGroupName