应用服务环境的异地分布式缩放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 that 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. 若要处理非常高的负载需求,可在单个区域内以及跨区域进行多个应用部署。To handle extreme load requirements, many app deployments can be made within a single region and across regions.

应用服务环境是非常适合横向扩展的平台。选择可支持已知请求率的应用服务环境配置后,开发人员可通过千篇一律的方式部署其他应用服务环境,以获得所需的峰值负载容量。App Service Environments are an ideal platform for horizontal scale-out. After selecting an App Service Environment configuration 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, 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 goal 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: Choose a domain name when creating an Azure Traffic Manager profile. 此名称与 trafficmanager.net 后缀相结合,以注册流量管理器所管理的域条目。This name will be combined with the trafficmanager.net 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.netAs a result the full domain name that is managed by Traffic Manager is scalable-ase-demo.trafficmanager.net.
  • 缩放应用占用空间的策略: 应用程序占用空间是否分布到单个区域中的多个应用服务环境?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? 做决策时请依据对客户流量来源位置的预期,以及应用的支持性后端基础结构其余部分的可缩放程度。Base the decision on expectations of where customer traffic will originate, and 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 many App Service Environments in each Azure region, multiplied by App Service Environments deployed across many Azure regions. 由于有 15 个以上的全球 Azure 区域可供选择,客户可真正构建全球性超高缩放性的应用程序范围。With 15+ global Azure regions available to choose from, customers can truly build a world-wide hyper-scale application footprint. 对于本文所使用的示例应用,已在单个 Azure 区域(中国东部 2)中创建了三个应用服务环境。For the sample app that's 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's 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 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 reuse 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, however, 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 parameter causes the domain name scalable-ase-demo.trafficmanager.cn to be 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. 由于选择此方法,客户请求将会根据与每个终结点关联的相对权重被分散到所有已注册的应用程序终结点。Because of this choice, customer requests will be spread across all registered application endpoints based on the relative weights that are associated with each endpoint.

在创建配置文件后,每个应用实例都添加到配置文件作为本机 Azure 终结点。With the profile created, each app instance is added to the profile as a native Azure endpoint. 以下代码提取对每个前端 Web 应用的引用。The following code fetches a reference to each front-end web app. 然后,它通过 TargetResourceId 参数将每个应用添加为流量管理器终结点。It then adds each app as a Traffic Manager endpoint through 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. 每个 PowerShell 命令中的 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 situation 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.netFor the sample app, point www.scalableasedemo.com at scalable-ase-demo.trafficmanager.net. 请使用管理自定义域的域注册机构来完成这一步。Complete this step 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 hasn't registered the custom domain 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 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 参数中指定的负载平衡策略,流量管理器会选择已配置的终结点之一。Based on the load-balancing policy specified earlier in the TrafficRoutingMethod parameter, Traffic Manager selects one of the configured endpoints. 然后,它会将该终结点的 FQDN 返回到浏览器或设备。It then returns 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 that runs 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. 它成功解析为在三个示例应用服务环境之一(在这种情况下是这三个应用服务环境中的第二个)上运行的应用实例:It successfully resolves to an app instance that runs 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.