Create Linux VM form
##how to creat Linux VM form ImageOS # 指定创建虚拟机的登陆账号 $username = "usrname"; $passwd = ConvertTo-SecureString "password" -AsPlainText -Force; $cred = New-Object System.Management.Automation.PSCredential($username, $passwd); # 指定虚拟机的创建区域,资源组,创建使用的存储账号,使用的自定义Image的URL $location = "China East"; $resourceGroup = "aomnew01"; $storageAccount = "storageaccout"; # 下面换成刚刚捕获的映像的vhd的URL $sourceImageUri = "https://xxx.blob.core.chinacloudapi.cn/system/Microsoft.Compute/Images/imagecontainer/AOMNewImage-osDisk.8678ae2d-9269-43d1-9fe3-8777473e9f0d.vhd"; # 指定虚拟机名称(由于是批量创建,所以指定一个名称模板),虚拟机尺寸,使用映像创建,OS磁盘缓存方式 $vmNameBase = "ImageVM"; $vmSize = "Standard_D2_v2"; $osCreatenOption = "FromImage"; $osDiskCaching = "ReadWrite"; # 指定IP对应的dns名称(可选) # $dnsNameLabelBase = "<DNS Name>";
#指定HAset的名称
New-AzureRmAvailabilitySet -ResourceGroupName $resourceGroup -Name ImageVM-HA -Location "China East" -PlatformUpdateDomainCount 11 -PlatformFaultDomainCount 2;
$avaSet = Get-AzureRmAvailabilitySet -ResourceGroupName $resourceGroup -Name ImageVM-HA;
# 指定虚拟网络和子网(已存在的) $virtualNetworkName = "vnet"; $subnetName = "sub02"; $vnet = Get-AzureRmVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroup; $subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet; for ($i = 1; $i -lt 3; $i += 1) { $vmName = "{0}{1}" -f $vmNameBase, $i; $osDiskName = "{0}Disk" -f $vmName; $osDiskUri = "https://{0}.blob.core.chinacloudapi.cn/vhds/{1}.vhd" -f $storageAccount, $vmName; $vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize -AvailabilitySetId $avaSet.Id; # 指定系统类型等 $vmConfig = Set-AzureRmVMOperatingSystem -VM $vmConfig -Linux -ComputerName $vmName -Credential $cred; # 创建public IP $publicIPName = "{0}publicip" -f $vmName; # $dnsLabel = "{0}{1}" -f $vmName, $dnsNameLabelBase $publicIP = New-AzureRmPublicIpAddress -Name $publicIPName -ResourceGroupName $resourceGroup -Location $location -AllocationMethod Dynamic; #-DomainNameLabel $dnsLabel; # 创建NIC $nicName = "{0}nic" -f $vmName; $nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $resourceGroup -Location $location -SubnetId $subnet.Id -PublicIpAddressId $publicIP.Id; $vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id; $vmConfig = Set-AzureRmVMOSDisk -VM $vmConfig -Name $osDiskName -VhdUri $osDiskUri -SourceImageUri $sourceImageUri -Caching $osDiskCaching -CreateOption $osCreatenOption -Linux; # 创建VM New-AzureRmVM -ResourceGroupName $resourceGroup -Location $location -VM $vmConfig; }
![](https://images2015.cnblogs.com/blog/810234/201707/810234-20170714144724040-140261729.png)