使用 Azure CLI 的流量管理器子网替代Traffic Manager subnet override using Azure CLI

使用流量管理器子网替代可以更改配置文件的路由方法。Traffic Manager subnet override allows you to alter the routing method of a profile. 添加替代后,会使用预定义的 IP 范围到终结点的映射,基于最终用户的 IP 地址来定向流量。The addition of an override will direct traffic based upon the end user's IP address with a predefined IP range to endpoint mapping.

子网替代的工作原理How subnet override works

将子网替代添加到流量管理器配置文件后,流量管理器会先检查最终用户的 IP 地址是否存在子网替代。When subnet overrides are added to a traffic manager profile, Traffic Manager will first check if there's a subnet override for the end user's IP address. 如果找到了一个替代,用户的 DNS 查询将定向到相应的终结点。If one is found, the user's DNS query will be directed to the corresponding endpoint. 如果找不到映射,流量管理器将回退到配置文件的原始路由方法。If a mapping is not found, Traffic Manager will fall back to the profile's original routing method.

可将 IP 地址范围指定为 CIDR 范围(例如 1.2.3.0/24)或地址范围(例如 1.2.3.4-5.6.7.8)。The IP address ranges can be specified as either CIDR ranges (for example, 1.2.3.0/24) or as address ranges (for example, 1.2.3.4-5.6.7.8). 与每个终结点关联的 IP 范围对于该终结点必须是唯一的。The IP ranges associated with each endpoint must be unique to that endpoint. 不同终结点之间的 IP 范围出现任何重叠会导致流量管理器拒绝配置文件。Any overlap of IP ranges among different endpoints will cause the profile to be rejected by Traffic Manager.

有两种类型的路由配置文件支持子网替代:There are two types of routing profiles that support subnet overrides:

  • 地理 - 如果流量管理器找到了 DNS 查询的 IP 地址的子网替代,它会将该查询路由到终结点,而不管该终结点的运行状况如何。Geographic - If Traffic Manager finds a subnet override for the DNS query's IP address, it will route the query to the endpoint whatever the health of the endpoint is.
  • 性能 - 如果流量管理器找到了 DNS 查询的 IP 地址的子网替代,它只会将流量路由到正常的终结点。Performance - If Traffic Manager finds a subnet override for the DNS query's IP address, it will only route the traffic to the endpoint if it's healthy. 如果子网替代终结点不正常,流量管理器将回退到性能路由试探法。Traffic Manager will fall back to the performance routing heuristic if the subnet override endpoint isn't healthy.

创建流量管理器子网替代Create a Traffic Manager subnet override

若要创建流量管理器子网替代,可以使用 Azure CLI 将替代子网添加到流量管理器终结点。To create a Traffic Manager subnet override, you can use Azure CLI to add the subnets for the override to the Traffic Manager endpoint.

Azure CLIAzure CLI

备注

在 Azure China 中使用 Azure CLI 2.0 之前,请首先运行 az cloud set -n AzureChinaCloud 更改云环境。Before you can use Azure CLI 2.0 in Azure China, please run az cloud set -n AzureChinaCloud first to change the cloud environment. 如果要切换回全局 Azure,请再次运行 az cloud set -n AzureCloudIf you want to switch back to Global Azure, run az cloud set -n AzureCloud again.

如果选择在本地安装并使用 CLI,本教程要求运行 Azure CLI 2.0.28 版或更高版本。If you choose to install and use the CLI locally, this tutorial requires that you are running a version of the Azure CLI version 2.0.28 or later. 若要查找版本,请运行 az --versionTo find the version, run az --version. 如果需要进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install Azure CLI.

使用子网替代更新流量管理器终结点。Update the Traffic Manager endpoint with subnet override.

使用 Azure CLI 通过 az network traffic-manager endpoint update 更新终结点。Use Azure CLI to update your endpoint with az network traffic-manager endpoint update.

### Add a range of IPs ###
az network traffic-manager endpoint update \
    --name MyEndpoint \
    --profile-name MyTmProfile \
    --resource-group MyResourceGroup \
    --subnets 1.2.3.4-5.6.7.8 \
    --type AzureEndpoints

### Add a subnet ###
az network traffic-manager endpoint update \
    --name MyEndpoint \
    --profile-name MyTmProfile \
    --resource-group MyResourceGroup \
    --subnets 9.10.11.0:24 \
    --type AzureEndpoints

可以在运行 az network traffic-manager endpoint update 时使用 --remove 选项,以便删除 IP 地址范围。You can remove the IP address ranges by running the az network traffic-manager endpoint update with the --remove option.

az network traffic-manager endpoint update \
    --name MyEndpoint \
    --profile-name MyTmProfile \
    --resource-group MyResourceGroup \
    --remove subnets \
    --type AzureEndpoints

后续步骤Next Steps

详细了解流量管理器流量路由方法Learn more about Traffic Manager traffic routing methods.

了解子网流量路由方法Learn about the Subnet traffic-routing method