简体   繁体   English

如何使用ARM Powershell在Azure中创建Linux VM

[英]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 请提供一些参考ARM PowerShell Cmdlet来帮助我,以创建Linux(Redhat版本)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. 稍微修改New-AzureRmVM文档中的示例,下面的PowerShell脚本即可完成此工作(根据需要修改参数)-它会提供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. 请记住,您不能在启用了货币上限的订阅(例如免费,试用版,仅具有货币信用的订阅等)上提供按需购买的Red Hat Enterprise Linux VM,因为这是第三方收费除了基本计算价格。 Read here for more details. 在此处阅读更多信息。

For quick create it is recommended to use Azure CLI. 为了快速创建,建议使用Azure CLI。 This would run on Windows, Mac, Linux. 它可以在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 . 或使用模板(例如this)

If you DO find a need for a quick create in ARM PowerShell, please file an issue on Azure PowerShell GitHub . 如果确实需要在ARM PowerShell中快速创建,请在Azure PowerShell GitHub上提出问题。

PowerShell script is more involved as it controls pretty much every aspect of VM creation: PowerShell脚本涉及更多,因为它几乎控制了VM创建的各个方面:

## 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). 您具有使用Azure CLI(这是Azure的x-plat命令行工具)执行此操作的完整过程。 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). 例如,使用azure vm quick-create命令:quick-create命令部署具有周围基础结构的VM,您可以使用该基础结构非常快速地对概念进行原型设计或测试(您可以将其视为实现Linux bash的最快方法)贝壳)。 https://azure.microsoft.com/en-gb/documentation/articles/virtual-machines-linux-quick-create-cli/ https://azure.microsoft.com/zh-CN/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/ 您还可以使用Azure CLI从头开始创建Linux VM: 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/ . 关于操作系统:您可以浏览市场以找到合适的操作系统(在您的情况下为redhat) https://azure.microsoft.com/zh-CN/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". 如果您使用此https://azure.microsoft.com/zh-CN/marketplace/partners/redhat/redhatenterpriselinux67/ ,则将按照所述方式向您收费:“使用此即用即付图像进行单独处理每小时的费用,除了Microsoft的Linux VM费率之外”。

But instead of using a marketplace image you can also upload & use your own OS image for the provisionning process. 但是,除了使用市场映像之外,您还可以上传并使用自己的OS映像进行预配置过程。

You can use an ARM template and deploy the template with Powershell. 您可以使用ARM模板,并通过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 . 您可以从这个简单的linux模板开始并根据您的需求自定义它https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-simple-linux

And then use Powershell to deploy it using 然后使用Powershell使用

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 请遵循此处提到的完整步骤: https : //azure.microsoft.com/zh-cn/documentation/articles/resource-group-template-deploy/#deploy-with-powershell

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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