简体   繁体   中英

How to Create a Linux VM in Azure Using ARM Powershell

Please help me with some reference ARM PowerShell Cmdlets for creating a Linux (Redhat version) VM

Thanks

Slightly modifying the sample from New-AzureRmVM documentation , the below PowerShell script should do the job (modify parameters as needed) - it will provision a RHEL 7.2 VM. Check for name collisions with your own resources before you run it.

Please remember that you CANNOT provision pay-as-you-go Red Hat Enterprise Linux VMs on subscriptions that have monetary cap enabled (eg free, trial, a subscription with monetary credits ONLY, etc.) because it is a third-party charge in addition to the base compute price. Read here for more details.

For quick create it is recommended to use Azure CLI. This would run on Windows, Mac, Linux. It is as simple as:

azure config mode arm
azure group create TestCLIRG EastUS
azure vm quick-create TestCLIRG vm1 EastUS Linux RedHat:RHEL:7.2:latest azureuser

or use a template, such as this one .

If you DO find a need for a quick create in ARM PowerShell, please file an issue on Azure PowerShell GitHub .

PowerShell script is more involved as it controls pretty much every aspect of VM creation:

## Global
$ResourceGroupName = "Group1"
$Location = "EastAsia"

## Storage
$StorageName = "storageaccname001"
$StorageType = "Standard_GRS"

## Network
$InterfaceName = "ServerInterface06"
$Subnet1Name = "Subnet1"
$VNetName = "VNet09"
$VNetAddressPrefix = "10.0.0.0/16"
$VNetSubnetAddressPrefix = "10.0.0.0/24"

## Compute
$VMName = "rhel-vm"
$VMSize = "Standard_D2"
$OSDiskName = $VMName + "OSDisk"

# Resource Group
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location

# Storage
$StorageAccount = New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName -Type $StorageType -Location $Location

# Network
$PIp = New-AzureRmPublicIpAddress -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -AllocationMethod Dynamic
$SubnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name $Subnet1Name -AddressPrefix $VNetSubnetAddressPrefix
$VNet = New-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName -Location $Location -AddressPrefix $VNetAddressPrefix -Subnet $SubnetConfig
$Interface = New-AzureRmNetworkInterface -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $VNet.Subnets[0].Id -PublicIpAddressId $PIp.Id

# Compute

## Setup local VM object
$Credential = Get-Credential
$VirtualMachine = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize
$VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -ComputerName $VMName -Linux -Credential $Credential
$VirtualMachine = Set-AzureRmVMSourceImage -VM $VirtualMachine -PublisherName "RedHat" -Offer "RHEL" -Skus "7.2" -Version "latest"
$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $Interface.Id
$OSDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + "vhds/" + $OSDiskName + ".vhd"
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $OSDiskUri -CreateOption FromImage

## Create the VM in Azure
New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $VirtualMachine

You have a complete process to do that with Azure CLI (which is a x-plat command-line tool for Azure). For example using azure vm quick-create command: The quick-create command deploys a VM with a basic infrastructure surrounding it that you can use to prototype or test a concept very rapidly (you can think of it as the quickest way to a Linux bash shell). https://azure.microsoft.com/en-gb/documentation/articles/virtual-machines-linux-quick-create-cli/

You can also create a Linux VM from the ground up using the Azure CLI : https://azure.microsoft.com/en-gb/documentation/articles/virtual-machines-linux-create-cli-complete/

About the OS : You can browse the marketplace to find the appropriate OS (redhat in your case) https://azure.microsoft.com/en-gb/documentation/articles/virtual-machines-linux-cli-ps-findimage/ .

If you use this one https://azure.microsoft.com/en-us/marketplace/partners/redhat/redhatenterpriselinux67/ , you will be charged as mentioned: "Use of this Pay-As-You-Go image carries a separate hourly charge that is in addition to Microsoft's Linux VM rates".

But instead of using a marketplace image you can also upload & use your own OS image for the provisionning process.

You can use an ARM template and deploy the template with Powershell. You can start from this simple linux template & customize it according to your needs https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-simple-linux .

And then use Powershell to deploy it using

New-AzureRmResourceGroupDeployment -Name ExampleDeployment -DeploymentDebugLogLevel All -ResourceGroupName ExampleResourceGroup -TemplateFile <PathOrLinkToTemplate>

Please follow the complete steps mentioned here: https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-deploy/#deploy-with-powershell

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM