快速入門:使用 Azure 入口網站來建立內部負載平衡器以平衡 VM 的負載Quickstart: Create an internal load balancer to load balance VMs using the Azure portal

使用 Azure 入口網站建立內部負載平衡器和三部虛擬機器,以開始使用 Azure Load Balancer。Get started with Azure Load Balancer by using the Azure portal to create an internal load balancer and three virtual machines.

必要條件Prerequisites

登入 AzureSign in to Azure

登入 Azure 入口網站:https://portal.azure.comSign in to the Azure portal at https://portal.azure.com.


注意

建議對生產環境工作負載使用標準 SKU 負載平衡器。Standard SKU load balancer is recommended for production workloads. 如需 SKU 的詳細資訊,請參閱 Azure Load Balancer 的標準 SKUFor more information about skus, see Azure Load Balancer SKUs.

針對快速入門所建立的標準負載平衡器資源。

在本節中,您會建立負載平衡器以平衡虛擬機器的負載。In this section, you create a load balancer that load balances virtual machines.

當您建立內部負載平衡器時,會將虛擬網路設定為負載平衡器的網路。When you create an internal load balancer, a virtual network is configured as the network for the load balancer.

虛擬網路中的私人 IP 位址會設定為負載平衡器的前端 (命名為 LoadBalancerFrontend)。A private IP address in the virtual network is configured as the frontend (named as LoadBalancerFrontend by default) for the load balancer.

前端公用 IP 位址可以是 靜態動態The frontend IP address can be Static or Dynamic.

建立虛擬網路Create the virtual network

在本節中,您會建立虛擬網路和子網路。In this section, you'll create a virtual network and subnet.

  1. 在畫面的左上方,選取 [建立資源] > [網路] > [虛擬網路],或在搜尋方塊中搜尋 [虛擬網路]。On the upper-left side of the screen, select Create a resource > Networking > Virtual network or search for Virtual network in the search box.

  2. 在 [建立虛擬網路] 中,在 [基本] 索引標籤中輸入或選取這項資訊:In Create virtual network, enter or select this information in the Basics tab:

    設定Setting Value
    專案詳細資料Project Details
    訂用帳戶Subscription 選取您的 Azure 訂用帳戶Select your Azure subscription
    資源群組Resource Group 選取 CreateIntLBQS-rgSelect CreateIntLBQS-rg
    執行個體詳細資料Instance details
    名稱Name 輸入 myVNetEnter myVNet
    區域Region 選取 [西歐]Select West Europe
  3. 選取 [IP 位址] 索引標籤,或選取頁面底部的 [下一步:IP 位置] 按鈕。Select the IP Addresses tab or select the Next: IP Addresses button at the bottom of the page.

  4. 在 [IP 位址] 索引標籤中,輸入這項資訊:In the IP Addresses tab, enter this information:

    設定Setting Value
    IPv4 位址空間IPv4 address space 輸入 10.1.0.0/16Enter 10.1.0.0/16
  5. 在 [子網路名稱] 下,選取 [預設] 字組。Under Subnet name, select the word default.

  6. 在 [編輯子網路] 中,輸入這項資訊:In Edit subnet, enter this information:

    設定Setting Value
    子網路名稱Subnet name 輸入 myBackendSubnetEnter myBackendSubnet
    子網路位址範圍Subnet address range 輸入 10.1.0.0/24Enter 10.1.0.0/24
  7. 選取 [儲存]。Select Save.

  8. 選取 [安全性] 索引標籤。Select the Security tab.

  9. 在 [BastionHost] 底下,選取 [啟用]。Under BastionHost, select Enable. 輸入此資訊:Enter this information:

    設定Setting Value
    Bastion 名稱Bastion name 輸入 myBastionHostEnter myBastionHost
    AzureBastionSubnet 位址空間AzureBastionSubnet address space 輸入 10.1.1.0/24Enter 10.1.1.0/24
    公用 IP 位址Public IP Address 選取 [建立新的]。Select Create new.
    在 [名稱] 中,輸入 myBastionIP。For Name, enter myBastionIP.
    選取 [確定]。Select OK.
  10. 選取 [檢閱 + 建立] 索引標籤,或選取 [檢閱 + 建立] 按鈕。Select the Review + create tab or select the Review + create button.

  11. 選取 [建立]。Select Create.

建立負載平衡器Create load balancer

  1. 在畫面的左上方,選取 [建立資源] > [網路] > [負載平衡器]。On the top left-hand side of the screen, select Create a resource > Networking > Load Balancer.

  2. 在 [建立負載平衡器] 頁面的 [基本] 索引標籤中,輸入或選取下列資訊:In the Basics tab of the Create load balancer page, enter, or select the following information:

    設定Setting Value
    訂用帳戶Subscription 選取您的訂用帳戶。Select your subscription.
    資源群組Resource group 選取您在上一個步驟中建立的 CreateIntLBQS-rgSelect CreateIntLBQS-rg created in the previous step.
    名稱Name 輸入 myLoadBalancerEnter myLoadBalancer
    區域Region 選取 [西歐]。Select West Europe.
    類型Type 選取 [內部]。Select Internal.
    SKUSKU 選取 [標準]Select Standard
    虛擬網路Virtual network 選取您在上一個步驟中建立的 myVNetSelect myVNet created in the previous step.
    子網路Subnet 選取您在上一個步驟中建立的 myBackendSubnetSelect myBackendSubnet created in the previous step.
    IP 位址指派IP address assignment 選取 [動態]。Select Dynamic.
    可用性區域Availability zone 選取 [區域備援]Select Zone-redundant
  3. 接受其餘設定的預設值,然後選取 [檢閱 + 建立]。Accept the defaults for the remaining settings, and then select Review + create.

  4. 在 [檢閱 + 建立] 索引標籤中,選取 [建立]。In the Review + create tab, select Create.

    建立標準內部負載平衡器。

建立負載平衡器資源Create load balancer resources

在本節中,您將會設定:In this section, you configure:

  • 後端位址集區的負載平衡器設定。Load balancer settings for a backend address pool.
  • 健康情況探查。A health probe.
  • 負載平衡器規則。A load balancer rule.

建立後端集區Create a backend pool

後端位址集區會包含已連線至負載平衡器之虛擬 NIC 的 IP 位址。A backend address pool contains the IP addresses of the virtual (NICs) connected to the load balancer.

建立後端位址集區 myBackendPool,以包含用於平衡網際網路流量負載的虛擬機器。Create the backend address pool myBackendPool to include virtual machines for load-balancing internet traffic.

  1. 選取左側功能表中的 [所有服務]、選取 [所有資源],然後從資源清單中選取 myLoadBalancerSelect All services in the left-hand menu, select All resources, and then select myLoadBalancer from the resources list.

  2. 在 [設定] 底下選取 [後端集區],然後選取 [新增]。Under Settings, select Backend pools, then select Add.

  3. 在 [新增後端集區] 頁面上,針對名稱輸入 myBackEndPool 作為後端集區的名稱,然後選取 [新增]。On the Add a backend pool page, for name, type myBackendPool, as the name for your backend pool, and then select Add.

建立健康狀態探查Create a health probe

負載平衡器會透過健康情況探查監視應用程式的狀態。The load balancer monitors the status of your app with a health probe.

健康狀態探查會根據 VM 對健康情況檢查的回應,從負載平衡器輪替中新增或移除 VM。The health probe adds or removes VMs from the load balancer based on their response to health checks.

建立名為 myHealthProbe 的健康狀態探查,以監視 VM 的健康狀態。Create a health probe named myHealthProbe to monitor the health of the VMs.

  1. 選取左側功能表中的 [所有服務]、選取 [所有資源],然後從資源清單中選取 myLoadBalancerSelect All services in the left-hand menu, select All resources, and then select myLoadBalancer from the resources list.

  2. 在 [設定] 底下選取 [健康狀態探查],然後選取 [新增]。Under Settings, select Health probes, then select Add.

    設定Setting Value
    名稱Name 輸入 myHealthProbeEnter myHealthProbe.
    通訊協定Protocol 選取 [HTTP]。Select HTTP.
    連接埠Port 輸入 80Enter 80.
    間隔Interval 輸入 15 作為探查嘗試之間的 [間隔] 秒數。Enter 15 for number of Interval in seconds between probe attempts.
    狀況不良臨界值Unhealthy threshold 選取 [2] 作為 [狀況不良閾值] 的數值,或將 VM 視為狀況不良之前,必須達到的連續探查失敗次數。Select 2 for number of Unhealthy threshold or consecutive probe failures that must occur before a VM is considered unhealthy.
  3. 保留其餘的預設值,然後選取 [確定]。Leave the rest the defaults and Select OK.

建立負載平衡器規則Create a load balancer rule

負載平衡器規則用來定義如何將流量分散至 VM。A load balancer rule is used to define how traffic is distributed to the VMs. 您可定義連入流量的前端 IP 組態及後端 IP 集區來接收流量。You define the frontend IP configuration for the incoming traffic and the backend IP pool to receive the traffic. 來源和目的地連接埠會在規則中定義。The source and destination port are defined in the rule.

在本節中,您將建立負載平衡器規則:In this section, you'll create a load balancer rule:

  • 已命名為 myHTTPRuleNamed myHTTPRule.
  • 在名為 LoadBalancerFrontEnd 的前端中。In the frontend named LoadBalancerFrontEnd.
  • 接聽 連接埠 80Listening on Port 80.
  • 將負載平衡的流量導向至 連接埠 80 上名為 myBackendPool 的後端。Directs load balanced traffic to the backend named myBackendPool on Port 80.
  1. 選取左側功能表中的 [所有服務]、選取 [所有資源],然後從資源清單中選取 myLoadBalancerSelect All services in the left-hand menu, select All resources, and then select myLoadBalancer from the resources list.

  2. 在 [設定] 下選取 [負載平衡規則],然後選取 [新增]。Under Settings, select Load balancing rules, then select Add.

  3. 使用下列值來設定負載平衡規則:Use these values to configure the load-balancing rule:

    設定Setting Value
    名稱Name 輸入 myHTTPRuleEnter myHTTPRule.
    IP 版本IP Version 選取 IPv4Select IPv4
    前端 IP 位址Frontend IP address 選取 LoadBalancerFrontEndSelect LoadBalancerFrontEnd
    通訊協定Protocol 選取 [TCP]。Select TCP.
    連接埠Port 輸入 80Enter 80.
    後端連接埠Backend port 輸入 80Enter 80.
    後端集區Backend pool 選取 [myBackendPool]。Select myBackendPool.
    健全狀況探查Health probe 選取 [myHealthProbe]。Select myHealthProbe.
    閒置逾時 (分鐘)Idle timeout (minutes) 將滑桿移至 15 分鐘Move the slider to 15 minutes.
    TCP 重設TCP reset 選取 [啟用] 。Select Enabled.
    輸出來源網路位址轉譯 (SNAT)Outbound source network address translation (SNAT) 選取 [(建議) 使用輸出規則,對後端集區成員提供網際網路的存取權]。Select (Recommended) Use outbound rules to provide backend pool members access to the internet.
  4. 保留其餘的預設值,然後選取 [確定]。Leave the rest of the defaults and then select OK.

注意

後端集區中的虛擬機器將不會有使用此設定的輸出網際網路連線。The virtual machines in the backend pool will not have outbound internet connectivity with this configuration.
如需有關提供輸出連線的詳細資訊,請參閱:For more information on providing outbound connectivity, see:
Azure 中的輸出連線Outbound connections in Azure
提供連線的選項:Options for providing connectivity:
僅輸出負載平衡器組態Outbound-only load balancer configuration
什麼是虛擬網路 NAT?What is Virtual Network NAT?

建立後端伺服器Create backend servers

在本節中,您可:In this section, you:

  • 為負載平衡器的後端集區建立三部虛擬機器。Create three virtual machines for the backend pool of the load balancer.
  • 在虛擬機器上安裝 IIS,以測試負載平衡器。Install IIS on the virtual machines to test the load balancer.

建立虛擬機器Create virtual machines

在本節中,您將建立三個 VM (myVM1myVM2myVM3)。In this section, you'll create three VMs (myVM1, myVM2, and myVM3).

這些 VM 會新增至先前建立之負載平衡器的後端集區。These VMs are added to the backend pool of the load balancer that was created earlier.

  1. 在入口網站的左上角,選取 [建立資源] > [計算] > [虛擬機器]。On the upper-left side of the portal, select Create a resource > Compute > Virtual machine.

  2. 在 [建立虛擬機器] 中,輸入或選取 [基本資訊] 索引標籤中的值:In Create a virtual machine, type or select the values in the Basics tab:

    設定Setting Value
    專案詳細資料Project Details
    訂用帳戶Subscription 選取您的 Azure 訂用帳戶Select your Azure subscription
    資源群組Resource Group 選取 CreateIntLBQS-rgSelect CreateIntLBQS-rg
    執行個體詳細資料Instance details
    虛擬機器名稱Virtual machine name 輸入 myVM1Enter myVM1
    區域Region 選取 [西歐]Select West Europe
    可用性選項Availability Options 選取 [可用性區域]Select Availability zones
    可用性區域Availability zone 選取 [1]Select 1
    映像Image 選取 [Windows Server 2019 Datacenter]Select Windows Server 2019 Datacenter
    Azure Spot 執行個體Azure Spot instance 選取 [否]Select No
    大小Size 選擇 VM 大小或接受預設設定Choose VM size or take default setting
    系統管理員帳戶Administrator account
    使用者名稱Username 輸入使用者名稱Enter a username
    密碼Password 輸入密碼Enter a password
    確認密碼Confirm password 再次輸入密碼Reenter password
  3. 選取 [網路] 索引標籤,或選取 [下一步:磁碟] ,然後選取 [下一步:網路]Select the Networking tab, or select Next: Disks, then Next: Networking.

  4. 在 [網路功能] 索引標籤中,選取或輸入:In the Networking tab, select or enter:

    設定Setting Value
    網路介面Network interface
    虛擬網路Virtual network myVNetmyVNet
    子網路Subnet myBackendSubnetmyBackendSubnet
    公用 IPPublic IP 選取 [無]Select None
    NIC 網路安全性群組NIC network security group 選取 [進階]Select Advanced
    設定網路安全性群組Configure network security group 選取 [建立新的]。Select Create new.
    在 [建立網路安全性群組] 的 [名稱] 中,輸入 myNSGIn the Create network security group, enter myNSG in Name.
    選取 [確定]Select OK
    負載平衡Load balancing
    要將此虛擬機器放在現有負載平衡解決方案後面嗎?Place this virtual machine behind an existing load balancing solution? 選取 [是]Select Yes
    負載平衡設定Load balancing settings
    負載平衡選項Load balancing options 選取 [Azure 負載平衡]Select Azure load balancing
    選取負載平衡器Select a load balancer 選取 [myLoadBalancer]Select myLoadBalancer
    選取後端集區Select a backend pool 選取 [myBackendPool]Select myBackendPool
  5. 選取 [檢閱 + 建立]。Select Review + create.

  6. 檢閱設定,然後選取 [建立]。Review the settings, and then select Create.

  7. 依照步驟 1 到 8,使用下列值建立另外兩個 VM (其他所有設定則與 myVM1 相同):Follow the steps 1 to 8 to create two more VMs with the following values and all the other settings the same as myVM1:

    設定Setting VM 2VM 2 VM 3VM 3
    名稱Name myVM2myVM2 myVM3myVM3
    可用性區域Availability zone 22 33
    網路安全性群組Network security group 選取現有的 myNSGSelect the existing myNSG 選取現有的 myNSGSelect the existing myNSG

建立測試虛擬機器Create test virtual machine

在本節中,您將建立名為 myTestVM 的 VM。In this section, you'll create a VM named myTestVM. 此 VM 將用來測試負載平衡器組態。This VM will be used to test the load balancer configuration.

  1. 在入口網站的左上角,選取 [建立資源] > [計算] > [虛擬機器]。On the upper-left side of the portal, select Create a resource > Compute > Virtual machine.

  2. 在 [建立虛擬機器] 中,輸入或選取 [基本資訊] 索引標籤中的值:In Create a virtual machine, type or select the values in the Basics tab:

    設定Setting Value
    專案詳細資料Project Details
    訂用帳戶Subscription 選取您的 Azure 訂用帳戶Select your Azure subscription
    資源群組Resource Group 選取 CreateIntLBQS-rgSelect CreateIntLBQS-rg
    執行個體詳細資料Instance details
    虛擬機器名稱Virtual machine name 輸入 myTestVMEnter myTestVM
    區域Region 選取 [西歐]Select West Europe
    可用性選項Availability Options 選取 [不需要基礎結構備援]Select No infrastructure redundancy required
    映像Image 選取 [Windows Server 2019 Datacenter]Select Windows Server 2019 Datacenter
    Azure Spot 執行個體Azure Spot instance 選取 [否]Select No
    大小Size 選擇 VM 大小或接受預設設定Choose VM size or take default setting
    系統管理員帳戶Administrator account
    使用者名稱Username 輸入使用者名稱Enter a username
    密碼Password 輸入密碼Enter a password
    確認密碼Confirm password 再次輸入密碼Reenter password
  3. 選取 [網路] 索引標籤,或選取 [下一步:磁碟] ,然後選取 [下一步:網路]Select the Networking tab, or select Next: Disks, then Next: Networking.

  4. 在 [網路功能] 索引標籤中,選取或輸入:In the Networking tab, select or enter:

    設定Setting Value
    網路介面Network interface
    虛擬網路Virtual network myVNetmyVNet
    子網路Subnet myBackendSubnetmyBackendSubnet
    公用 IPPublic IP 選取 [無]。Select None.
    NIC 網路安全性群組NIC network security group 選取 [進階]Select Advanced
    設定網路安全性群組Configure network security group 選取您在上一個步驟中建立的 MyNSGSelect MyNSG created in the previous step.
  5. 選取 [檢閱 + 建立]。Select Review + create.

  6. 檢閱設定,然後選取 [建立]。Review the settings, and then select Create.

安裝 IISInstall IIS

  1. 選取左側功能表中的 [所有服務]、選取 [所有資源],然後從資源清單選取 CreateIntLBQS-rg 資源群組中的 [myVM1]。Select All services in the left-hand menu, select All resources, and then from the resources list, select myVM1 that is located in the CreateIntLBQS-rg resource group.

  2. 在 [概觀] 頁面上,選取 [連線],然後選 [Bastion]。On the Overview page, select Connect, then Bastion.

  3. 輸入在 VM 建立期間輸入的使用者名稱和密碼。Enter the username and password entered during VM creation.

  4. 選取 [連接]。Select Connect.

  5. 在伺服器桌面上,瀏覽至 [Windows 系統管理工具] > [Windows PowerShell]。On the server desktop, navigate to Windows Administrative Tools > Windows PowerShell.

  6. 在 PowerShell 視窗中執行下列命令,以便:In the PowerShell Window, run the following commands to:

    • 安裝 IIS 伺服器Install the IIS server
    • 移除預設的 iisstart.htm 檔案Remove the default iisstart.htm file
    • 新增顯示 VM 名稱的新 iisstart.htm 檔案:Add a new iisstart.htm file that displays the name of the VM:
    
     # install IIS server role
     Install-WindowsFeature -name Web-Server -IncludeManagementTools
    
     # remove default htm file
      remove-item  C:\inetpub\wwwroot\iisstart.htm
    
     # Add a new htm file that displays server name
      Add-Content -Path "C:\inetpub\wwwroot\iisstart.htm" -Value $("Hello World from " + $env:computername)
    
  7. 關閉 myVM1 的 Bastion 工作階段。Close the Bastion session with myVM1.

  8. 重複步驟 1 到 6,在 myVM2 和 myVM3 上安裝 IIS 和更新的 iisstart.htm 檔案。Repeat steps 1 to 6 to install IIS and the updated iisstart.htm file on myVM2 and myVM3.

測試負載平衡器Test the load balancer

  1. 在 [概觀] 畫面上尋找負載平衡器的私人 IP 位址。Find the private IP address for the load balancer on the Overview screen. 選取左側功能表中的 [所有服務]、選取 [所有資源],然後選取 [myLoadBalancer]。Select All services in the left-hand menu, select All resources, and then select myLoadBalancer.

  2. myLoadBalancer概觀 中,記下或複製 私人 IP 位址 旁的位址。Make note or copy the address next to Private IP Address in the Overview of myLoadBalancer.

  3. 選取左側功能表中的 [所有服務]、選取 [所有資源],然後從資源清單選取 CreateIntLBQS-rg 資源群組中的 [myTestVM]。Select All services in the left-hand menu, select All resources, and then from the resources list, select myTestVM that is located in the CreateIntLBQS-rg resource group.

  4. 在 [概觀] 頁面上,選取 [連線],然後選 [Bastion]。On the Overview page, select Connect, then Bastion.

  5. 輸入在 VM 建立期間輸入的使用者名稱和密碼。Enter the username and password entered during VM creation.

  6. myTestVM 上開啟 Internet ExplorerOpen Internet Explorer on myTestVM.

  7. 在瀏覽器的網址列中,輸入上一個步驟中的 IP 位址。Enter the IP address from the previous step into the address bar of the browser. IIS Web 伺服器的預設頁面會顯示在瀏覽器上。The default page of IIS Web server is displayed on the browser.

    此螢幕擷取畫面顯示正常顯示預設頁面的瀏覽器視窗。

若要讓負載平衡器將流量分散到這兩個 VM,您可以為每個 VM 的 IIS Web 伺服器自訂預設頁面,然後從用戶端機器強制重新整理您的網頁瀏覽器。To see the load balancer distribute traffic across both VMs, you can customize the default page of each VM's IIS Web server and then force-refresh your web browser from the client machine.

清除資源Clean up resources

若不再需要,可刪除資源群組、負載平衡器和所有相關資源。When no longer needed, delete the resource group, load balancer, and all related resources. 若要這樣做,請選取包含資源的資源群組 CreateIntLBQS-rg,然後選取 [刪除]。To do so, select the resource group CreateIntLBQS-rg that contains the resources and then select Delete.

後續步驟Next steps

在本快速入門中,您已:In this quickstart, you:

  • 已建立 Azure 標準或基本內部負載平衡器Created an Azure standard or basic internal load balancer
  • 將 3 個 VM 連接至負載平衡器。Attached 3 VMs to the load balancer.
  • 設定負載平衡器流量規則、健康情況探查,並測試負載平衡器。Configured the load balancer traffic rule, health probe, and then tested the load balancer.

若要深入了解 Azure Load Balancer,請繼續:To learn more about Azure Load Balancer, continue to: