Azure 中的 Windows 虚拟机概述Overview of Windows virtual machines in Azure

Azure 虚拟机 (VM) 是 Azure 提供的多种可缩放按需分配计算资源之一。Azure Virtual Machines (VM) is one of several types of on-demand, scalable computing resources that Azure offers. 通常情况下,如果需要以更大的力度(相对于其他控制选项)控制计算环境,则应选择 VM。Typically, you choose a VM when you need more control over the computing environment than the other choices offer. 本文介绍创建 VM 之前的注意事项,以及 VM 的创建方法和管理方式。This article gives you information about what you should consider before you create a VM, how you create it, and how you manage it.

使用 Azure VM 可以灵活进行虚拟化,而无需购买和维护运行 VM 的物理硬件。An Azure VM gives you the flexibility of virtualization without having to buy and maintain the physical hardware that runs it. 不过,仍然需要通过执行任务来维护 VM,例如,配置、修补和安装在 VM 上运行的软件。However, you still need to maintain the VM by performing tasks, such as configuring, patching, and installing the software that runs on it.

可通过多种方式使用 Azure 虚拟机。Azure virtual machines can be used in various ways. 下面是一些示例:Some examples are:

  • 开发和测试 – 在 Azure VM 上,可以快速轻松地创建具有特定配置的计算机来满足编程和应用程序测试的需要。Development and test - Azure VMs offer a quick and easy way to create a computer with specific configurations required to code and test an application.
  • 云中的应用程序 – 由于应用程序的需求会不断变化,在 Azure 中的 VM 上运行应用程序可能会节省成本。Applications in the cloud - Because demand for your application can fluctuate, it might make economic sense to run it on a VM in Azure. 使用 VM 时,需要支付额外的费用;关闭 VM 时,则无需付费。You pay for extra VMs when you need them and shut them down when you don't.
  • 扩展的数据中心 – Azure 虚拟网络中的虚拟机可以轻松连接到组织的网络。Extended datacenter - Virtual machines in an Azure virtual network can easily be connected to your organization's network.

可以根据需要,将应用程序使用的 VM 纵向和横向扩展为任意数目。The number of VMs that your application uses can scale up and out to whatever is required to meet your needs.

在创建 VM 之前需要考虑哪些因素?What do I need to think about before creating a VM?

在 Azure 中构建应用程序基础结构时,始终要考虑多种设计注意事项There are always a multitude of design considerations when you build out an application infrastructure in Azure. 在开始之前,必须考虑到 VM 的以下重要方面:These aspects of a VM are important to think about before you start:

  • 应用程序资源的名称The names of your application resources
  • 资源的存储位置The location where the resources are stored
  • VM 的大小The size of the VM
  • 可以创建的 VM 数目上限The maximum number of VMs that can be created
  • VM 运行的操作系统The operating system that the VM runs
  • VM 在启动后的配置The configuration of the VM after it starts
  • VM 所需的相关资源The related resources that the VM needs

命名Naming

虚拟机有一个分配的名称,另外,它还配置有一个在操作系统中使用的计算机名称。A virtual machine has a name assigned to it and it has a computer name configured as part of the operating system. VM 的名称最多可包含 15 个字符。The name of a VM can be up to 15 characters.

如果使用 Azure 创建操作系统磁盘,计算机名称与虚拟机名称相同。If you use Azure to create the operating system disk, the computer name and the virtual machine name are the same. 如果上传包含以前配置的操作系统的自有映像并使用它来创建虚拟机,则名称可以不同。If you upload and use your own image that contains a previously configured operating system and use it to create a virtual machine, the names can be different. 建议在上传自己的映像文件时,使操作系统中的计算机名称与虚拟机名称保持相同。We recommend that when you upload your own image file, you make the computer name in the operating system and the virtual machine name the same.

位置Locations

在 Azure 中创建的所有资源分布在中国的多个地理区域All resources created in Azure are distributed across multiple geographical regions around China. 创建 VM 时,区域通常称为 位置Usually, the region is called location when you create a VM. 位置指定 VM 虚拟硬盘的存储位置。For a VM, the location specifies where the virtual hard disks are stored.

下表显示了获取可用位置列表的一些方法。This table shows some of the ways you can get a list of available locations.

方法Method 说明Description
Azure 门户Azure portal 创建 VM 时,可从列表中选择位置。Select a location from the list when you create a VM.
Azure PowerShellAzure PowerShell 使用 Get-AzLocation 命令。Use the Get-AzLocation command.
REST APIREST API 使用列出位置操作。Use the List locations operation.
Azure CLIAzure CLI 使用 az account list-locations 操作。Use the az account list-locations operation.

VM 大小VM size

VM 的大小由所要运行的工作负荷决定。The size of the VM that you use is determined by the workload that you want to run. 然后,选择的大小决定了处理能力、内存和存储容量等因素。The size that you choose then determines factors such as processing power, memory, and storage capacity. Azure 提供各种大小来支持多种类型的用途。Azure offers a wide variety of sizes to support many types of uses.

Azure 根据 VM 的大小和操作系统按小时进行收费Azure charges an hourly price based on the VM's size and operating system. 对于不足一小时的部分,Azure 仅根据使用的分钟数计费。For partial hours, Azure charges only for the minutes used. 存储将另行定价和收费。Storage is priced and charged separately.

VM 限制VM Limits

订阅附带默认的配额限制,在为项目部署大量 VM 时,这些限制可能会造成影响。Your subscription has default quota limits in place that could impact the deployment of many VMs for your project. 每个订阅的当前限制是每区域 20 个 VM。The current limit on a per subscription basis is 20 VMs per region. 可以开具支持票证来请求提高限制Limits can be raised by filing a support ticket requesting an increase

操作系统磁盘和映像Operating system disks and images

虚拟机使用虚拟硬盘 (VHD) 来存储其操作系统 (OS) 和数据。Virtual machines use virtual hard disks (VHDs) to store their operating system (OS) and data. VHD 还可用于存储映像,可以选择某个映像来安装 OS。VHDs are also used for the images you can choose from to install an OS.

Azure 提供许多市场映像来配合各种版本和类型的 Windows Server 操作系统使用。Azure provides many marketplace images to use with various versions and types of Windows Server operating systems. 市场映像由映像发布者、产品、SKU 和版本(通常指定为最新版本)标识。Marketplace images are identified by image publisher, offer, sku, and version (typically version is specified as latest). 仅支持 64 位操作系统。Only 64-bit operating systems are supported. 有关受支持的来宾操作系统、角色和功能的详细信息,请参阅 Azure 虚拟机的 Microsoft 服务器软件支持For more information on the supported guest operating systems, roles, and features, see Microsoft server software support for Azure virtual machines.

下表显示了查找映像信息的一些方法。This table shows some ways that you can find the information for an image.

方法Method 说明Description
Azure 门户Azure portal 选择要使用的映像时,系统会自动指定值。The values are automatically specified for you when you select an image to use.
Azure PowerShellAzure PowerShell Get-AzVMImagePublisher -Location locationGet-AzVMImagePublisher -Location location
Get-AzVMImageOffer -Location location -Publisher publisherNameGet-AzVMImageOffer -Location location -Publisher publisherName
Get-AzVMImageSku -Location location -Publisher publisherName -Offer offerNameGet-AzVMImageSku -Location location -Publisher publisherName -Offer offerName
REST APIREST APIs 列出映像发布者List image publishers
列出映像产品List image offers
列出映像 SKUList image skus
Azure CLIAzure CLI az vm image list-publishers --location locationaz vm image list-publishers --location location
az vm image list-offers --location location --publisher publisherNameaz vm image list-offers --location location --publisher publisherName
az vm image list-skus --location location --publisher publisherName --offer offerNameaz vm image list-skus --location location --publisher publisherName --offer offerName

可以选择 上传并使用自己的映像 ,在这种情况下,无需使用发布者名称、产品和 SKU。You can choose to upload and use your own image and when you do, the publisher name, offer, and sku aren't used.

扩展Extensions

VM 扩展通过部署后的配置和自动化任务来增加 VM 的功能。VM extensions give your VM additional capabilities through post deployment configuration and automated tasks.

可以使用扩展完成以下常见任务:These common tasks can be accomplished using extensions:

VM 使用下表中的资源,创建 VM 时,这些资源必须存在,否则要予以创建。The resources in this table are used by the VM and need to exist or be created when the VM is created.

资源Resource 必须Required 说明Description
资源组Resource group Yes VM 必须包含在资源组中。The VM must be contained in a resource group.
存储帐户Storage account Yes VM 需要使用存储帐户来存储其虚拟硬盘。The VM needs the storage account to store its virtual hard disks.
虚拟网络Virtual network Yes VM 必须是虚拟网络的成员。The VM must be a member of a virtual network.
公共 IP 地址Public IP address No 可以向 VM 分配一个公共 IP 地址,以便远程访问它。The VM can have a public IP address assigned to it to remotely access it.
LinuxNetwork interface Yes VM 需要使用网络接口在网络中通信。The VM needs the network interface to communicate in the network.
数据磁盘数Data disks No VM 可以包含数据磁盘,以便扩展存储功能。The VM can include data disks to expand storage capabilities.

如何创建第一个 VM?How do I create my first VM?

可以选择多种方法创建 VM。You have several choices for creating your VM. 选择哪种方法取决于所在的环境。The choice that you make depends on the environment you are in.

此表提供的信息可用于创建 VM。This table provides information to get you started creating your VM.

方法Method 文章Article
Azure 门户Azure portal 使用门户创建运行 Windows 的虚拟机Create a virtual machine running Windows using the portal
模板Templates 使用 Resource Manager 模板创建 Windows 虚拟机Create a Windows virtual machine with a Resource Manager template
Azure PowerShellAzure PowerShell 使用 PowerShell 创建 Windows VMCreate a Windows VM using PowerShell
客户端 SDKClient SDKs 使用 C# 部署 Azure 资源Deploy Azure Resources using C#
REST APIREST APIs 创建或更新 VMCreate or update a VM
Azure CLIAzure CLI 使用 Azure CLI 创建 VMCreate a VM with the Azure CLI

问题偶尔会不期而至。You hope it never happens, but occasionally something goes wrong. 如果遇到了问题,请查看排查在 Azure 中创建 Windows 虚拟机时遇到的 Resource Manager 部署问题If this situation happens to you, look at the information in Troubleshoot Resource Manager deployment issues with creating a Windows virtual machine in Azure.

如何管理创建的 VM?How do I manage the VM that I created?

可以使用基于浏览器的门户、支持脚本的命令行工具或直接通过 API 管理 VM。VMs can be managed using a browser-based portal, command-line tools with support for scripting, or directly through APIs. 可能要执行的一些常见管理任务包括获取有关 VM 的信息、登录到 VM、管理可用性以及执行备份。Some typical management tasks that you might perform are getting information about a VM, logging on to a VM, managing availability, and making backups.

获取有关 VM 的信息Get information about a VM

下表显示了获取有关 VM 的信息的一些方法。This table shows you some of the ways that you can get information about a VM.

方法Method 说明Description
Azure 门户Azure portal 在中心菜单中,单击“虚拟机”,然后从列表中选择 VM。On the hub menu, click Virtual Machines and then select the VM from the list. 在 VM 的边栏选项卡中,可以访问概述信息、设置值以及监控指标。On the blade for the VM, you have access to overview information, setting values, and monitoring metrics.
Azure PowerShellAzure PowerShell 若要了解如何使用 PowerShell 管理 VM,请参阅使用 Azure PowerShell 模块创建和管理 Windows VMFor information about using PowerShell to manage VMs, see Create and manage Windows VMs with the Azure PowerShell module.
REST APIREST API 使用获取 VM 信息操作获取有关 VM 的信息。Use the Get VM information operation to get information about a VM.
客户端 SDKClient SDKs 有关使用 C# 管理 VM 的信息,请参阅使用 Azure Resource Manager 与 C# 来管理 Azure 虚拟机For information about using C# to manage VMs, see Manage Azure Virtual Machines using Azure Resource Manager and C#.
Azure CLIAzure CLI 有关使用 Azure CLI 管理 VM 的信息,请参阅 Azure CLI 参考For information about using Azure CLI to manage VMs, see Azure CLI Reference.

登录到 VMLog on to the VM

使用 Azure 门户中的“连接”按钮启动远程桌面 (RDP) 会话You use the Connect button in the Azure portal to start a Remote Desktop (RDP) session. 尝试使用远程连接时,有时可能会出错。Things can sometimes go wrong when trying to use a remote connection. 如果遇到这种情况,请查看对运行 Windows 的 Azure 虚拟机的远程桌面连接进行故障排除中的帮助信息。If this situation happens to you, check out the help information in Troubleshoot Remote Desktop connections to an Azure virtual machine running Windows.

管理可用性Manage availability

了解如何确保应用程序的高可用性,这一点很重要。It's important for you to understand how to ensure high availability for your application. 此配置涉及到创建多个 VM,确保至少有一个 VM 在运行。This configuration involves creating multiple VMs to ensure that at least one is running.

为了使部署符合 VM 运行时间达到 99.95% 的服务级别协议,必须在可用性集中部署两个或更多个运行工作负荷的 VM。In order for your deployment to qualify for our 99.95 VM Service Level Agreement, you need to deploy two or more VMs running your workload inside an availability set. 此配置可确保 VM 分布到多个容错域,并使用不同的维护时段部署到主机上。This configuration ensures your VMs are distributed across multiple fault domains and are deployed onto hosts with different maintenance windows. 完整 Azure SLA 说明了 Azure 作为整体的保证可用性。The full Azure SLA explains the guaranteed availability of Azure as a whole.

备份 VMBack up the VM

恢复服务保管库用于保护 Azure 备份和 Azure Site Recovery 服务中的数据与资产。A Recovery Services vault is used to protect data and assets in both Azure Backup and Azure Site Recovery services. 可以使用恢复服务保管库,通过 PowerShell 来部署和管理采用 Resource Manager 模型部署的 VM 备份You can use a Recovery Services vault to deploy and manage backups for Resource Manager-deployed VMs using PowerShell.

后续步骤Next steps