使用 PowerShell 管理流量管理器Using PowerShell to manage Traffic Manager

Azure Resource Manager 是 Azure 中的首选服务管理接口。Azure Resource Manager is the preferred management interface for services in Azure. 可以使用基于 Azure Resource Manager 的 API 和工具来管理 Azure 流量管理器配置文件。Azure Traffic Manager profiles can be managed using Azure Resource Manager-based APIs and tools.

备注

本文进行了更新,以便使用新的 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.

资源模型Resource model

Azure 流量管理器是使用名为流量管理器配置文件的一系列设置进行配置的。Azure Traffic Manager is configured using a collection of settings called a Traffic Manager profile. 此配置文件包含 DNS 设置、流量路由设置、终结点监视设置,以及流量要路由到的服务终结点列表。This profile contains DNS settings, traffic routing settings, endpoint monitoring settings, and a list of service endpoints to which traffic is routed.

每个流量管理器配置文件以一个“TrafficManagerProfiles”类型的资源表示。Each Traffic Manager profile is represented by a resource of type 'TrafficManagerProfiles'. 在 REST API 级别,每个配置文件的 URI 如下:At the REST API level, the URI for each profile is as follows:

https://management.chinacloudapi.cn/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Network/trafficManagerProfiles/{profile-name}?api-version={api-version}

设置 Azure PowerShellSetting up Azure PowerShell

备注

本文进行了更新,以便使用新的 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.

本部分中的说明使用 Azure PowerShell。These instructions use Azure PowerShell. 以下文章介绍了如何安装和配置 Azure PowerShell。The following article explains how to install and configure Azure PowerShell.

本文中的示例假设已有一个资源组。The examples in this article assume that you have an existing resource group. 可以使用以下命令创建资源组:You can create a resource group using the following command:

New-AzResourceGroup -Name MyRG -Location "China North"

备注

Azure Resource Manager 要求所有资源组都有一个位置。Azure Resource Manager requires that all resource groups have a location. 此位置用作该资源组中创建的资源的默认位置。This location is used as the default for resources created in that resource group. 但是,由于流量管理器配置文件资源是全局性而不是区域性的,因此,所选的资源组位置不会影响 Azure 流量管理器。However, since Traffic Manager profile resources are global, not regional, the choice of resource group location has no impact on Azure Traffic Manager.

创建流量管理器配置文件Create a Traffic Manager Profile

若要创建流量管理器配置文件,请使用 New-AzTrafficManagerProfile cmdlet:To create a Traffic Manager profile, use the New-AzTrafficManagerProfile cmdlet:

$TmProfile = New-AzTrafficManagerProfile -Name MyProfile -ResourceGroupName MyRG -TrafficRoutingMethod Performance -RelativeDnsName contoso -Ttl 30 -MonitorProtocol HTTP -MonitorPort 80 -MonitorPath "/"

下表描述了参数:The following table describes the parameters:

参数Parameter 说明Description
名称Name 流量管理器配置文件资源的资源名称。The resource name for the Traffic Manager profile resource. 同一资源组中的配置文件必须具有唯一的名称。Profiles in the same resource group must have unique names. 此名称不同于用于 DNS 查询的 DNS 名称。This name is separate from the DNS name used for DNS queries.
ResourceGroupNameResourceGroupName 包含配置文件资源的资源组的名称The name of the resource group containing the profile resource.
TrafficRoutingMethodTrafficRoutingMethod 指定流量路由方法,用于确定在响应 DNS 查询时要返回的终结点。Specifies the traffic-routing method used to determine which endpoint is returned in response a DNS query. 可能的值为“Performance”、“Weighted”或“Priority”。Possible values are 'Performance', 'Weighted' or 'Priority'.
RelativeDnsNameRelativeDnsName 指定此流量管理器配置文件提供的 DNS 名称的主机名部分。Specifies the hostname portion of the DNS name provided by this Traffic Manager profile. 将此值与 Azure 流量管理器使用的 DNS 域名相结合,可以构成配置文件的完全限定域名 (FQDN)。This value is combined with the DNS domain name used by Azure Traffic Manager to form the fully qualified domain name (FQDN) of the profile. 例如,设置“contoso”值可以构成“contoso.trafficmanager.cn”。For example, setting the value of 'contoso' becomes 'contoso.trafficmanager.cn.'
TTLTTL 指定 DNS 生存时间 (TTL),以秒为单位。Specifies the DNS Time-to-Live (TTL), in seconds. 此 TTL 通知本地 DNS 解析器和 DNS 客户端缓存此流量管理器配置文件的 DNS 响应的时长。This TTL informs the Local DNS resolvers and DNS clients how long to cache DNS responses for this Traffic Manager profile.
MonitorProtocolMonitorProtocol 指定用于监视终结点运行状况的协议。Specifies the protocol to use to monitor endpoint health. 可能的值为“HTTP”和“HTTPS”。Possible values are 'HTTP' and 'HTTPS'.
MonitorPortMonitorPort 指定用于监视终结点运行状况的 TCP 端口。Specifies the TCP port used to monitor endpoint health.
MonitorPathMonitorPath 指定用于探测终结点运行状况的终结点域名的相对路径。Specifies the path relative to the endpoint domain name used to probe for endpoint health.

该 cmdlet 在 Azure 流量管理器中创建流量管理器配置文件,将相应的配置文件对象返回到 PowerShell。The cmdlet creates a Traffic Manager profile in Azure and returns a corresponding profile object to PowerShell. 此时,配置文件不包含任何终结点。At this point, the profile does not contain any endpoints. 有关将终结点添加到流量管理器配置文件的详细信息,请参阅“添加流量管理器终结点”。For more information about adding endpoints to a Traffic Manager profile, see Adding Traffic Manager Endpoints.

获取流量管理器配置文件Get a Traffic Manager Profile

若要检索现有的流量管理器配置文件对象,请使用 Get-AzTrafficManagerProfle cmdlet:To retrieve an existing Traffic Manager profile object, use the Get-AzTrafficManagerProfle cmdlet:

$TmProfile = Get-AzTrafficManagerProfile -Name MyProfile -ResourceGroupName MyRG

此 cmdlet 返回流量管理器配置文件对象。This cmdlet returns a Traffic Manager profile object.

更新流量管理器配置文件Update a Traffic Manager Profile

修改流量管理器配置文件遵循 3 步流程:Modifying Traffic Manager profiles follows a 3-step process:

  1. 使用 Get-AzTrafficManagerProfile 检索配置文件,或使用 New-AzTrafficManagerProfile 返回的配置文件。Retrieve the profile using Get-AzTrafficManagerProfile or use the profile returned by New-AzTrafficManagerProfile.
  2. 修改配置文件。Modify the profile. 可以添加和删除终结点,或者更改终结点或配置文件参数。You can add and remove endpoints or change endpoint or profile parameters. 这些更改属于脱机操作。These changes are off-line operations. 只是更改了内存中代表配置文件的本地对象。You are only changing the local object in memory that represents the profile.
  3. 使用 Set-AzTrafficManagerProfile cmdlet 提交更改。Commit your changes using the Set-AzTrafficManagerProfile cmdlet.

所有的配置文件属性都可更改,配置文件的 RelativeDnsName 除外。All profile properties can be changed except the profile's RelativeDnsName. 如果要更改 RelativeDnsName,必须删除配置文件,并使用新名称新建一个配置文件。To change the RelativeDnsName, you must delete profile and a new profile with a new name.

以下示例演示如何更改配置文件的 TTL:The following example demonstrates how to change the profile's TTL:

$TmProfile = Get-AzTrafficManagerProfile -Name MyProfile -ResourceGroupName MyRG
$TmProfile.Ttl = 300
Set-AzTrafficManagerProfile -TrafficManagerProfile $TmProfile

有三种类型的流量管理器终结点:There are three types of Traffic Manager endpoints:

  1. Azure 终结点 是在 Azure 中托管的服务Azure endpoints are services hosted in Azure
  2. 外部终结点 是在 Azure 外部托管的服务External endpoints are services hosted outside of Azure
  3. 嵌套式终结点 用于构造流量管理器配置文件的嵌套式层次结构。Nested endpoints are used to construct nested hierarchies of Traffic Manager profiles. 嵌套式终结点可以针对复杂的应用程序启用高级流量路由配置。Nested endpoints enable advanced traffic-routing configurations for complex applications.

在所有三种情况下,都可以通过两种方式添加终结点:In all three cases, endpoints can be added in two ways:

  1. 使用上面所述的三步骤过程。Using a 3-step process described previously. 此方法的优点是可以通过一次更新完成多项终结点更改。The advantage of this method is that several endpoint changes can be made in a single update.
  2. 使用 New-AzTrafficManagerEndpoint cmdlet。Using the New-AzTrafficManagerEndpoint cmdlet. 此 cmdlet 通过一个操作将终结点添加到现有的流量管理器配置文件。This cmdlet adds an endpoint to an existing Traffic Manager profile in a single operation.

添加 Azure 终结点Adding Azure Endpoints

Azure 终结点引用 Azure 中托管的服务。Azure endpoints reference services hosted in Azure. 支持 2 种类型的 Azure 终结点:Two types of Azure endpoints are supported:

  1. Azure 应用服务Azure App Service
  2. Azure PublicIpAddress 资源(可以附加到负载均衡器或虚拟机 NIC)。Azure PublicIpAddress resources (which can be attached to a load-balancer or a virtual machine NIC). 必须为 PublicIpAddress 分配一个 DNS 名称,才能在流量管理器中使用。The PublicIpAddress must have a DNS name assigned to be used in Traffic Manager.

在每种情况下:In each case:

  • 服务是使用 Add-AzTrafficManagerEndpointConfigNew-AzTrafficManagerEndpoint 的“targetResourceId”参数指定。The service is specified using the 'targetResourceId' parameter of Add-AzTrafficManagerEndpointConfig or New-AzTrafficManagerEndpoint.
  • “Target”和“EndpointLocation”由 TargetResourceId 表明。The 'Target' and 'EndpointLocation' are implied by the TargetResourceId.
  • 指定“Weight”是可选操作。Specifying the 'Weight' is optional. 仅当配置文件配置为使用“加权”流量路由方法时,才使用权重。Weights are only used if the profile is configured to use the 'Weighted' traffic-routing method. 否则会忽略该参数。Otherwise, they are ignored. 如果指定权重,其值必须是介于 1 和 1000 之间的数字。If specified, the value must be a number between 1 and 1000. 默认值为“1”。The default value is '1'.
  • 指定“Priority”是可选操作。Specifying the 'Priority' is optional. 仅当配置文件配置为使用“优先级”流量路由方法时,才使用优先级。Priorities are only used if the profile is configured to use the 'Priority' traffic-routing method. 否则会忽略该参数。Otherwise, they are ignored. 有效值为从 1 到 1000,值越小,优先级越高。Valid values are from 1 to 1000 with lower values indicating a higher priority. 如果为一个终结点指定了该值,则必须为所有终结点指定该值。If specified for one endpoint, they must be specified for all endpoints. 如果省略该参数,将按终结点的列出顺序应用默认值(从 1 开始)。If omitted, default values starting from '1' are applied in the order that the endpoints are listed.

示例 1:使用 Add-AzTrafficManagerEndpointConfig 添加应用服务终结点Example 1: Adding App Service endpoints using Add-AzTrafficManagerEndpointConfig

在此示例中,创建了一个流量管理器配置文件,并使用 Add-AzTrafficManagerEndpointConfig cmdlet 添加了两个应用服务终结点。In this example, we create a Traffic Manager profile and add two App Service endpoints using the Add-AzTrafficManagerEndpointConfig cmdlet.

$TmProfile = New-AzTrafficManagerProfile -Name myprofile -ResourceGroupName MyRG -TrafficRoutingMethod Performance -RelativeDnsName myapp -Ttl 30 -MonitorProtocol HTTP -MonitorPort 80 -MonitorPath "/"
$webapp1 = Get-AzWebApp -Name webapp1
Add-AzTrafficManagerEndpointConfig -EndpointName webapp1ep -TrafficManagerProfile $TmProfile -Type AzureEndpoints -TargetResourceId $webapp1.Id -EndpointStatus Enabled
$webapp2 = Get-AzWebApp -Name webapp2
Add-AzTrafficManagerEndpointConfig -EndpointName webapp2ep -TrafficManagerProfile $TmProfile -Type AzureEndpoints -TargetResourceId $webapp2.Id -EndpointStatus Enabled
Set-AzTrafficManagerProfile -TrafficManagerProfile $TmProfile

示例 2:使用 New-AzTrafficManagerEndpoint 添加 publicIpAddress 终结点Example 2: Adding a publicIpAddress endpoint using New-AzTrafficManagerEndpoint

在此示例中,公共 IP 地址资源添加到了流量管理器配置文件中。In this example, a public IP address resource is added to the Traffic Manager profile. 公共 IP 地址必须配置了 DNS 名称,并且可以绑定到 VM 的 NIC 或者绑定到负载均衡器。The public IP address must have a DNS name configured, and can be bound either to the NIC of a VM or to a load balancer.

$ip = Get-AzPublicIpAddress -Name MyPublicIP -ResourceGroupName MyRG
New-AzTrafficManagerEndpoint -Name MyIpEndpoint -ProfileName MyProfile -ResourceGroupName MyRG -Type AzureEndpoints -TargetResourceId $ip.Id -EndpointStatus Enabled

添加外部终结点Adding External Endpoints

流量管理器使用外部终结点将流量定向到在 Azure 外部承载的服务。Traffic Manager uses external endpoints to direct traffic to services hosted outside of Azure. 与 Azure 终结点一样,可以使用 Add-AzTrafficManagerEndpointConfig(后跟 Set-AzTrafficManagerProfile)或 New-AzTrafficManagerEndpoint 添加外部终结点。As with Azure endpoints, external endpoints can be added either using Add-AzTrafficManagerEndpointConfig followed by Set-AzTrafficManagerProfile, or New-AzTrafficManagerEndpoint.

指定外部终结点时:When specifying external endpoints:

  • 必须使用“Target”参数指定终结点域名The endpoint domain name must be specified using the 'Target' parameter
  • 如果使用“性能”流量路由方法,则需要“EndpointLocation”。If the 'Performance' traffic-routing method is used, the 'EndpointLocation' is required. 否则,该参数是可选的。Otherwise it is optional. 该值必须是 有效的 Azure 区域名称The value must be a valid Azure region name.
  • “加权”和“优先级”是可选项。The 'Weight' and 'Priority' are optional.

示例 1:使用 Add-AzTrafficManagerEndpointConfigSet-AzTrafficManagerProfile 添加外部终结点Example 1: Adding external endpoints using Add-AzTrafficManagerEndpointConfig and Set-AzTrafficManagerProfile

本示例创建一个流量管理器配置文件,添加两个外部终结点,并提交所做的更改。In this example, we create a Traffic Manager profile, add two external endpoints, and commit the changes.

$TmProfile = New-AzTrafficManagerProfile -Name myprofile -ResourceGroupName MyRG -TrafficRoutingMethod Performance -RelativeDnsName myapp -Ttl 30 -MonitorProtocol HTTP -MonitorPort 80 -MonitorPath "/"
Add-AzTrafficManagerEndpointConfig -EndpointName eu-endpoint -TrafficManagerProfile $TmProfile -Type ExternalEndpoints -Target app-eu.contoso.com -EndpointLocation "China North" -EndpointStatus Enabled
Add-AzTrafficManagerEndpointConfig -EndpointName us-endpoint -TrafficManagerProfile $TmProfile -Type ExternalEndpoints -Target app-us.contoso.com -EndpointLocation "China North" -EndpointStatus Enabled
Set-AzTrafficManagerProfile -TrafficManagerProfile $TmProfile

示例 2:使用 New-AzTrafficManagerEndpoint 添加外部终结点Example 2: Adding external endpoints using New-AzTrafficManagerEndpoint

在此示例中,我们向已有配置文件添加了一个外部终结点。In this example, we add an external endpoint to an existing profile. 该配置文件是使用配置文件名称和资源组名称指定的。The profile is specified using the profile and resource group names.

New-AzTrafficManagerEndpoint -Name eu-endpoint -ProfileName MyProfile -ResourceGroupName MyRG -Type ExternalEndpoints -Target app-eu.contoso.com -EndpointStatus Enabled

添加“嵌套式”终结点Adding 'Nested' endpoints

每个流量管理器配置文件都会指定一个流量路由方法。Each Traffic Manager profile specifies a single traffic-routing method. 但在某些情况下,所需的流量路由方法比单个流量管理器配置文件所提供的方法更复杂。However, there are scenarios that require more sophisticated traffic routing than the routing provided by a single Traffic Manager profile. 可以嵌套流量管理器配置文件,将多个流量路由方法的优势结合在一起。You can nest Traffic Manager profiles to combine the benefits of more than one traffic-routing method. 使用嵌套式配置文件可以重写默认的流量管理器行为,支持更大、更复杂的应用程序部署。Nested profiles allow you to override the default Traffic Manager behavior to support larger and more complex application deployments. 有关更多详细示例,请参阅嵌套式流量管理器配置文件For more detailed examples, see Nested Traffic Manager profiles.

在父配置文件中使用特定的终结点类型“NestedEndpoints”配置嵌套式终结点。Nested endpoints are configured at the parent profile, using a specific endpoint type, 'NestedEndpoints'. 指定嵌套式终结点时:When specifying nested endpoints:

  • 必须使用“targetResourceId”参数指定终结点The endpoint must be specified using the 'targetResourceId' parameter
  • 如果使用“性能”流量路由方法,则需要“EndpointLocation”。If the 'Performance' traffic-routing method is used, the 'EndpointLocation' is required. 否则,该参数是可选的。Otherwise it is optional. 该值必须是 有效的 Azure 区域名称The value must be a valid Azure region name.
  • 与指定 Azure 终结点时一样,“Weight”和“Priority”是可选的。The 'Weight' and 'Priority' are optional, as for Azure endpoints.
  • “MinChildEndpoints”参数是可选的。The 'MinChildEndpoints' parameter is optional. 默认值为“1”。The default value is '1'. 如果可用终结点数低于此阈值,父配置文件会将子配置文件视为“已降级”,并将流量转移到父配置文件中的其他终结点。If the number of available endpoints falls below this threshold, the parent profile considers the child profile 'degraded' and diverts traffic to the other endpoints in the parent profile.

示例 1:使用 Add-AzTrafficManagerEndpointConfigSet-AzTrafficManagerProfile 添加嵌套终结点Example 1: Adding nested endpoints using Add-AzTrafficManagerEndpointConfig and Set-AzTrafficManagerProfile

在此示例中,我们创建新的流量管理器子配置文件和父配置文件,将子配置文件添加为父配置文件中的嵌套式终结点,并提交所做的更改。In this example, we create new Traffic Manager child and parent profiles, add the child as a nested endpoint to the parent, and commit the changes.

$child = New-AzTrafficManagerProfile -Name child -ResourceGroupName MyRG -TrafficRoutingMethod Priority -RelativeDnsName child -Ttl 30 -MonitorProtocol HTTP -MonitorPort 80 -MonitorPath "/"
$parent = New-AzTrafficManagerProfile -Name parent -ResourceGroupName MyRG -TrafficRoutingMethod Performance -RelativeDnsName parent -Ttl 30 -MonitorProtocol HTTP -MonitorPort 80 -MonitorPath "/"
Add-AzTrafficManagerEndpointConfig -EndpointName child-endpoint -TrafficManagerProfile $parent -Type NestedEndpoints -TargetResourceId $child.Id -EndpointStatus Enabled -EndpointLocation "China North" -MinChildEndpoints 2
Set-AzTrafficManagerProfile -TrafficManagerProfile $parent

为简洁起见,本示例未将其他任何终结点添加到子配置文件或父配置文件。For brevity in this example, we did not add any other endpoints to the child or parent profiles.

示例 2:使用 New-AzTrafficManagerEndpoint 添加嵌套终结点Example 2: Adding nested endpoints using New-AzTrafficManagerEndpoint

本示例将现有的子配置文件作为嵌套式终结点添加到现有的父配置文件。In this example, we add an existing child profile as a nested endpoint to an existing parent profile. 该配置文件是使用配置文件名称和资源组名称指定的。The profile is specified using the profile and resource group names.

$child = Get-AzTrafficManagerEndpoint -Name child -ResourceGroupName MyRG
New-AzTrafficManagerEndpoint -Name child-endpoint -ProfileName parent -ResourceGroupName MyRG -Type NestedEndpoints -TargetResourceId $child.Id -EndpointStatus Enabled -EndpointLocation "China North" -MinChildEndpoints 2

从其他订阅添加终结点Adding endpoints from another subscription

流量管理器可以使用不同订阅中的终结点。Traffic Manager can work with endpoints from different subscriptions. 需要使用要添加的终结点切换到订阅,以检索所需的流量管理器输入。You need to switch to the subscription with the endpoint you want to add to retrieve the needed input to Traffic Manager. 然后,需要使用流量管理器配置文件切换到订阅,并向其中添加终结点。Then you need to switch to the subscriptions with the Traffic Manager profile, and add the endpoint to it. 下面的示例演示如何使用公共 IP 地址执行此操作。The below example shows how to do this with a public IP address.

Set-AzContext -SubscriptionId $EndpointSubscription
$ip = Get-AzPublicIpAddress -Name $IpAddressName -ResourceGroupName $EndpointRG

Set-AzContext -SubscriptionId $trafficmanagerSubscription
New-AzTrafficManagerEndpoint -Name $EndpointName -ProfileName $ProfileName -ResourceGroupName $TrafficManagerRG -Type AzureEndpoints -TargetResourceId $ip.Id -EndpointStatus Enabled

更新流量管理器终结点Update a Traffic Manager Endpoint

有两种方法可以更新现有的流量管理器终结点:There are two ways to update an existing Traffic Manager endpoint:

  1. 使用 Get-AzTrafficManagerProfile 获取流量管理器配置文件,更新配置文件中的终结点属性,然后使用 Set-AzTrafficManagerProfile 提交更改。Get the Traffic Manager profile using Get-AzTrafficManagerProfile, update the endpoint properties within the profile, and commit the changes using Set-AzTrafficManagerProfile. 此方法的优势在于能够通过单个操作更新多个终结点。This method has the advantage of being able to update more than one endpoint in a single operation.
  2. 使用 Get-AzTrafficManagerEndpoint 获取流量管理器终结点,更新终结点属性,然后使用 Set-AzTrafficManagerEndpoint 提交更改。Get the Traffic Manager endpoint using Get-AzTrafficManagerEndpoint, update the endpoint properties, and commit the changes using Set-AzTrafficManagerEndpoint. 此方法更简单,因为不需要在配置文件的终结点数组中进行索引操作。This method is simpler, since it does not require indexing into the Endpoints array in the profile.

示例 1:使用 Get-AzTrafficManagerProfileSet-AzTrafficManagerProfile 更新多个终结点Example 1: Updating endpoints using Get-AzTrafficManagerProfile and Set-AzTrafficManagerProfile

在此示例中,我们修改现有配置文件中两个终结点上的优先级。In this example, we modify the priority on two endpoints within an existing profile.

$TmProfile = Get-AzTrafficManagerProfile -Name myprofile -ResourceGroupName MyRG
$TmProfile.Endpoints[0].Priority = 2
$TmProfile.Endpoints[1].Priority = 1
Set-AzTrafficManagerProfile -TrafficManagerProfile $TmProfile

示例 2:使用 Get-AzTrafficManagerEndpointSet-AzTrafficManagerEndpoint 更新单个终结点Example 2: Updating an endpoint using Get-AzTrafficManagerEndpoint and Set-AzTrafficManagerEndpoint

在此示例中,我们修改现有配置文件中单个终结点的权重。In this example, we modify the weight of a single endpoint in an existing profile.

$endpoint = Get-AzTrafficManagerEndpoint -Name myendpoint -ProfileName myprofile -ResourceGroupName MyRG -Type ExternalEndpoints
$endpoint.Weight = 20
Set-AzTrafficManagerEndpoint -TrafficManagerEndpoint $endpoint

启用和禁用终结点和配置文件Enabling and Disabling Endpoints and Profiles

可以通过流量管理器启用和禁用各个终结点,以及启用和禁用整个配置文件。Traffic Manager allows individual endpoints to be enabled and disabled, as well as allowing enabling and disabling of entire profiles. 这些更改可以通过获取/更新/设置终结点或配置文件资源来完成。These changes can be made by getting/updating/setting the endpoint or profile resources. 为了简化这些常用操作,也可通过专用 cmdlet 来完成它们。To streamline these common operations, they are also supported via dedicated cmdlets.

示例 1:启用和禁用流量管理器配置文件Example 1: Enabling and disabling a Traffic Manager profile

若要启用流量管理器配置文件,请使用 Enable-AzTrafficManagerProfileTo enable a Traffic Manager profile, use Enable-AzTrafficManagerProfile. 可以使用配置文件对象指定该配置文件。The profile can be specified using a profile object. 可以通过管道或使用“-TrafficManagerProfile”参数传递配置文件对象。The profile object can be passed via the pipeline or by using the '-TrafficManagerProfile' parameter. 本示例按配置文件和资源组名称指定配置文件。In this example, we specify the profile by the profile and resource group name.

Enable-AzTrafficManagerProfile -Name MyProfile -ResourceGroupName MyResourceGroup

若要禁用流量管理器配置文件,请执行以下操作:To disable a Traffic Manager profile:

Disable-AzTrafficManagerProfile -Name MyProfile -ResourceGroupName MyResourceGroup

Disable-AzTrafficManagerProfile cmdlet 提示进行确认。The Disable-AzTrafficManagerProfile cmdlet prompts for confirmation. 可以使用“-Force”参数取消该提示。This prompt can be suppressed using the '-Force' parameter.

示例 2:启用和禁用流量管理器终结点Example 2: Enabling and disabling a Traffic Manager endpoint

若要启用流量管理器终结点,请使用 Enable-AzTrafficManagerEndpointTo enable a Traffic Manager endpoint, use Enable-AzTrafficManagerEndpoint. 有两种方法可以指定终结点There are two ways to specify the endpoint

  1. 使用通过管道传递的 TrafficManagerEndpoint 对象,或使用“-TrafficManagerEndpoint”参数Using a TrafficManagerEndpoint object passed via the pipeline or using the '-TrafficManagerEndpoint' parameter
  2. 使用终结点名称、终结点类型、配置文件名称和资源组名称:Using the endpoint name, endpoint type, profile name, and resource group name:
Enable-AzTrafficManagerEndpoint -Name MyEndpoint -Type AzureEndpoints -ProfileName MyProfile -ResourceGroupName MyRG

同样,若要禁用流量管理器终结点,请执行以下操作:Similarly, to disable a Traffic Manager endpoint:

Disable-AzTrafficManagerEndpoint -Name MyEndpoint -Type AzureEndpoints -ProfileName MyProfile -ResourceGroupName MyRG -Force

Disable-AzTrafficManagerProfile 一样,Disable-AzTrafficManagerEndpoint cmdlet 也会提示进行确认。As with Disable-AzTrafficManagerProfile, the Disable-AzTrafficManagerEndpoint cmdlet prompts for confirmation. 可以使用“-Force”参数取消该提示。This prompt can be suppressed using the '-Force' parameter.

删除流量管理器终结点Delete a Traffic Manager Endpoint

若要单独删除终结点,请使用 Remove-AzTrafficManagerEndpoint cmdlet:To remove individual endpoints, use the Remove-AzTrafficManagerEndpoint cmdlet:

Remove-AzTrafficManagerEndpoint -Name MyEndpoint -Type AzureEndpoints -ProfileName MyProfile -ResourceGroupName MyRG

此 cmdlet 提示进行确认。This cmdlet prompts for confirmation. 可以使用“-Force”参数取消该提示。This prompt can be suppressed using the '-Force' parameter.

删除流量管理器配置文件Delete a Traffic Manager Profile

若要删除流量管理器配置文件,请使用 Remove-AzTrafficManagerProfile,同时指定配置文件和资源组名称:To delete a Traffic Manager profile, use the Remove-AzTrafficManagerProfile cmdlet, specifying the profile and resource group names:

Remove-AzTrafficManagerProfile -Name MyProfile -ResourceGroupName MyRG [-Force]

此 cmdlet 提示进行确认。This cmdlet prompts for confirmation. 可以使用“-Force”参数取消该提示。This prompt can be suppressed using the '-Force' parameter.

也可以使用配置文件对象指定要删除的配置文件:The profile to be deleted can also be specified using a profile object:

$TmProfile = Get-AzTrafficManagerProfile -Name MyProfile -ResourceGroupName MyRG
Remove-AzTrafficManagerProfile -TrafficManagerProfile $TmProfile [-Force]

还可以通过管道执行此序列:This sequence can also be piped:

Get-AzTrafficManagerProfile -Name MyProfile -ResourceGroupName MyRG | Remove-AzTrafficManagerProfile [-Force]

后续步骤Next steps

流量管理器监视Traffic Manager monitoring

流量管理器性能注意事项Traffic Manager performance considerations