Jonathan
TulianiAzure网络
- DNS和 Traffic Manager高级项目经理
在北美
TechEd 大会上,我们宣布了
Azure Traffic Manager将支持 Azure外部端点。我们非常高兴能够宣布进一步的增强功能,为使用轮询机制负载平衡增加权重的支持。综合使用这些功能可以实现一系列新的方案,包括在内部部署和云之间的混合方案中分配流量。
这些功能现可通过我们的 PowerShell cmdlet进行支持
—它还进行了新的扩展,以支持 Traffic Manager。
简介
利用 Traffic Manager,可以在多项服务之间实现传入流量的负载平衡,不论这些服务是在同一数据中心运行,还是在世界各地的不同数据中心运行。Traffic
Manager 可实现的关键方案包括通过将最终用户路由到最近的部署改善应用程序的性能,以及通过监控您的服务并在服务出现故障时自动进行故障转移,从而实现高可用性。
直到最近,还只有 Azure云服务(IaaS和
PaaS)和 Azure网站受到支持。而现在,我们启用了
Traffic Manager对 Azure外部端点的支持。我们还增强了轮询机制负载平衡的方法以支持权重,为在端点间分配流量提供更大的掌控能力。
这些增强功能使 Traffic Manager的优势得以在更广泛的应用程序中发挥作用,并实现了一些新的方案。
例如,外部端点支持意味着 Traffic Manager现在允许您使用
Azure来扩展已有的内部部署或外部托管部署。这可以让离任一Azure数据中心都较远的地理位置改善性能,以主动-主动方式或故障转移方式增加冗余,或者持续增加容量,或临时增加容量以应对需求高峰。外部端点还允许
Traffic Manager配置文件跨不同 Azure订阅中的服务,这在以前是不可能的。
权重轮询机制还可以实现其他新的方案,例如在多个部署之间合理分配负载以最大限度地提高利用率,或将一小部分流量转移到不同部署并作为“A/B测试”方案的一部分。在与外部端点配合使用时,它可实现内部部署应用程序向云的平稳过渡
— 首先将 100%的流量导向内部部署应用程序,然后“转移方向”,逐步将流量迁移到基于云的版本。
这些功能目前可通过我们的REST
API和我们全新的Traffic
ManagerPowerShell cmdlet获得。Azure管理门户网站中不提供这些功能。本博客文章的其余部分将向您展示如何使用
PowerShell对 Traffic Manager的新支持,以利用这些新功能。
入门
要开始使用 Azure PowerShell,请参阅如何安装和配置
Azure PowerShell。请注意,您需要使用 0.8.3或更高版本。
查看已有配置文件和端点
“Get-AzureTrafficManagerProfile”cmdlet可以检索一系列配置文件对象,以便您可以查看:
<span style="font-size:14px;">PS C:\> $profiles = Get-AzureTrafficManagerProfile
PS C:\> $profiles | Format-Table
Name DomainName Status
---- ---------- ------
MyProfile myprofile.trafficmanage...Enabled
websites websites.trafficmanager...Enabled
</span>
或者,通过指定“-Name”参数,您可以仅检索一个配置文件。每个配置文件都包含有关配置文件名称、Traffic
Manager 域、TTL和端点监控设置的字段:
<span style="font-size:14px;">PS C:\> $profile = Get-AzureTrafficManagerProfile -Name "MyProfile"
PS C:\> $profile | Format-List
TimeToLiveInSeconds : 30
MonitorRelativePath : /
MonitorPort : 80
MonitorProtocol :Http
LoadBalancingMethod :RoundRobin
Endpoints :{tm-demo-us.cloudapp.net, www.microsoft.com}
MonitorStatus :CheckingEndpoints
Name :MyProfile
DomainName :myprofile.trafficmanager.net
Status :Enabled
</span>
还有一系列端点,其中包含端点域名、位置、类型、状态、监控状态和权重:
<span style="font-size:14px;">PS C:\> $profile.Endpoints | Format-
DomainName Location Type Status MonitorStatus Weight
---------- -------- ---- ------ ------------- ------
tm-demo-us...CloudService Enabled Online 1
www.micros...Any Enabled Online 1
</span>
创建配置文件并添加端点
常用的方法是使用“Profile”对象来表示您的
Traffic Manager 配置文件。您可以使用 cmdlet来脱机配置此配置文件,然后在准备就绪后,使用“Set-AzureTrafficManagerProfile”cmdlet将其加载到
Azure。(记住,实际调用 Azure管理
API的仅有两个
cmdlet, 分别是“New-AzureTrafficManagerProfile”和“Set-AzureTrafficManagerProfile”。)
下面的示例创建了一个新的
Traffic Manager 配置文件,向其添加两个端点,并将结果提交到 Azue:
<span style="font-size:14px;">PS C:\> $profile = New-AzureTrafficManagerProfile -Name "MyProfile" -DomainName "myprofile.trafficmanager.net" -LoadBalancingMethod "RoundRobin" -Ttl 30 -MonitorProtocol "Http" -MonitorPort 80 -MonitorRelativePath "/"
PS C:\> $profile = Add-AzureTrafficManagerEndpoint -TrafficManagerProfile $profile -DomainName "myapp-eu.cloudapp.net" -Status "Enabled" -Type "CloudService"
PS C:\> $profile = Add-AzureTrafficManagerEndpoint -TrafficManagerProfile $profile -DomainName "myapp-us.cloudapp.net" -Status "Enabled" -Type "CloudService"
PS C:\> Set-AzureTrafficManagerProfile –TrafficManagerProfile $profile
</span>
这些命令(以及本博客文章后面的其他示例)也可以“组合”:
<span style="font-size:14px;">PS C:\> New-AzureTrafficManagerProfile -Name "MyProfile" -DomainName "myprofile.trafficmanager.net" -LoadBalancingMethod "RoundRobin" -Ttl 30 -MonitorProtocol "Http" -MonitorPort 80 -MonitorRelativePath "/" | Add-AzureTrafficManagerEndpoint -DomainName "myapp-eu.cloudapp.net" -Status "Enabled" -Type "CloudService" | Add-AzureTrafficManagerEndpoint -DomainName "myapp-us.cloudapp.net" -Status "Enabled" -Type "CloudService" | Set-AzureTrafficManagerProfile</span>
外部端点
Add-AzureTrafficManagerEndpointcmdlet可用于创建外部端点(即
Azure外部的端点)。只需在 DomainName参数中指定端点的域名,并将类型指定为“Any”即可:
<span style="font-size:14px;">PS C:\> Add-AzureTrafficManagerEndpoint -TrafficManagerProfile $profile -DomainName "www.microsoft.com" -Status "Enabled" -Type "Any" | Set-AzureTrafficManagerProfile</span>
在配合使用外部端点与 Performance负载平衡时,需要一个附加的“Location”参数。它会告诉
Azure 您的外部端点所在的位置,使 Traffic Manager可以适当地跨地域路由流量。
<span style="font-size:14px;">PS C:\> Add-AzureTrafficManagerEndpoint -TrafficManagerProfile $profile -DomainName "www.microsoft.com" -Status "Enabled" -Type "Any" -Location "North Europe" | Set-AzureTrafficManagerProfile</span>
可用的位置反映出
Azure的全球数据中心网络,可使用 Get-AzureLocationcmdlet找到:
<span style="font-size:14px;">PS C:\> $loc = Get-AzureLocation
PS C:\> $loc.Name | Format-List
East Asia
Southeast Asia
North Europe
West Europe
East US
West US
Japan East
Japan West
Brazil South
North Central US
South Central US
</span>
如果您更改了负载平衡方法,例如改为轮询机制,然后切换回
Performance,那么 Traffic Manager会记住(但是会忽略)您以前配置的端点位置,因此您不需要再次指定。
权重端点
权重仅适用于使用“轮询机制”负载平衡方法的
Traffic Manager 策略。它可用于所有端点类型。流量会按比例分布到所有目前正在使用的正常运行的端点的权重。
您可以使用下面示例中所显示的“Weight”参数来指定从
1 到 1000的任意权重。它是一个可选参数
— 默认情况下,所有端点的权重都是“1”。
<span style="font-size:14px;">PS C:\> Add-AzureTrafficManagerEndpoint -TrafficManagerProfile $profile -DomainName "tm-demo-us.cloudapp.net" -Status "Enabled" -Type "CloudService" -Weight 70 | Set-AzureTrafficManagerProfile</span>
与外部端点位置类似,如果您更改了负载平衡方法(例如改为 Performance),权重会被忽略,切换回轮询机制时会记住权重。Tranfic
Manager在 DNS级别运行,而
DNS在设计上会由各组织和
ISP 所运行的 DNS客户端和本地
DNS解析器进行缓存。权重的流量分布最适用于面向 Internet的传统应用程序,因为在这些应用程序中存在大量的客户端
—在这种情况下,DNS缓存不会影响流量的分布。但是,当使用的客户端数量很少时,或当所有客户端均位于少量本地
DNS 服务器之后时,缓存就可能会扭曲流量分布。在这种情况下,应对每个连接分配流量,例如使用应用程序级别的 HTTP 302重定向。
其他常见操作
下面给出了 Traffic Manager配置文件的其他常见操作的示例。
启用和禁用端点
您可以禁用端点,停止分配流量给它。这会停止
Traffic Manager 对此端点计费,但会将它保留在您的配置文件中,因此可以轻松地重新启用。
<span style="font-size:14px;">PS C:\> $profile = Get-AzureTrafficManagerProfile -Name "MyProfile"
PS C:\> $profile.Endpoints[0].Status = "Disabled"
PS C:\> Set-AzureTrafficManagerProfile –TrafficManagerProfile $profile
</span>
<span style="font-size:14px;">
</span>
端点重新排序
端点的顺序可以确定使用“故障转移”负载平衡方法时的故障转移顺序。下面的示例显示了如何对一对端点进行重新排序:
<span style="font-size:14px;">PS C:\> $profile = Get-AzureTrafficManagerProfile -Name "MyProfile"
PS C:\> $profile.Endpoints[0],$profile.Endpoints[1] = $profile.Endpoints[1],$profile.Endpoints[0]
PS C:\> Set-AzureTrafficManagerProfile –TrafficManagerProfile $profile
</span>
删除端点
要删除端点,可以使用“Remove-AzureTrafficManagerEndpoint”cmdlet:
<span style="font-size:14px;">PS C:\> $profile = Get-AzureTrafficManagerProfile -Name "MyProfile"
PS C:\> Remove-AzureTrafficManagerEndpoint -TrafficManagerProfile $profile -DomainName www.microsoft.com
PS C:\> Set-AzureTrafficManagerProfile –TrafficManagerProfile $profile
</span>
更新端点监控设置
在此示例中,我们将修改监控路径,以指向专用的监控页面:
<span style="font-size:14px;">PS C:\> $profile = Get-AzureTrafficManagerProfile -Name "MyProfile"
PS C:\> $profile.MonitorRelativePath = "/monitor.aspx"
PS C:\> Set-AzureTrafficManagerProfile –TrafficManagerProfile $profile
</span>
禁用配置文件
您可以完全禁用 Traffic Manager配置文件。这将停止流向所有端点的流量,也会停止对此配置文件的计费。为此,可以使用专用的
cmdlet:
<span style="font-size:14px;">PS C:\> Disable-AzureTrafficManagerProfile -Name "MyProfile"
PS C:\> Enable-AzureTrafficManagerProfile -Name "MyProfile"
</span>
删除配置文件
最后,您还可以删除 Traffic Manager配置文件(“Force”标记会覆盖确认提示):
<span style="font-size:14px;">PS C:\> Remove-AzureTrafficManagerProfile -Name "MyProfile" -Force</span>
常见问题
我是否可以通过 Azure管理门户网站使用外部端点或权重?
这些功能目前仅能通过 REST API和
PowerShell cmdlet进行配置。在 Azure管理门户网站上不提供这些功能。
但是,您可以继续通过 Azure管理门户网站来查看使用外部端点或权重的配置文件的状态,甚至可以管理这些配置文件上的其他设置,例如启用和禁用端点,或配置监控设置。
我是否可以在同一个 Traffic Manager配置文件中混合使用
Azure端点(云服务和网站)与外部端点?
可以。对于您在一个配置文件中如何混合使用不同类型的端点没有任何限制。
外部端点和权重的计费模型是否存在任何变化?
外部端点的计费标准高于 Azure端点。使用权重不额外收费。有关完整的详细信息,请参阅我们的定价页面。
AzureTraffic Manager在
Azure SDK或 Xplat-CLI中是否受支持?
TrafficManager管理库包含在.NET
SDK中。它在
Java SDK或 Node.js SDK以及
Xplat-CLI中尚不受支持。
我能否将 Azure服务设置为外部端点?
可以,您可以使用外部端点来引用其他 Azure服务(不包括网站)。此方法的计费费率与其他
Azure端点相同。但是,与云服务和网站不同的是,如果您禁用该服务,将继续针对相应的 Traffic Manager端点对您进行计费,除非您明确禁用或删除
Traffic Manager中的端点。
我在哪里可以找到有关 Azure Traffic Manager的更多信息?
Azure门户网站中包含有关
Traffic Manager 服务和方案的概览。它还包含定价和SLA的详细信息。
MSDN中包含更为详细的概述,包括对
Traffic Manager 的负载平衡方法以及端点监控和配置的说明。
除了 Azure的付款支持计划外,我们的MSDN论坛可用于咨询有关
DNS 或 Traffic Manager的各种
Azure问题。有关功能的建议公布在我们的反馈网站上,您也可以在这里为已有建议投票。