您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure 云服务的概述Overview of Azure Cloud Services

Azure 云服务是平台即服务 (PaaS) 的一个示例。Azure Cloud Services is an example of a platform as a service (PaaS). Azure 应用服务一样,此技术设计用于支持可缩放、可靠且运营成本低廉的应用程序。Like Azure App Service, this technology is designed to support applications that are scalable, reliable, and inexpensive to operate. 同样,应用服务托管在虚拟机 (VM) 上,Azure 云服务也是如此。In the same way that App Service is hosted on virtual machines (VMs), so too is Azure Cloud Services. 但是,你对 VM 有更多的控制。However, you have more control over the VMs. 可以在使用 Azure 云服务的 VM 上安装自己的软件,并且可以远程访问它们。You can install your own software on VMs that use Azure Cloud Services, and you can access them remotely.

Azure 云服务关系图

更多控制也意味着更不易于使用。More control also means less ease of use. 除非需要更多控制选项,否则,与 Azure 云服务相比,在应用服务的 Web 应用功能中启动和运行 Web 应用程序通常要快速方便一些。Unless you need the additional control options, it's typically quicker and easier to get a web application up and running in the Web Apps feature of App Service compared to Azure Cloud Services.

有两种类型的 Azure 云服务角色。There are two types of Azure Cloud Services roles. 两者之间的唯一区别是角色在 VM 上的托管方式:The only difference between the two is how your role is hosted on the VMs:

  • Web 角色:通过 IIS 自动部署和托管应用。Web role: Automatically deploys and hosts your app through IIS.

  • 辅助角色:不使用 IIS,并独立运行应用。Worker role: Does not use IIS, and runs your app standalone.

例如,简单的应用程序可能只使用一个 web 角色为网站提供服务。For example, a simple application might use just a single web role, serving a website. 更复杂的应用程序可能使用 Web 角色来处理用户的传入请求,然后将这些请求传递给辅助角色进行处理。A more complex application might use a web role to handle incoming requests from users, and then pass those requests on to a worker role for processing. (此通信可以使用 Azure 服务总线Azure 队列存储。)(This communication might use Azure Service Bus or Azure Queue storage.)

如上图所示,一个应用程序中的所有 VM 都在同一云服务中运行。As the preceding figure suggests, all the VMs in a single application run in the same cloud service. 用户通过单个公共 IP 地址访问应用程序,而请求会自动在应用程序的 VM 中进行负载均衡。Users access the application through a single public IP address, with requests automatically load balanced across the application's VMs. 该平台采用一种能够避免单点硬件故障的方式在 Azure 云服务应用程序中缩放和部署 VM。The platform scales and deploys the VMs in an Azure Cloud Services application in a way that avoids a single point of hardware failure.

即使应用程序在 VM 中运行,理解 Azure 云服务提供的是 PaaS 而非基础结构即服务 (IaaS) 也很重要。Even though applications run in VMs, it's important to understand that Azure Cloud Services provides PaaS, not infrastructure as a service (IaaS). 以下办法有助于理解这一点。Here's one way to think about it. 使用 IaaS(例如 Azure 虚拟机)时,首先要创建并配置你的应用程序将在其中运行的环境。With IaaS, such as Azure Virtual Machines, you first create and configure the environment your application runs in. 然后,将应用程序部署到该环境中。Then you deploy your application into this environment. 你要负责执行该环境的大部分管理工作,例如在每个 VM 中部署操作系统的新修补版本。You're responsible for managing much of this world, by doing things such as deploying new patched versions of the operating system in each VM. 相反,在 PaaS 中,这样的环境似乎早已存在。In PaaS, by contrast, it's as if the environment already exists. 只需部署应用程序。All you have to do is deploy your application. 已处理它所运行的平台的管理工作,包括部署操作系统的新版本。Management of the platform it runs on, including deploying new versions of the operating system, is handled for you.

缩放和管理Scaling and management

使用 Azure 云服务时,你不需要创建虚拟机。With Azure Cloud Services, you don't create virtual machines. 相反,你将提供一个配置文件,告知 Azure 每个 VM 需要多少个角色实例(例如,“三个 Web 角色实例”和“两个辅助角色实例”)。Instead, you provide a configuration file that tells Azure how many of each you'd like, such as "three web role instances" and "two worker role instances." 然后,平台将创建它们。The platform then creates them for you. 虽然仍然要选择这些备份 VM 的大小,但不用直接自行进行创建。You still choose what size those backing VMs should be, but you don't explicitly create them yourself. 如果应用程序需要处理更大的负载,则可以要求增加 VM,Azure 将创建这些实例。If your application needs to handle a greater load, you can ask for more VMs, and Azure creates those instances. 如果负载降低,则可以关闭这些实例并停止为它们付费。If the load decreases, you can shut down those instances and stop paying for them.

通常通过两个步骤就能使 Azure 云服务应用程序可供用户使用。An Azure Cloud Services application is typically made available to users via a two-step process. 首先,开发人员将应用程序上传到该平台的暂存区域。A developer first uploads the application to the platform's staging area. 当开发人员准备好使应用程序上线后,他们会使用 Azure 门户从过渡环境切换到生产环境。When the developer is ready to make the application live, they use the Azure portal to swap staging with production. 暂存与生产之间的这种切换无需停机就可完成,这使运行的应用程序可在不打扰其用户的情况下升级到新版本。This switch between staging and production can be done with no downtime, which lets a running application be upgraded to a new version without disturbing its users.

监视Monitoring

Azure 云服务还提供监视功能。Azure Cloud Services also provides monitoring. 像虚拟机一样,它将检测发生故障的物理服务器,并在新的计算机上重新启动原先在该服务器上运行的 VM。Like Virtual Machines, it detects a failed physical server and restarts the VMs that were running on that server on a new machine. Azure 云服务不仅检测硬件故障,还检测发生故障的 VM 和应用程序。But Azure Cloud Services also detects failed VMs and applications, not just hardware failures. 与虚拟机不同,它在每个 Web 角色和辅助角色中都存在有代理,因此它能够在发生故障时启动新的 VM 和应用程序实例。Unlike Virtual Machines, it has an agent inside each web and worker role, and so it's able to start new VMs and application instances when failures occur.

Azure 云服务的 PaaS 特性还具有其他含义。The PaaS nature of Azure Cloud Services has other implications, too. 其中一个最重要的含义是,应编写基于此技术构建的应用程序以在任何 Web 角色或辅助角色实例出现故障时正确运行。One of the most important is that applications built on this technology should be written to run correctly when any web or worker role instance fails. 要实现这一目标,Azure 云服务应用程序不应该在它自己的 VM 的文件系统中维持状态。To achieve this, an Azure Cloud Services application shouldn't maintain state in the file system of its own VMs. 与通过“虚拟机”创建的 VM 不同,对 Azure 云服务 VM 所做的写入不是持久的。Unlike VMs created with Virtual Machines, writes made to Azure Cloud Services VMs aren't persistent. 这与虚拟机数据磁盘不同。There's nothing like a Virtual Machines data disk. 相反,Azure 云服务应用程序应将所有状态明确写入到 Azure SQL 数据库、blob、表或其他某种外部存储中。Instead, an Azure Cloud Services application should explicitly write all state to Azure SQL Database, blobs, tables, or some other external storage. 以这种方式构建应用程序会使它们更易于扩展、抵抗故障的能力更强,这是 Azure 云服务的两个重要目标。Building applications this way makes them easier to scale and more resistant to failure, which are both important goals of Azure Cloud Services.

后续步骤Next steps