IIS Work with Network Load Balancing, NLB


  1. 說明
    1. SSL Issues
  2. 實驗步驟
  3. 參考資料
  4. 相關連結

如何使用 Network Load Balancing, NLB 技術來達到平衡或是偏好性分流,將使用者需求分流至各網頁伺服器的方式。NLB 屬於 OSI Layer 3 Transport Layer 的架構應用,因此無法偵測到應用程式本身的狀態,這點讓 NLB 無法單獨勝任 High Availability 的工作,但其作為負載平衡的重要性不容小覷 🙂

logo

說明

NLB 是藉由 TCP/IP 的方式來分流需求 (Requests),設定 NLB 不需要額外的硬體設備,僅需要將各 Web Server (Host) 安裝 Windows NLB Features,並進行設定。

在設定上,各 Host 需要分別設定一組專屬的 IP 以及共用的 IP,其中共用的 IP 是在 DNS 對應為 A Record,提供 Client 端連線使用的,各專屬 IP 則是用於識別不同的 Host。藉由 NLB 可以調整 Requests 該按如何比例、優先順序的方式分流至各 Host,以達到平衡的作用。

此外當 NLB 中的任一 Host 無法服務時,會由其他的 Host 接手。然而看似美好,但 NLB 實際上無法感知 IIS 的服務狀態(甚至是 IIS 的存在),只有在 Server Crash 或者 Network Crash 的情況下,使用 NLB 若要達到 IIS Failover 必須自行在應用程式設計上實作監控與切換的機制。

NLB Detects Server Failures, NOT Websites Failures.

NLB does not monitor the health of your application. Instead, it allows the application developer to determine how healthy a load-balanced application is. Since each application has its own notion of load and health, measuring and monitoring these quantities is best achieved by the application itself. By using collected measurements from your application and the NLB public WMI provider, it is a relatively simple task to add load and health monitoring to your load-balanced application.
learn.microsoft.com

SSL Issues

實驗步驟

首先於兩台 WebServer 分別設定虛擬機網路卡

接著使用 Remote Powershell 來進行安裝 NLB Features

$Sessions = New-PSSession –ComputerName Web1, Web2
Invoke-Command –Session $Sessions {Add-WindowsFeature Web-server, NLB, RSAT-NLB}

在 DNS Server 加入 A Record

Add-DnsServerResourceRecordA
  -Name demo
  -ZoneName sdwh.local
  -IPv4Address 10.100.100.10
  -ComputerName DC.sdwh.local

接著設定 NLB

Get-NlbCluster -HostName WebServer1 | 
  Add-NlbClusterNode -NewNodeName WebServer2 -NewNodeInterface Ethernet

最後在建置 IIS 站台

PS> $Sessions = New-PSSession –ComputerName WebServer1, WebServer2
PS> Invoke-Command -Session $Sessions {New-WebAppPool -Name demo-pool}
PS> Invoke-Command -Session $Sessions {
  New-Website
    -Name demo
    -HostHeader demo.sdwh.local
    -PhysicalPath C:\inetpub\sites\demo
    -ApplicationPool demo
  }

參考資料

Network Load Balancing | learn.microsoft

Network Load Balancing 2016 | learn.microsoft

Web Farm & NLB

Windows Server 2012 R2 NLB 網路負載平衡 架設

相關連結

IIS Work With Application Request Routing, ARR

IIS Work With Network Load Balancing, NLB

IIS Failover With DNS Round Robin

IIS 筆記整理