window server 2008的网络负载均衡(NLB)算法

最近项目中接触到关于群集的问题,后来看到关于window server 2008的NLB网络负载均衡中提到其均衡算法不需要群集主机间协商通信,就仔细研究了下,网上查到MSDN的两个帖子。

How Does Network Load Balancing Algorithm Works Internally (矛盾)

Network Load Balancing Technical Overview   (正解)

 

第一个帖子看了后觉得有问题,因为照他描述的算法来看,必须要求主机间在处理网络请求时协商,这与上述所说有矛盾,后来查到这二个帖子,这个帖子是官方正式描述,算法是基于统计学的原理,这个才是正解,现把其算法关键内容翻译下分享给网友:

 

Load Balancing Algorithm (负载均衡算法)

Network Load Balancing employs a fully distributed filtering algorithm to map incoming clients to the cluster hosts. This algorithm was chosen to eable cluster hosts to make a load-balancing decision independently and quickly for each incoming packet. It was optimized to deliver statistically even load balance for a large client population making numerous, relatively small requests, such as those typically made to Web servers. When the client population is small and/or the client connections produce widely varying loads on the server, Network Load Balancing's load balancing algorithm is less effective. However, the simplicity and speed of its algorithm allows it to deliver very high performance, including both high throughput and low response time, in a wide range of useful client/server applications.

NLB(网络负载均衡)采用完全分布式过滤算法将请求的客户端映射到某台群集主机,该算法使得群集主机能对每个请求包快速独立地做负载均衡决策。这个算法经过优化可将大量客户群提交的大量、较小的请求处理到达统计式公平的负载均衡,如典型的针对WEB服务器的请求。当客户端少并且(或)客户端连接产生分布广而不均的服务器负载,NLB的负载均衡算法则效率较低。尽管如此,该算法的简单性、高速度使得它能够在很多有用的客户端/服务端应用场合下,具有非常高的性能,包括高吞吐量、低响应时间。

Network Load Balancing load-balances incoming client requests by directing a selected percentage of new requests to each cluster host; the load percentage is set in the Network Load Balancing Properties dialog box for each port range to be load-balanced. The algorithm does not respond to changes in the load on each cluster host (such as the CPU load or memory usage). However, the mapping is modified when the cluster membership changes, and load percentages are renormalized accordingly.

NLB根据设定比例将请求导向到各个群集主机进行负载均衡,在NLB的属性对话框里可为每段端口范围进行负载比例的设定。该算法不响应群集主机自身的负载变化(如CPU负载或内存使用)。但是,当群集主机成员发生变化时,则负载比例会相应重新常态化。

When inspecting an arriving packet, all hosts simultaneously perform a statistical mapping to quickly determine which host should handle the packet. The mapping uses a randomization function that calculates a host priority based on the client's IP address, port, and other state information maintained to optimize load balance. The corresponding host forwards the packet up the network stack to TCP/IP, and the other cluster hosts discard it. The mapping does not vary unless the membership of cluster hosts changes, ensuring that a given client's IP address and port will always map to the same cluster host. However, the particular cluster host to which the client's IP address and port map cannot be predetermined since the randomization function takes into account the current and past cluster's membership to minimize remappings.

当侦测到一个到达的数据包,所有主机同时执行"统计映射"以迅速判断哪个主机应当处理该数据包.映射采用随机函数,并基于客户端IP地址、端口和用于优化NLB的其他状态信息来计算主机优先级。相应的主机推送数据包从网络栈直到TCP/IP层,而其他主机则丢弃该数据包。映射不会发生变化除非集群主机发生变化,这能保证给定的客户端IP地址和端口总能映射到同一台集群主机。但是,某客户端IP地址和端口所映射的某个主机是不能事先确定的,因为随机函数会考虑当前和过去的群集成员状态以减少重映射过程。(注:算法的关键内容在这里)

 

The load-balancing algorithm assumes that client IP addresses and port numbers (when client affinity is not enabled) are statistically independent. This assumption can break down if a server-side firewall is used that proxies client addresses with one IP address and, at the same time, client affinity is enabled. In this case, all client requests will be handled by one cluster host and load balancing is defeated. However, if client affinity is not enabled, the distribution of client ports within the firewall usually provides good load balance.

负载均衡算法假定客户端IP地址和端口号(当客户相似性未启用)是统计独立的。如果用服务端防火墙1个IP代理多客户端IP地址,同时客户相似性启用,那这个假定就被打破。这种情况,所有客户端请求会被一台群集主机处理,负载均衡就废掉了。如果客户相似性未启用,则客户端在防火墙内的端口分布情况则通常能作为良好负载均衡的条件。

 

In general, the quality of load balance is statistically determined by the number of clients making requests. This behavior is analogous to coin tosses where the two sides of the coin correspond to the number of cluster hosts (thus, in this analogy, two), and the number of tosses corresponds to the number of client requests. The load distribution improves as the number of client requests increases just as the fraction of coin tosses resulting in "heads" approaches 1/2 with an increasing number of tosses. As a rule of thumb, with client affinity set, there must be many more clients than cluster hosts to begin to observe even load balance.

通常,负载均衡的质量在统计上是由请求的客户端的数量决定的。这个行为类似于扔硬币,硬币的两面对应群集主机数(也就是说,两个),扔硬币的次数对应客户端的请求次数。负载的分配质量随客户请求次数增加而提升,这就像随着扔硬币的次数增加,结果为"头"的概率会接近于1/2。作为经验法则,物以类聚,必定会有越来越多于群集主机的客户端能开始觉察到公平的负载均衡。

 

As the statistical nature of the client population fluctuates, the evenness of load balance can be observed to vary slightly over time. It is important to note that achieving precisely identical load balance on each cluster host imposes a performance penalty (throughput and response time) due to the overhead required to measure and react to load changes. This performance penalty must be weighed against the benefit of maximizing the use of cluster resources (principally CPU and memory). In any case, excess cluster resources must be maintained to absorb the client load in case of failover. Network Load Balancing takes the approach of using a very simple but powerful load-balancing algorithm that delivers the highest possible performance and availability.

根据客户群波动的统计学本质看, 在经过足够长的时间后,观察负载均衡的平衡性的变化是轻微的。这里着重注意的是,要达到每个群集主机的负载均衡精确一致则会带来性能上的损失(吞吐和响应时间),这是由于测量和响应负载变化所带来的开销。这个开销必须在与最大化利用群集资源(主要是CPU和内存)的好处之间权衡。无论何种情况,必定会保持多余的群集资源用于承接故障转移而导致的客户端请求负载。NLB通过使用一个非常简单而强大的负载均衡算法的办法来提供尽可能高的性能和可用性。

 

Network Load Balancing's client affinity settings are implemented by modifying the statistical mapping algorithm's input data. When client affinity is selected in the Network Load Balancing Properties dialog box, the client's port information is not used as part of the mapping. Hence, all requests from the same client always map to the same host within the cluster. Note that this constraint has no timeout value (as is often the case in dispatcher-based implementations) and persists until there is a change in cluster membership. When single affinity is selected, the mapping algorithm uses the client's full IP address. However, when class C affinity is selected, the algorithm uses only the class C portion (the upper 24 bits) of the client's IP address. This ensures that all clients within the same class C address space map to the same cluster host.

NLB客户相似性设置是通过修改统计映射算法的输入数据来实现。当在NLB属性对话框里选中客户相似性,客户端端口信息不会作为映射的部分。因此,来自于同一个客户端的所有请求总是映射到同一台群集主机。这个约束没有超时限制(而这通常是基于调度者模式实现的情况)并且保持直到群集成员发生变化。当单一相似性选中,映射算法使用客户端的IP地址值的全部。但是当C类相似性被选中,算法仅使用客户端IP地址C类部分(上面的24位)。这保证所有来自同一C类段地址空间的客户映射到同一台群集主机

 

 

算法理解:

   假设"统计映射”函数 StatMapping , 每个群集主机需要设定负载比例,端口范围,客户相似性。群集时的心跳信息会让每个群集主机都知道群集的成员状态,也就是说一定时间内,群集成员的个数是固定的、负载比例和其他参数是不变的,而且每个群集主机都知道其他群集主机的这些设定。由于群集主机共享一个群集IP,则所有客户端的请求数据包都会到达每个群集主机,此时,每个群集主机都计算所有群集主机的优先级: (假定客户相似性未启用,该参数只是影响输入数据,不影响算法逻辑)

       Priority = StatMapping( Client IP, Port, 主机负载比例,主机其他参数)

通过这个算法就可以得到所有主机的优先级,如果优先级高的主机恰好是本机,则处理,否则则丢弃。

这个算法实质上应该就是一个哈希算法,将大范围的客户端映射到小范围的群集主机,这个哈希算法的统计学分布比例越均衡则负载均衡的质量越高。当然前面也提到了则个算法不考虑主机当时的CPU或内存负载,所以无法做到动态调整负载,但对于常用的客户端/服务器应用则简单实用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nlb负载均衡架设教程图解在Server 2008上搭建域控制器 打开服务器管理,如下图所示: 1. 2 选择【角色】然后点击右侧新建角色,在“添加角色向导”页面点击【服务器角色】,如下图所示: 2. 3 勾选“Active Directory域服务” ,根据提示添加相应组件,然后点击【下一步】,如下图所示: 3. 4 选择【下一步】,如下图所示: 4. 5 点击【安装】,如下图所示: 5. 6 安装完成后点击关闭,如下图所示: 6. 7 在运行中输入dcpromo.exe,如下图所示: 7. 8 弹出Active Directory域服务安装向导,点击下一步,如下图所示: 8. 9 继续下一步,如下图所示: 9. 10 选择新建域,如下图所示: 10. 11 输入自定义域名点击下一步,如下图所示: 11. 12 林功能级别选择Windows server 2008 R2,点击下一步,如下图所示: 12. 13 勾选DNS服务器,点击下一步,如下图所示: 13. 14 选择是,单击下一步,如下图所示: 14. 15 选择文件存放路径,点击下一步,如下图所示: 15. 16 设置还原密码后点击下一步,如下图所示: 16. 17 查看配置信息,点击下一步,如下图所示: 17. 18 完成安装,如下图所示: 18. 19 选择不立即重启,如下图所示: 19. 20 打开网卡的IP配置信息,将DNS服务器设置为本机ip,如下图所示: 20. 21 重启服务器。 END 检测域是否建立成功 1. 1 打开第二台机器修改主机的DNS为域服务器ip,如下图所示: 2. 2 点击更改域和工作组,如下图所示: 3. 3 填入创建的域名,如下图所示: 4. 4 输入域管理员账号和密码,等待加域成功,重启后生效。 负载均衡安装 网络负载平衡,英文简称为NLBwindows Server 2012 中该功能允许你将传入的请求传播到最多达32台的服务器上,即可以使用最多32台服务器共同分担对外的网络请求服务。网络负载平衡,保证即使是在负载很重的情况下它们也能够在很快的时间内做出反应。 网络负载平衡可以让客户端用一个逻辑Internet名称和虚拟IP地址(又称群集IP地址)访问群集,同时保留每台计算机各自的名称。网络负载平衡对外只须提供一个IP地址(或域名)。 当网络负载平衡中的服务器故障,不可用时,网络负载平衡会自动检测到不可用的服务器,并在剩余的服务器中,重新指派客户机通讯。从而实现服务器的高可用,并且,可以根据网络访问量的增多来增加网络负载平衡服务器的数量。 实验项目: 示例:利用Windows Server 2012实现网络负载平衡,并实现WEB站点的高可用 实验环境说明: server01是域控,server02和server03做负载平衡并安装Web服务,server05是客户机,做测试用,server02和server03两台服务器需要两块网卡,一块用于通信,一块做心跳线,如下图 步骤1:安装NLB角色 在server02、server03分别安装网络负载平衡管理器 打开服务器管理器,选择添加角色与功能 检查服务器信息 在功能中选择网络负载平衡 添加所需要的功能,并完成安装 步骤2: 配置NLB 此操作在server02上设置 打开服务器管理器,单击工具,选择网络负载平衡管理器 右键单击网络负载平衡管理器,选择新建群集 输入要做网络负载平衡的服务器的名称,点击链接,选择用于通讯的IP地址 选择优先级,一般第一个服务器是1,第二个是2,以此类推 单击添加,添加群集IP地址 输入群集IP地址,单击确定 检查群集IP配置,注意群集群集操作模式选项,这里选择的是多播,单击下一步 这里我们来稍微介绍一下群集的操作模式 群集操作模式: 单播: 所有节点的MAC地址会被替换成统一的群集MAC地址 多播: 每个节点使用自己的MAC地址 配置端口规则,实验环境,默认即可,单击完成 这样我们就配置完成了一台服务器,下面我们来给群集添加服务器,右键单击群集IP地址,选择添加主机到群集 输入另一台主机的名称server03,单击链接,选择用于通讯的IP地址 大家会发现,这里的优先级变成了2,而且无法选择1,那是因为,优先级是1的,是最开始加入进来的服务器 余下的配置与刚才一样,只是少了添加群集IP地址,单击下一步,并完成配置 配置完的网路负载平衡如下图,在这里说一下,并不是配置完成,网络负载平衡就会马上生效,他会有一个配置的过程,真正完成配置的状态如下图 下面我们来测试一下

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值