Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Yves Pitsch Azure 网络首席项目经理
我们很高兴地宣布,Azure负载平衡器现在可以为云服务和虚拟机提供可配置的 TCP空闲超时支持。要配置此功能,可以使用服务管理 API、PowerShell或服务模型
概述
在默认配置下,Azure 负载平衡器的“空闲超时”设置是 4分钟。
这意味着,如果 tcp 或 http 会话不活动的时间超过这个超时值,客户端和服务之间的连接将无法保证是否可以维持下去。
当连接关闭时,客户端应用程序会显示如下错误消息“The underlyingconnection was closed: A connection that was expected to be kept alive wasclosed by the server”(基础连接已关闭:应该保持连接状态的连接已被服务器关闭)。
让连接长时间保持连接状态的常见做法是使用TCP Keep-alive(此处可找到 .NET 示例)。在连接检测不到活动时将自动发送数据包。通过保持持续的网络活动,空闲超时值将永远无法达到,连接也就可以长时间保持。
虽然 TCP Keep-alive对于电池量不是约束因素的场景非常有效,但通常对于移动应用却不是一种有效的选择。在移动应用中使用 TCPKeep-alive很可能会更快耗尽设备电量。
为了支持此类场景,我们增加了对可配置空闲超时的支持。您现在可以将空闲超时设置为 4到 30分钟之间。该设置仅对入站连接有效。
场景
通过 PowerShell 或服务管理 API 为虚拟机上的端点配置 TCP 超时
通过 PowerShell 或服务管理 API 为负载平衡端点集配置 TCP 超时。
通过服务模型为 Web/Worker Role配置 TCP 超时。
PowerShell 示例
确保下载并安装最新的 Azure PowerShell
将实例级公共 IP的 TCP超时配置为 15 分钟。
| Set-AzurePublicIP –PublicIPName webip –VM MyVM -IdleTimeoutInMinutes 15 |
IdleTimeoutInMinutes 是可选的。如果不设置,默认的超时是 4 分钟。现在该值可以设置为 4 到 30 分钟之间。
在虚拟机上创建 Azure 端点时设置空闲超时
| Get-AzureVM -ServiceName "mySvc" -Name "MyVM1" | Add-AzureEndpoint -Name "HttpIn" -Protocol "tcp" -PublicPort 80 -LocalPort 8080 -IdleTimeoutInMinutes 15| Update-AzureVM |
检索空闲超时配置
PS C:\> Get-AzureVM –ServiceName “MyService” –Name “MyVM” | Get-AzureEndpoint
VERBOSE:6:43:50 PM - Completed Operation:Get Deployment
LBSetName :MyLoadBalancedSet
LocalPort :80
Name :HTTP
Port :80
Protocol : tcp
Vip :65.52.xxx.xxx
ProbePath :
ProbePort :80
ProbeProtocol : tcp
ProbeIntervalInSeconds :15
ProbeTimeoutInSeconds :31
EnableDirectServerReturn :False
Acl :{}
InternalLoadBalancerName :
IdleTimeoutInMinutes :15
在负载平衡端点集上设置 TCP超时
如果端点是负载平衡端点集的一部分,TCP超时必须在负载平衡端点集上设置
| Set-AzureLoadBalancedEndpoint -ServiceName "MyService" -LBSetName "LBSet1" -Protocol tcp -LocalPort 80 -ProbeProtocolTCP -ProbePort 8080 -IdleTimeoutInMinutes 15 |
云服务示例
您可以使用Azure SDK for .NET 2.4更新云服务
云服务的端点设置在 .csdef中进行。因此,要更新云服务部署的 TCP超时,必须进行部署升级。例外情况是仅为公共 IP指定 TCP超时的情况。公共 IP设置位于 .cscfg中,这些设置可以通过部署更新和升级进行更新。
端点设置的 .csdef 更改如下:
<WorkerRole name="worker-role-name" vmsize="worker-role-size"
enableNativeCodeExecution="[true|false]">
<Endpoints>
<InputEndpoint name="input-endpoint-name" protocol="[http|https|tcp|udp]"
localPort="local-port-number" port="port-number" certificate="certificate-name"
loadBalancerProbe="load-balancer-probe-name" idleTimeoutInMinutes="tcp-timeout" />
</Endpoints>
</WorkerRole>The .cscfg changes for the timeout setting on Public IPs are:
<NetworkConfiguration>
<VirtualNetworkSite name="VNet"/>
<AddressAssignments>
<InstanceAddress roleName="VMRolePersisted">
<PublicIPs>
<PublicIP name="public-ip-name" idleTimeoutInMinutes="timeout-in-minutes"/>
</PublicIPs>
</InstanceAddress>
</AddressAssignments>
</NetworkConfiguration>
API 示例
要进行 TCP 空闲超时配置,可以使用服务管理 API
确保将添加的 x-ms-version头设置为 2014-06-01或更高版本。
更新部署中所有虚拟机上特定负载平衡输入端点的配置
请求
| POST https://management.core.windows.net/<subscription-id>/services/hostedservices/<cloudservice-name>/deployments/<deployment-name> |
响应
<LoadBalancedEndpointList xmlns="https://schemas.microsoft.com/windowsazure"
xmlns:i="https://www.w3.org/2001/XMLSchema-instance">
<InputEndpoint>
<LoadBalancedEndpointSetName>endpoint-set-name</LoadBalancedEndpointSetName>
<LocalPort>local-port-number</LocalPort>
<Port>external-port-number</Port>
<LoadBalancerProbe>
<Path>path-of-probe</Path>
<Port>port-assigned-to-probe</Port>
<Protocol>probe-protocol</Protocol>
<IntervalInSeconds>interval-of-probe</IntervalInSeconds>
<TimeoutInSeconds>timeout-for-probe</TimeoutInSeconds>
</LoadBalancerProbe>
<LoadBalancerName>name-of-internal-loadbalancer</LoadBalancerName>
<Protocol>endpoint-protocol</Protocol>
<IdleTimeoutInMinutes>15</IdleTimeoutInMinutes>
<EnableDirectServerReturn>enable-direct-server-return</EnableDirectServerReturn>
<EndpointACL>
<Rules>
<Rule>
<Order>priority-of-the-rule</Order>
<Action>permit-rule</Action>
<RemoteSubnet>subnet-of-the-rule</RemoteSubnet>
<Description>description-of-the-rule</Description>
</Rule>
</Rules>
</EndpointACL>
</InputEndpoint>
</LoadBalancedEndpointList>
如果你有任何疑问, 欢迎访问MSDN社区,由专家来为您解答Windows Azure各种技术问题,或者拨打世纪互联客户服务热线400-089-0365/010-84563652咨询各类服务信息。
本文翻译自:https://azure.microsoft.com/blog/2014/08/14/new-configurable-idle-timeout-for-azure-load-balancer/