流量管理器路由方法Traffic Manager routing methods

Azure 流量管理器支持使用六种流量路由方法来确定如何将网络流量路由到不同的服务终结点。Azure Traffic Manager supports six traffic-routing methods to determine how to route network traffic to the various service endpoints. 对于任何配置文件,流量管理器将关联到它的流量路由方法应用于它收到的每个 DNS 查询。For any profile, Traffic Manager applies the traffic-routing method associated to it to each DNS query it receives. 流量路由方法确定要在 DNS 响应中返回哪个终结点。The traffic-routing method determines which endpoint is returned in the DNS response.

流量管理器中提供了以下流量路由方法:The following traffic routing methods are available in Traffic Manager:

  • 优先级 如果想要使用主服务终结点来处理所有流量,并提供备份来防范主终结点或备份终结点不可用的情况,可以选择“优先级”。 Priority: Select Priority when you want to use a primary service endpoint for all traffic, and provide backups in case the primary or the backup endpoints are unavailable.
  • 加权 如果想要将流量分配到一组终结点上,不管是平均分配还是根据所定义的权重进行分配,都可以选择“加权” 。Weighted: Select Weighted when you want to distribute traffic across a set of endpoints, either evenly or according to weights, which you define.
  • 性能 如果终结点位于不同的地理位置,并且希望最终用户依据最低网络延迟使用“最近的”终结点,可以选择“性能” 。Performance: Select Performance when you have endpoints in different geographic locations and you want end users to use the "closest" endpoint in terms of the lowest network latency.
  • 地理 选择“地理” ,以便根据用户的 DNS 查询所源自的地理位置将用户定向到特定终结点(“Azure”、“外部”或“嵌套”)。Geographic: Select Geographic so that users are directed to specific endpoints (Azure, External, or Nested) based on which geographic location their DNS query originates from. 这使流量管理器客户可以启用特定的方案:在这些方案中,了解用户的地理区域,并基于该地理区域路由用户很重要。This empowers Traffic Manager customers to enable scenarios where knowing a user's geographic region and routing them based on that is important. 示例包括遵守数据所有权要求、内容本地化和用户体验,以及测量来自不同区域的流量。Examples include complying with data sovereignty mandates, localization of content & user experience and measuring traffic from different regions.
  • 多值 对于只能包含 IPv4/IPv6 地址作为终结点的流量管理器配置文件,请选择“多值”。 Multivalue: Select MultiValue for Traffic Manager profiles that can only have IPv4/IPv6 addresses as endpoints. 当收到针对此配置文件的查询时,将返回所有正常运行的终结点。When a query is received for this profile, all healthy endpoints are returned.
  • 子网 若要在流量管理器配置文件中将最终用户 IP 地址范围集映射到特定终结点,请选择“子集”。 Subnet: Select Subnet traffic-routing method to map sets of end-user IP address ranges to a specific endpoint within a Traffic Manager profile. 当收到请求时,将返回为该请求的源 IP 地址映射的终结点。When a request is received, the endpoint returned will be the one mapped for that request's source IP address. 

所有流量管理器配置文件都包括监视终结点运行状况以及终结点自动故障转移的设置。All Traffic Manager profiles include monitoring of endpoint health and automatic endpoint failover. 有关详细信息,请参阅流量管理器终结点监视For more information, see Traffic Manager Endpoint Monitoring. 一个流量管理器配置文件只能使用一种流量路由方法。A single Traffic Manager profile can use only one traffic routing method. 可以随时为配置文件选择其他流量路由方法。You can select a different traffic routing method for your profile at any time. 一分钟内即可应用所做的更改,不会导致停机。Changes are applied within one minute, and no downtime is incurred. 可以通过嵌套式流量管理器配置文件来组合使用多种流量路由方法。Traffic-routing methods can be combined by using nested Traffic Manager profiles. 使用嵌套可以启用复杂且灵活的流量路由配置,满足更大、更复杂应用程序的需求。Nesting enables sophisticated and flexible traffic-routing configurations that meet the needs of larger, complex applications. 有关详细信息,请参阅嵌套式流量管理器配置文件For more information, see nested Traffic Manager profiles.

“优先级”流量路由方法Priority traffic-routing method

组织往往会提供一个或多个备份服务来防范主服务发生故障,从而确保其服务的可靠性。Often an organization wants to provide reliability for its services by deploying one or more backup services in case their primary service goes down. Azure 客户可以通过“优先级”流量路由方法来轻松实现此故障转移模式。The 'Priority' traffic-routing method allows Azure customers to easily implement this failover pattern.

Azure 流量管理器的“优先级”流量路由方法

流量管理器配置文件包含服务终结点的优先顺序列表。The Traffic Manager profile contains a prioritized list of service endpoints. 默认情况下,流量管理器将所有流量发送到主终结点(优先级最高)。By default, Traffic Manager sends all traffic to the primary (highest-priority) endpoint. 如果主终结点不可用,流量管理器会将流量路由到第二个终结点。If the primary endpoint is not available, Traffic Manager routes the traffic to the second endpoint. 如果主终结点和辅助终结点都不可用,流量会转到第三个终结点,依此类推。If both the primary and secondary endpoints are not available, the traffic goes to the third, and so on. 终结点的可用性取决于配置的状态(已启用或已禁用)和正在进行的终结点监视。Availability of the endpoint is based on the configured status (enabled or disabled) and the ongoing endpoint monitoring.

配置终结点Configuring endpoints

在 Azure Resource Manager 中,可以使用每个终结点的“priority”属性显式配置终结点优先级。With Azure Resource Manager, you configure the endpoint priority explicitly using the 'priority' property for each endpoint. 此属性是一个介于 1 和 1000 之间的值。This property is a value between 1 and 1000. 值越小,优先级越高。Lower values represent a higher priority. 终结点不能共享优先级值。Endpoints cannot share priority values. 该属性的设置是可选的。Setting the property is optional. 如果省略该属性,会根据终结点顺序使用默认优先级。When omitted, a default priority based on the endpoint order is used.

“加权”流量路由方法Weighted traffic-routing method

使用“加权”流量路由方法可以均匀分布流量,或使用预定义的权重。The 'Weighted' traffic-routing method allows you to distribute traffic evenly or to use a pre-defined weighting.

Azure 流量管理器的“加权”流量路由方法

在“加权”流量路由方法中,需要为流量管理器配置文件中的每个终结点分配一个权重。In the Weighted traffic-routing method, you assign a weight to each endpoint in the Traffic Manager profile configuration. 该权重是从 1 到 1000 的整数。The weight is an integer from 1 to 1000. 此参数是可选的。This parameter is optional. 如果省略此参数,流量管理器会使用默认权重“1”。If omitted, Traffic Managers uses a default weight of '1'. 权重越高,优先级就越高。The higher weight, the higher the priority.

对于收到的每个 DNS 查询,流量管理器会随机选择一个可用终结点。For each DNS query received, Traffic Manager randomly chooses an available endpoint. 选择哪个终结点取决于分配到所有可用终结点的权重。The probability of choosing an endpoint is based on the weights assigned to all available endpoints. 对所有终结点使用相同的权重会导致均匀分布流量。Using the same weight across all endpoints results in an even traffic distribution. 对特定的终结点使用较高或较低的权重会导致这些终结点在 DNS 响应中的返回次数较多或较少。Using higher or lower weights on specific endpoints causes those endpoints to be returned more or less frequently in the DNS responses.

加权方法可以实现一些有用的方案:The weighted method enables some useful scenarios:

  • 应用程序逐步升级:分配要路由到新终结点的流量百分比,并随着时间的推移逐渐将流量增加到 100%。Gradual application upgrade: Allocate a percentage of traffic to route to a new endpoint, and gradually increase the traffic over time to 100%.
  • 将应用程序迁移到 Azure:创建包含 Azure 终结点和外部终结点的配置文件。Application migration to Azure: Create a profile with both Azure and external endpoints. 调整终结点的权重,优先选择新终结点。Adjust the weight of the endpoints to prefer the new endpoints.
  • 适用于更多容量的云爆发:通过将本地部署放在流量管理器配置文件之后,快速将本地部署扩展到云中。Cloud-bursting for additional capacity: Quickly expand an on-premises deployment into the cloud by putting it behind a Traffic Manager profile. 当你需要在云中获得额外的容量时,可以添加或启用更多终结点,并指定哪部分流量将流向每个终结点。When you need extra capacity in the cloud, you can add or enable more endpoints and specify what portion of traffic goes to each endpoint.

除了使用 Azure 门户之外,还可以使用 Azure PowerShell、CLI 和 REST API 配置权重。In addition to using the Azure portal, you can configure weights using Azure PowerShell, CLI, and the REST APIs.

必须知道,客户端及其用来解析 DNS 名称的递归 DNS 服务器会缓存 DNS 响应。It is important to understand that DNS responses are cached by clients and by the recursive DNS servers that the clients use to resolve DNS names. 这种缓存可能会影响到加权流量分布。This caching can have an impact on weighted traffic distributions. 如果客户端和递归 DNS 服务器的数目较大,流量分布将按预期工作。When the number of clients and recursive DNS servers is large, traffic distribution works as expected. 但是,如果客户端或递归 DNS 服务器的数目较小,缓存可能会严重影响流量分布。However, when the number of clients or recursive DNS servers is small, caching can significantly skew the traffic distribution.

常见用例包括:Common use cases include:

  • 开发和测试环境Development and testing environments
  • 应用程序间通信Application-to-application communications
  • 目标用户群体较小、共享一个公用递归 DNS 基础结构的应用程序(例如,公司的员工通过代理进行连接)Applications aimed at a narrow user-base that share a common recursive DNS infrastructure (for example, employees of company connecting through a proxy)

这些 DNS 缓存影响常见于所有基于 DNS 的流量路由系统,不只存在于 Azure 流量管理器上。These DNS caching effects are common to all DNS-based traffic routing systems, not just Azure Traffic Manager. 在某些情况下,显式清除 DNS 缓存可能会解决问题。In some cases, explicitly clearing the DNS cache may provide a workaround. 在另外一些情况下,可能更适合使用替代性流量路由方法。In other cases, an alternative traffic-routing method may be more appropriate.

“性能”流量路由方法Performance traffic-routing method

在国家/地区的两个或更多位置部署终结点,将流量路由到“最靠近”用户的位置,即可改善许多应用程序的响应能力。Deploying endpoints in two or more locations across the nation can improve the responsiveness of many applications by routing traffic to the location that is 'closest' to you. “性能”流量路由方法提供这种能力。The 'Performance' traffic-routing method provides this capability.

Azure 流量管理器的“性能”流量路由方法

“最靠近”的终结点不一定是地理距离最近的终结点。The 'closest' endpoint is not necessarily closest as measured by geographic distance. “性能”流量路由方法通过测试网络延迟来确定最靠近的终结点。Instead, the 'Performance' traffic-routing method determines the closest endpoint by measuring network latency. 流量管理器维护一份 Internet 延迟表,用于跟踪 IP 地址范围与每个 Azure 数据中心之间的往返时间。Traffic Manager maintains an Internet Latency Table to track the round-trip time between IP address ranges and each Azure datacenter.

流量管理器在 Internet 延迟表中查找传入 DNS 请求的源 IP 地址。Traffic Manager looks up the source IP address of the incoming DNS request in the Internet Latency Table. 然后,流量管理器在处理该 IP 地址范围的请求时具有最低延迟的 Azure 数据中心内选择一个可用终结点,并在 DNS 响应中返回该终结点。Traffic Manager then chooses an available endpoint in the Azure datacenter that has the lowest latency for that IP address range, and returns that endpoint in the DNS response.

流量管理器工作原理中所述,流量管理器不会直接从客户端接收 DNS 查询。As explained in How Traffic Manager Works, Traffic Manager does not receive DNS queries directly from clients. DNS 查询来自客户端配置使用的递归 DNS 服务。Rather, DNS queries come from the recursive DNS service that the clients are configured to use. 因此,用于确定“最靠近”终结点的 IP 地址不是客户端的 IP 地址,而是递归 DNS 服务的 IP 地址。Therefore, the IP address used to determine the 'closest' endpoint is not the client's IP address, but it is the IP address of the recursive DNS service. 在实践中,此 IP 地址是客户端的适当代理。In practice, this IP address is a good proxy for the client.

流量管理器定期更新 Internet 延迟表,反映全国 Internet 的变化以及新的 Azure 区域。Traffic Manager regularly updates the Internet Latency Table to account for changes in the national Internet and new Azure regions. 但是,由于 Internet 上的负载会实时变化,应用程序性能也会随之变化。However, application performance varies based on real-time variations in load across the Internet. “性能”流量路由不会监视给定服务终结点上的负载。Performance traffic-routing does not monitor load on a given service endpoint. 但是,如果某个终结点变得不可用,则流量管理器不会在 DNS 查询响应中包括该终结点。However, if an endpoint becomes unavailable, Traffic Manager does not include it in DNS query responses.

需要注意的要点:Points to note:

  • 如果配置文件包含同一 Azure 区域中的多个终结点,流量管理器会在该区域中的可用终结点之间均匀分布流量。If your profile contains multiple endpoints in the same Azure region, then Traffic Manager distributes traffic evenly across the available endpoints in that region. 如果想要在某个区域中采用不同的流量分布,可以使用嵌套式流量管理器配置文件If you prefer a different traffic distribution within a region, you can use nested Traffic Manager profiles.
  • 如果最近的 Azure 区域中所有启用的终结点已降级,则流量管理器会将流量移到下一个最近的 Azure 区域中的终结点。If all enabled endpoints in the closest Azure region are degraded, Traffic Manager moves traffic to the endpoints in the next closest Azure region. 如果想要定义首选故障转移顺序,请使用嵌套式流量管理器配置文件If you want to define a preferred failover sequence, use nested Traffic Manager profiles.
  • 对外部终结点或嵌套式终结点使用“性能”流量路由方法时,需要指定这些终结点的位置。When using the Performance traffic routing method with external endpoints or nested endpoints, you need to specify the location of those endpoints. 请选择离部署最近的 Azure 区域。Choose the Azure region closest to your deployment. 这些位置是 Internet 延迟表支持的值。Those locations are the values supported by the Internet Latency Table.
  • 选择终结点的算法是确定性的。The algorithm that chooses the endpoint is deterministic. 同一个客户端重复发出的 DNS 查询会定向到同一个终结点。Repeated DNS queries from the same client are directed to the same endpoint. 通常,客户端在遍历时使用不同的递归 DNS 服务器。Typically, clients use different recursive DNS servers when traveling. 客户端可以路由到不同的终结点。The client may be routed to a different endpoint. 更新 Internet 延迟表也可能会影响路由。Routing can also be affected by updates to the Internet Latency Table. 因此,“性能”流量路由方法不保证始终将客户端路由到同一个终结点。Therefore, the Performance traffic-routing method does not guarantee that a client is always routed to the same endpoint.
  • 更改 Internet 延迟表时,可能会注意到某些客户端被定向到其他终结点。When the Internet Latency Table changes, you may notice that some clients are directed to a different endpoint. 这种路由更改基于当前延迟数据,因此更加准确。This routing change is more accurate based on current latency data. 进行这些更新很重要,可以确保在 Internet 持续发展的情况下“性能”流量路由的准确性。These updates are essential to maintain the accuracy of Performance traffic-routing as the Internet continually evolves.

多值流量路由方法Multivalue traffic-routing method

多值流量路由方法允许你在单个 DNS 查询响应中获得多个正常运行的终结点。The Multivalue traffic-routing method allows you to get multiple healthy endpoints in a single DNS query response. 这使得调用方在返回的某个终结点无法响应时能够通过其他终结点进行重试。This enables to caller to do client-side retries with other endpoints in the event of a returned endpoint being unresponsive. 此模式可以提高服务可用性,并降低与新 DNS 查询获取正常运行的终结点相关的延迟。This pattern can increase the availability of a service and reduce the latency associated with a new DNS query to obtain a healthy endpoint. 只有当所有终结点的类型都是“外部”并且指定为 IPv4 或 IPv6 地址时,多值路由方法才有效。MultiValue routing method works only if all the endpoints of type 'External' and are specified as IPv4 or IPv6 addresses. 当收到对此配置文件的查询时,会根据可配置的最大返回计数返回所有正常运行的终结点。When a query is received for this profile, all healthy endpoints are returned and are subject to a configurable maximum return count.

子网流量路由方法Subnet traffic-routing method

子网流量路由方法允许你将一个最终用户 IP 地址范围集映射到配置文件中的特定终结点。The Subnet traffic-routing method allows you to map a set of end user IP address ranges to specific endpoints in a profile. 此后,如果流量管理器收到针对该配置文件的 DNS 查询,则它将检查该请求的源 IP 地址(大多数情况下,这是调用方使用的 DNS 解析程序的传出 IP 地址),确定它映射到哪个终结点,并在查询响应中返回该终结点。After that, if Traffic Manager receives a DNS query for that profile, it will inspect the source IP address of that request (in most cases this will be the outgoing IP address of the DNS resolver used by the caller), determine which endpoint it is mapped to and will return that endpoint in the query response.

可以将要映射到终结点的 IP 地址指定为 CIDR 范围(例如 1.2.3.0/24)或地址范围(例如 1.2.3.4-5.6.7.8)。The IP address to be mapped to an endpoint can be specified as CIDR ranges (e.g. 1.2.3.0/24) or as an address range (e.g. 1.2.3.4-5.6.7.8). 与某个终结点关联的 IP 范围在该配置文件中必须是唯一的,并且不能与同一配置文件中另一个终结点的 IP 地址集重叠。The IP ranges associated with an endpoint need to be unique within that profile and cannot have an overlap with the IP address set of a different endpoint in the same profile. 如果定义一个没有地址范围的终结点,则该终结点将用作回退终结点并从任何剩余的子网获取流量。If you define an endpoint with no address range, that functions as a fallback and take traffic from any remaining subnets. 如果未包含回退终结点,则流量管理器会针对任何未定义的范围发送 NODATA 响应。If no fallback endpoint is included, Traffic Manager sends a NODATA response for any undefined ranges. 因此,强烈建议你定义回退终结点,或者确保在终结点上指定所有可能的 IP 范围。It is therefore highly recommended that you either define a fallback endpoint, or else ensure that all possible IP ranges are specified across your endpoints.

子网路由可以用来为从特定 IP 空间进行连接的用户提供不同的体验。Subnet routing can be used to deliver a different experience for users connecting from a specific IP space. 例如,使用子网路由,客户可以将来自其公司的所有请求路由到一个不同的终结点,他们可以在这里测试其应用的仅限内部版本。For example, using subnet routing, a customer can make all requests from their corporate office be routed to a different endpoint where they might be testing an internal only version of their app. 另一种情况是,你可能希望为从特定 ISP 进行连接的用户提供不同的体验(例如,阻止来自给定 ISP 的用户)。Another scenario is if you want to provide a different experience to users connecting from a specific ISP (For example, block users from a given ISP).

后续步骤Next steps

了解如何使用流量管理器终结点监视开发高可用性应用程序Learn how to develop high-availability applications using Traffic Manager endpoint monitoring