应用服务环境的异地分布式缩放Geo Distributed Scale with App Service Environments

概述Overview

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

需要极高缩放性的应用程序方案可能超过单个应用部署可用的计算资源容量。Application scenarios which require very high scale can exceed the compute resource capacity available to a single deployment of an app. 例如,投票应用程序、体育活动及电视娱乐活动都属于需要极高缩放性的方案。Voting applications, sporting events, and televised entertainment events are all examples of scenarios that require extremely high scale. 只要对单个区域内和跨区域的多个应用部署进行应用的水平扩展,即可达到高缩放性要求以处理极高的负载要求。High scale requirements can be met by horizontally scaling out apps, with multiple app deployments being made within a single region, as well as across regions, to handle extreme load requirements.

应用服务环境是水平扩展的理想平台。在选择可支持已知请求率的应用服务环境配置后,开发人员即可通过以千篇一律的方式部署其他应用服务环境,以获得所需的峰值负载容量。App Service Environments are an ideal platform for horizontal scale out. Once an App Service Environment configuration has been selected that can support a known request rate, developers can deploy additional App Service Environments in "cookie cutter" fashion to attain a desired peak load capacity.

例如,假设在应用服务环境配置上运行的应用已经过测试,每秒可处理 20K 个请求 (RPS)。For example suppose an app running on an App Service Environment configuration has been tested to handle 20K requests per second (RPS). 如果所需的峰值负载容量是 100K RPS,则可以创建并配置五 (5) 个应用服务环境,以确保应用程序能够处理最大预计负载。If the desired peak load capacity is 100K RPS, then five (5) App Service Environments can be created and configured to ensure the application can handle the maximum projected load.

由于客户通常使用自定义(或虚构)域访问应用,因此开发人员必须要有将应用请求分散到所有应用服务环境实例的方法。Since customers typically access apps using a custom (or vanity) domain, developers need a way to distribute app requests across all of the App Service Environment instances. 使用 Azure 流量管理器配置文件解析自定义域是不错的方法。A great way to accomplish this is to resolve the custom domain using an Azure Traffic Manager profile. 流量管理器配置文件可配置为指向每个应用服务环境。The Traffic Manager profile can be configured to point at all of the individual App Service Environments. 流量管理器根据流量管理器配置文件中的负载均衡设置,自动将客户分散到所有应用服务环境。Traffic Manager will automatically handle distributing customers across all of the App Service Environments based on the load balancing settings in the Traffic Manager profile. 无论所有的应用服务环境是部署在单个 Azure 区域还是跨多个 Azure 区域部署于世界各地,此方法都可正常进行。This approach works regardless of whether all of the App Service Environments are deployed in a single Azure region, or deployed worldwide across multiple Azure regions.

此外,由于客户通过虚构域访问应用,因此无从得知运行应用的 应用服务环境数。Furthermore, since customers access apps through the vanity domain, customers are unaware of the number of App Service Environments running an app. 因此,开发人员可以根据观察到的流量负载,快速轻松地添加和删除应用服务环境。As a result developers can quickly and easily add, and remove, App Service Environments based on observed traffic load.

下面的概念图描绘了在单个区域内以水平方式扩展到三个应用服务环境的应用。The conceptual diagram below depicts an app horizontally scaled out across three App Service Environments within a single region.

概念体系结构

本主题的其余部分演练如何使用多个应用服务环境为示例应用设置分布式拓扑所需的步骤。The remainder of this topic walks through the steps involved with setting up a distributed topology for the sample app using multiple App Service Environments.

规划拓扑Planning the Topology

在规划分布式应用的占用空间之前,最好先准备好几项信息。Before building out a distributed app footprint, it helps to have a few pieces information ahead of time.

  • 应用的自定义域: 客户访问应用时使用的自定义域名是什么?Custom domain for the app: What is the custom domain name that customers will use to access the app? 对于示例应用,自定义域名为 www.scalableasedemo.comFor the sample app the custom domain name is www.scalableasedemo.com
  • 流量管理器域: 创建 Azure 流量管理器配置文件时需要选择域名。Traffic Manager domain: A domain name needs to be chosen when creating an Azure Traffic Manager profile. 此名称与 trafficmanager.cn 后缀相结合,以注册流量管理器所管理的域条目。This name will be combined with the trafficmanager.cn suffix to register a domain entry that is managed by Traffic Manager. 就示例应用而言,选择的名称是 scalable-ase-demoFor the sample app, the name chosen is scalable-ase-demo. 因此,流量管理器所管理的完整域名是 scalable-ase-demo.trafficmanager.cnAs a result the full domain name that is managed by Traffic Manager is scalable-ase-demo.trafficmanager.cn.
  • 缩放应用范围的策略: 应用程序范围是否分散在单个区域中的多个应用服务环境之间?Strategy for scaling the app footprint: Will the application footprint be distributed across multiple App Service Environments in a single region? 是多个区域吗?Multiple regions? 两种方法要混搭使用吗?A mix-and-match of both approaches? 决策依据应来自于客户流量的来源位置,以及其余应用的支持后端基础结构的伸缩性。The decision should be based on expectations of where customer traffic will originate, as well as how well the rest of an app's supporting back-end infrastructure can scale. 例如,对于 100% 无状态的应用程序,可以使用每一 Azure 区域多个应用服务环境的组合,乘以跨多个 Azure 区域部署的应用服务环境数,来大幅缩放应用。For example, with a 100% stateless application, an app can be massively scaled using a combination of multiple App Service Environments per Azure region, multiplied by App Service Environments deployed across multiple Azure regions. 由于有 15 个以上的公用 Azure 区域可供选择,客户可真正构建全球性超高缩放性的应用程序占用空间。With 15+ public Azure regions available to choose from, customers can truly build a world-wide hyper-scale application footprint. 在本文所使用的示例应用中,有三个应用服务环境创建在单个 Azure 区域(中国东部 2)。For the sample app used for this article, three App Service Environments were created in a single Azure region (China East 2).
  • 应用服务环境的命名约定: 每个应用服务环境需要唯一的名称。Naming convention for the App Service Environments: Each App Service Environment requires a unique name. 有两个或更多应用服务环境时,命名约定将有助于标识每个应用服务环境。Beyond one or two App Service Environments it is helpful to have a naming convention to help identify each App Service Environment. 示例应用中使用了简单的命名约定。For the sample app a simple naming convention was used. 三个应用服务环境的名称分别是 fe1asefe2asefe3aseThe names of the three App Service Environments are fe1ase, fe2ase, and fe3ase.
  • 应用的命名约定: 由于将部署多个应用实例,每个部署的应用实例都要有名称。Naming convention for the apps: Since multiple instances of the app will be deployed, a name is needed for each instance of the deployed app. 有一项鲜为人知、但非常方便的应用服务环境功能,是多个应用服务环境可以使用相同的应用名称。One little-known but very convenient feature of App Service Environments is that the same app name can be used across multiple App Service Environments. 由于每个应用服务环境都有唯一的域后缀,开发人员可以选择在每个环境中重复使用完全相同的应用名称。Since each App Service Environment has a unique domain suffix, developers can choose to re-use the exact same app name in each environment. 例如,开发人员可以将应用命名如下:myapp.foo1.p.chinacloudsites.cnmyapp.foo2.p.chinacloudsites.cnmyapp.foo3.p.chinacloudsites.cn,等等。但示例应用的每个应用实例也都有唯一名称。For example a developer could have apps named as follows: myapp.foo1.p.chinacloudsites.cn, myapp.foo2.p.chinacloudsites.cn, myapp.foo3.p.chinacloudsites.cn, etc. For the sample app though each app instance also has a unique name. 所用的应用实例名称是 webfrontend1webfrontend2webfrontend3The app instance names used are webfrontend1, webfrontend2, and webfrontend3.

设置流量管理器配置文件Setting up the Traffic Manager Profile

将应用的多个实例部署在多个应用服务环境上之后,可以使用流量管理器来注册单个应用实例。Once multiple instances of an app are deployed on multiple App Service Environments, the individual app instances can be registered with Traffic Manager. 就示例应用而言,scalable-ase-demo.trafficmanager.cn 必须要有流量管理器配置文件,以将客户路由到任何以下已部署的应用实例: For the sample app a Traffic Manager profile is needed for scalable-ase-demo.trafficmanager.cn that can route customers to any of the following deployed app instances:

  • webfrontend1.fe1ase.p.chinacloudsites.cn: 部署在第一个应用服务环境中的示例应用实例。webfrontend1.fe1ase.p.chinacloudsites.cn: An instance of the sample app deployed on the first App Service Environment.
  • webfrontend2.fe2ase.p.chinacloudsites.cn: 部署在第二个应用服务环境中的示例应用实例。webfrontend2.fe2ase.p.chinacloudsites.cn: An instance of the sample app deployed on the second App Service Environment.
  • webfrontend3.fe3ase.p.chinacloudsites.cn: 部署在第三个应用服务环境中的示例应用实例。webfrontend3.fe3ase.p.chinacloudsites.cn: An instance of the sample app deployed on the third App Service Environment.

要注册多个 Azure 应用服务终结点(全部运行于相同的 Azure 区域中),最简单的方法是使用 Powershell Azure 资源管理器流量管理器支持The easiest way to register multiple Azure App Service endpoints, all running in the same Azure region, is with the Powershell Azure Resource Manager Traffic Manager support.

第一个步骤是创建 Azure 流量管理器配置文件。The first step is to create an Azure Traffic Manager profile. 以下代码演示如何为示例应用创建配置文件:The code below shows how the profile was created for the sample app:

$profile = New-AzureTrafficManagerProfile –Name scalableasedemo -ResourceGroupName yourRGNameHere -TrafficRoutingMethod Weighted -RelativeDnsName scalable-ase-demo -Ttl 30 -MonitorProtocol HTTP -MonitorPort 80 -MonitorPath "/"

请注意 RelativeDnsName 参数已设置为 scalable-ase-demoNotice how the RelativeDnsName parameter was set to scalable-ase-demo. 这说明域名 scalable-ase-demo.trafficmanager.cn 是如何创建并与流量管理器配置文件关联的。This is how the domain name scalable-ase-demo.trafficmanager.cn is created and associated with a Traffic Manager profile.

TrafficRoutingMethod 参数定义负载均衡策略,供流量管理器用于判断如何将客户负载分散到所有可用的终结点。The TrafficRoutingMethod parameter defines the load balancing policy Traffic Manager will use to determine how to spread customer load across all of the available endpoints. 本示例选择了 Weighted 方法。In this example the Weighted method was chosen. 这使客户请求根据与每个终结点关联的相对加权分散到所有已注册的应用程序终结点。This will result in customer requests being spread across all of the registered application endpoints based on the relative weights associated with each endpoint.

在创建配置文件后,每个应用实例都添加到配置文件作为本机 Azure 终结点。With the profile created, each app instance is added to the profile as a native Azure endpoint. 下面的代码获取对每个前端 Web 应用的引用,并通过 TargetResourceId 参数将每个应用添加为流量管理器终结点。The code below fetches a reference to each front end web app, and then adds each app as a Traffic Manager endpoint by way of the TargetResourceId parameter.

$webapp1 = Get-AzWebApp -Name webfrontend1
Add-AzureTrafficManagerEndpointConfig –EndpointName webfrontend1 –TrafficManagerProfile $profile –Type AzureEndpoints -TargetResourceId $webapp1.Id –EndpointStatus Enabled –Weight 10

$webapp2 = Get-AzWebApp -Name webfrontend2
Add-AzureTrafficManagerEndpointConfig –EndpointName webfrontend2 –TrafficManagerProfile $profile –Type AzureEndpoints -TargetResourceId $webapp2.Id –EndpointStatus Enabled –Weight 10

$webapp3 = Get-AzWebApp -Name webfrontend3
Add-AzureTrafficManagerEndpointConfig –EndpointName webfrontend3 –TrafficManagerProfile $profile –Type AzureEndpoints -TargetResourceId $webapp3.Id –EndpointStatus Enabled –Weight 10

Set-AzureTrafficManagerProfile –TrafficManagerProfile $profile

请注意,每个应用实例分别有一个 Add-AzureTrafficManagerEndpointConfig 调用。Notice how there is one call to Add-AzureTrafficManagerEndpointConfig for each individual app instance. TargetResourceId 参数引用三个已部署应用实例之一。The TargetResourceId parameter in each Powershell command references one of the three deployed app instances. 流量管理器配置文件将负载分布在配置文件中注册的所有三个终结点上。The Traffic Manager profile will spread load across all three endpoints registered in the profile.

所有三个终结点对 Weight 参数使用了相同的值 (10)。All of the three endpoints use the same value (10) for the Weight parameter. 这使流量管理器将客户请求较平均地分散到所有三个应用实例。This results in Traffic Manager spreading customer requests across all three app instances relatively evenly.

将应用的自定义域指向流量管理器域Pointing the App's Custom Domain at the Traffic Manager Domain

最后一个必要步骤是将应用的自定义域指向流量管理器域。The final step necessary is to point the custom domain of the app at the Traffic Manager domain. 对于示例应用,这意味着将 www.scalableasedemo.com 指向 scalable-ase-demo.trafficmanager.cnFor the sample app this means pointing www.scalableasedemo.com at scalable-ase-demo.trafficmanager.cn. 此步骤必须以管理自定义域的域注册机构来完成。This step needs to be completed with the domain registrar that manages the custom domain.

如果使用注册机构的域管理工具,则需要创建一条将自定义域指向流量管理器域的 CNAME 记录。Using your registrar's domain management tools, a CNAME records needs to be created which points the custom domain at the Traffic Manager domain. 下图显示了此 CNAME 配置的示例:The picture below shows an example of what this CNAME configuration looks like:

自定义域的 CNAME

尽管本主题并未说明,但请记住,每个应用实例也都需要注册其自定义域。Although not covered in this topic, remember that each individual app instance needs to have the custom domain registered with it as well. 否则,在对应用实例发出请求时,如果应用程序并未注册应用的自定义域,请求将失败。Otherwise if a request makes it to an app instance, and the application does not have the custom domain registered with the app, the request will fail.

在本示例中,自定义域是 www.scalableasedemo.com,且每个应用程序实例都有其关联的自定义域。In this example the custom domain is www.scalableasedemo.com, and each application instance has the custom domain associated with it.

自定义域

有关在 Azure 应用服务应用中注册自定义域的汇总信息,请参阅以下有关注册自定义域的文章。For a recap of registering a custom domain with Azure App Service apps, see the following article on registering custom domains.

试用分布式拓扑Trying out the Distributed Topology

使用流量管理器及 DNS 配置的最终结果是 www.scalableasedemo.com 的请求经历以下顺序的流程:The end result of the Traffic Manager and DNS configuration is that requests for www.scalableasedemo.com will flow through the following sequence:

  1. 浏览器或设备对 www.scalableasedemo.com 发出 DNS 查找A browser or device will make a DNS lookup for www.scalableasedemo.com
  2. 域注册机构上的 CNAME 条目使 DNS 查找重定向到 Azure 流量管理器。The CNAME entry at the domain registrar causes the DNS lookup to be redirected to Azure Traffic Manager.
  3. 对某个 Azure 流量管理器 DNS 服务器执行 scalable-ase-demo.trafficmanager.cn 的 DNS 查找。A DNS lookup is made for scalable-ase-demo.trafficmanager.cn against one of the Azure Traffic Manager DNS servers.
  4. 根据负载均衡策略(前面创建流量管理器配置文件时所用的 TrafficRoutingMethod 参数),流量管理器选择其中一个已配置的终结点,并将该终结点的 FQDN 返回到浏览器或设备。Based on the load balancing policy (the TrafficRoutingMethod parameter used earlier when creating the Traffic Manager profile), Traffic Manager will select one of the configured endpoints and return the FQDN of that endpoint to the browser or device.
  5. 由于终结点的 FQDN 是在应用服务环境中运行的应用实例的 URL,因此浏览器或设备请求 Microsoft Azure DNS 服务器将 FQDN 解析为 IP 地址。Since the FQDN of the endpoint is the Url of an app instance running on an App Service Environment, the browser or device will ask a Microsoft Azure DNS server to resolve the FQDN to an IP address.
  6. 浏览器或设备将 HTTP/S 请求发送到此 IP 地址。The browser or device will send the HTTP/S request to the IP address.
  7. 请求送达至某个应用服务环境中运行的应用实例之一。The request will arrive at one of the app instances running on one of the App Service Environments.

以下控制台图片显示了示例应用自定义域的 DNS 查找;该域已成功解析为在三个示例应用服务环境之一(在本例中,为三个应用服务环境中的第二个)中运行的应用实例:The console picture below shows a DNS lookup for the sample app's custom domain successfully resolving to an app instance running on one of the three sample App Service Environments (in this case the second of the three App Service Environments):

DNS 查找

有关 Powershell Azure 资源管理器流量管理器支持的文档。Documentation on the Powershell Azure Resource Manager Traffic Manager support.

备注

如果要在注册 Azure 帐户之前开始使用 Azure 应用服务,请转到试用应用服务,可以在应用服务中立即创建一个生存期较短的入门 Web 应用。If you want to get started with Azure App Service before signing up for an Azure account, go to Try App Service, where you can immediately create a short-lived starter web app in App Service. 不需要使用信用卡,也不需要做出承诺。No credit cards required; no commitments.