教學課程:使用入口網站在 Azure Load Balancer 中設定連接埠轉送Tutorial: Configure port forwarding in Azure Load Balancer using the portal

連接埠轉送可讓您使用 Azure Load Balancer 公用 IP 位址和連接埠號碼連線到 Azure 虛擬網路中的虛擬機器 (VM)。Port forwarding lets you connect to virtual machines (VMs) in an Azure virtual network by using an Azure Load Balancer public IP address and port number.

在本教學課程中,您會設定 Azure Load Balancer 上的連接埠轉送。In this tutorial, you set up port forwarding on an Azure Load Balancer. 您會了解如何:You learn how to:

  • 建立公用標準負載平衡器來平衡 VM 間的網路流量。Create a public Standard load balancer to balance network traffic over VMs.
  • 使用網路安全性群組 (NSG) 規則建立虛擬網路和 VM。Create a virtual network and VMs with a network security group (NSG) rule.
  • 將 VM 新增至負載平衡器的後端位址集區。Add the VMs to the load balancer back-end address pool.
  • 建立負載平衡器健康情況探查和流量規則。Create a load balancer health probe and traffic rules.
  • 建立負載平衡器輸入 NAT 連接埠轉送規則。Create load balancer inbound NAT port-forwarding rules.
  • 在 VM 上安裝及設定 IIS 以檢視作用中的負載平衡與連接埠轉送。Install and configure IIS on the VMs to view load balancing and port forwarding in action.

如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶If you don't have an Azure subscription, create a free account before you begin.

若要取得本教學課程中的所有步驟,請登入 Azure 入口網站,網址為:https://portal.azure.comFor all steps in this tutorial, sign in to the Azure portal at https://portal.azure.com.

必要條件Prerequisites

  • Azure 訂用帳戶。An Azure subscription.

建立標準負載平衡器Create a Standard load balancer

首先,建立公用標準負載平衡器,以平衡 VM 間的流量負載。First, create a public Standard load balancer that can balance traffic load over VMs. 標準負載平衡器只支援標準公用 IP 位址。A Standard load balancer supports only a Standard public IP address. 當您建立標準負載平衡器時,您也會建立新的標準公用 IP 位址,而該 IP 位址會設定為負載平衡器的前端 (預設的名稱為 LoadBalancerFrontEnd)。When you create a Standard load balancer, you also create a new Standard public IP address, which is configured as the load balancer front end and named LoadBalancerFrontEnd by default.

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

  2. 在 [建立負載平衡器] 頁面的 [基本資料] 中,輸入或選取下列資訊、接受其餘設定的預設值,然後選取 [檢閱 + 建立]:In the Basics tab of the Create load balancer page, enter or select the following information, accept the defaults for the remaining settings, and then select Review + create:

    設定Setting Value
    訂用帳戶Subscription 選取您的訂用帳戶。Select your subscription.
    資源群組Resource group 選取 [新建] ,並在文字方塊中輸入 MyResourceGroupLBSelect Create new and type MyResourceGroupLB in the text box.
    名稱Name myLoadBalancermyLoadBalancer
    區域Region 選取 [西歐] 。Select West Europe.
    類型Type 選取 [公用]。Select Public.
    SKUSKU 選取 [標準]。Select Standard.
    公用 IP 位址Public IP address 選取 [建立新的] 。Select Create new.
    公用 IP 位址名稱Public IP address name 在文字方塊中輸入 myPublicIPType myPublicIP in the text box.
    可用性區域Availability zone 選取 [區域備援] 。Select Zone redundant.

    注意

    務必在支援可用性區域的位置中建立您的 Load Balancer 和其所有資源。Make sure to create your Load Balancer and all resources for it in a location that supports Availability Zones. 如需詳細資訊,請參閱支援可用性區域的區域For more information, see Regions that support Availability Zones.

  3. 在 [檢閱 + 建立] 索引標籤中,按一下 [建立] 。In the Review + create tab, click Create.

建立及設定後端伺服器Create and configure back-end servers

建立一個虛擬網路以及兩部虛擬機器,並將 VM 新增至負載平衡器的後端集區。Create a virtual network with two virtual machines, and add the VMs to the back-end pool of your load balancer.

虛擬網路和參數Virtual network and parameters

在本節中,您需要使用下列資訊來取代步驟中的下列參數:In this section you'll need to replace the following parameters in the steps with the information below:

參數Parameter Value
<resource-group-name> myResourceGroupLB (選取現有的資源群組)myResourceGroupLB (Select existing resource group)
<virtual-network-name> myVNetmyVNet
<region-name> 西歐West Europe
<IPv4-address-space> 10.3.0.0\1610.3.0.0\16
<subnet-name> myBackendSubnetmyBackendSubnet
<subnet-address-range> 10.3.0.0\2410.3.0.0\24

建立虛擬網路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 ReplTest1Value
    專案詳細資料Project Details
    訂用帳戶Subscription 選取您的 Azure 訂用帳戶Select your Azure subscription
    資源群組Resource Group 選取 [新建],輸入 <resource-group-name> ,然後選取 [確定],或根據參數選取現有的 <resource-group-name>Select Create new, enter <resource-group-name>, then select OK, or select an existing <resource-group-name> based on parameters.
    執行個體詳細資料Instance details
    名稱Name 輸入 <virtual-network-name>Enter <virtual-network-name>
    區域Region 選取 <region-name>Select <region-name>
  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 輸入 <IPv4-address-space>Enter <IPv4-address-space>
  5. 在 [子網路名稱] 下,選取 [預設] 字組。Under Subnet name, select the word default.

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

    設定Setting Value
    子網路名稱Subnet name 輸入 <subnet-name>Enter <subnet-name>
    子網路位址範圍Subnet address range 輸入 <subnet-address-range>Enter <subnet-address-range>
  7. 選取 [儲存] 。Select Save.

  8. 選取 [檢閱 + 建立] 索引標籤,或選取 [檢閱 + 建立] 按鈕。Select the Review + create tab or select the Review + create button.

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

建立 VM 並將其新增至負載平衡器後端集區Create VMs and add them to the load balancer back-end pool

  1. 在入口網站的左上方,選取 [建立資源] > [計算] > [Windows Server 2016 Datacenter]。On the upper-left side of the portal, select Create a resource > Compute > Windows Server 2016 Datacenter.

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

    • [訂用帳戶] > [資源群組]:下拉並選取 [MyResourceGroupLB]。Subscription > Resource Group: Drop down and select MyResourceGroupLB.
    • 虛擬機器名稱:輸入 MyVM1。Virtual machine name: Type MyVM1.
    • 區域:選取 [西歐]。Region: Select West Europe.
    • 使用者名稱:輸入 azureuser。Username: Type azureuser.
    • 密碼:輸入 Azure1234567。Password: Type Azure1234567. 在 [確認密碼]**** 欄位中重新輸入密碼。Retype the password in the Confirm password field.
  3. 選取 [網路] 索引標籤,或選取 [下一步:磁碟] ,然後選取 [下一步:網路]Select the Networking tab, or select Next: Disks, then Next: Networking.

    請確定已選取下列項目:Make sure the following are selected:

    • 虛擬網路MyVNetVirtual network: MyVNet
    • 子網路MyBackendSubnetSubnet: MyBackendSubnet
  4. 在 [公用 IP]**** 下選取 [新建]****,然後在 [建立公用 IP 位址]**** 頁面上選取 [標準]****,最後選取 [確定]****。Under Public IP, select Create new, select Standard on the Create public IP address page, and then select OK.

  5. 在 [網路安全性群組]**** 之下選取 [進階]****,即可建立新的網路安全性群組 (NSG,一種防火牆類型)。Under Network Security Group, select Advanced to create a new network security group (NSG), a type of firewall.

    1. 在 [設定網路安全性群組]**** 欄位中,選取 [新建]****。In the Configure network security group field, select Create new.
    2. 輸入 MyNetworkSecurityGroup,然後選取 [確定]。Type MyNetworkSecurityGroup, and select OK.

    注意

    請注意,根據預設,NSG 已有用於開啟連接埠 3389 (遠端桌面 (RDP) 連接埠) 的傳入規則。Observe that by default, the NSG already has an incoming rule to open port 3389, the remote desktop (RDP) port.

  6. 您可以將 VM 新增至您建立的負載平衡器後端集區:Add the VM to a load balancer back-end pool that you create:

    1. 在 [負載平衡] > [將此虛擬機器放置到現有負載平衡解決方案後方?] 底下,選取 [是]。Under LOAD BALANCING > Place this virtual machine behind an existing load balancing solution?, select Yes.
    2. 針對 [負載平衡選項]****,下拉並選取 [Azure Load Balancer]****。For Load balancing options, drop down and select Azure load balancer.
    3. 針對 [選取負載平衡器]****,下拉並選取 [MyLoadBalancer]****。For Select a load balancer, drop down and select MyLoadBalancer.
    4. 在 [選取後端集區]**** 底下選取 [新建]****,然後輸入 [MyBackendPool]** 並選取 [建立]****。Under Select a backend pool, select Create new, then type MyBackendPool, and select Create.

    建立虛擬網路

  7. 選取 [管理] 索引標籤,或選取 [下一步] > [管理]。Select the Management tab, or select Next > Management. 在 [監視] 下,將 [開機診斷] 設定為 [關閉]。Under Monitoring, set Boot diagnostics to Off.

  8. 選取 [檢閱 + 建立]。Select Review + create.

  9. 檢閱設定,並在驗證成功時選取 [建立]****。Review the settings, and when validation succeeds, select Create.

  10. 請依照下列步驟來建立名為 MyVM2 的第二個 VM,其所有其他設定與 MyVM1 相同。Follow the steps to create a second VM named MyVM2, with all the other settings the same as MyVM1.

    針對 [網路安全性群組]****,請在選取 [進階]**** 之後下拉並選取您已建立的 MyNetworkSecurityGroupFor Network Security Group, after selecting Advanced, drop down and select the MyNetworkSecurityGroup that you already created.

    請確定 [選取後端集區]**** 底下的 [MyBackendPool]**** 已選取。Under Select a backend pool, make sure MyBackendPool is selected.

建立 VM 的 NSG 規則Create an NSG rule for the VMs

建立 VM 的網路安全性群組 (NSG) 規則,以允許輸入的網際網路 (HTTP) 連線。Create a network security group (NSG) rule for the VMs to allow inbound internet (HTTP) connections.

注意

根據預設,NSG 已有用於開啟連接埠 3389 (遠端桌面 (RDP) 連接埠) 的規則。By default, the NSG already has a rule that opens port 3389, the remote desktop (RDP) port.

  1. 在左側功能表上,選取 [所有資源]****。Select All resources on the left menu. 從資源清單,選取 MyResourceGroupLB 資源群組中的 MyNetworkSecurityGroupFrom the resource list, select MyNetworkSecurityGroup in the MyResourceGroupLB resource group.

  2. 在 [設定]**** 下,選取 [輸入安全性規則]****,然後選取 [新增]****。Under Settings, select Inbound security rules, and then select Add.

  3. 在 [新增輸入安全性規則]**** 對話方塊中,輸入或選取下列值:In the Add inbound security rule dialog, type or select the following:

    • 來源:選取 [服務標記]****。Source: Select Service Tag.
    • 來源服務標記:選取 [網際網路]****。Source service tag: Select Internet.
    • 目的地連接埠範圍:輸入 80**。Destination port ranges: Type 80.
    • 通訊協定:選取 [TCP]。Protocol: Select TCP.
    • 動作:選取 [允許]****。Action: Select Allow.
    • 優先權:輸入 100**。Priority: Type 100.
    • 名稱:輸入 MyHTTPRule**。Name: Type MyHTTPRule.
    • 描述:輸入 [允許 HTTP]**。Description: Type Allow HTTP.
  4. 選取 [新增] 。Select Add.

    建立 NSG 規則

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

在本節中,您將檢查負載平衡器後端集區,並設定負載平衡器健康情況探查與流量規則。In this section, you inspect the load balancer back-end pool, and configure a load balancer health probe and traffic rules.

檢視後端位址集區View the back-end address pool

若要將流量分散至 VM,負載平衡器會使用後端位址集區,其中包含已連線至負載平衡器的虛擬網路介面 (NIC) IP 位址。To distribute traffic to the VMs, the load balancer uses a back-end address pool, which contains the IP addresses of the virtual network interfaces (NICs) that are connected to the load balancer.

您已建立負載平衡器後端集區,並在建立 VM 時,將 VM 新增至此。You created your load balancer back-end pool and added VMs to it when you created the VMs. 您也可以建立後端集區,然後從負載平衡器的 [後端集區]**** 頁面中新增或移除 VM。You can also create back-end pools and add or remove VMs from the load balancer Backend pools page.

  1. 選取左側功能表上的 [所有資源],然後從資源清單中選取 [MyLoadBalancer]。Select All resources on the left menu, and then select MyLoadBalancer from the resource list.

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

  3. 在 [後端集區] 頁面上,展開 MyBackendPool,並確定 VM1VM2 都已列出。On the Backend pools page, expand MyBackendPool and make sure both VM1 and VM2 are listed.

  4. 選取 [MyBackendPool]。Select MyBackendPool.

    在 [MyBackendPool]**** 頁面上的 [虛擬機器]**** 和 [IP 位址]**** 下,您可以在集區中移除或新增可用 VM。On the MyBackendPool page, under VIRTUAL MACHINE and IP ADDRESS, you can remove or add available VMs to the pool.

您可以在 [後端集區]**** 頁面上選取 [新增]**** 來建立新的後端集區。You can create new back-end pools by selecting Add on the Backend pools page.

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

若要讓負載平衡器能監視 VM 狀態,請使用健康情況探查。To allow the load balancer to monitor VM status, you use a health probe. 健康狀態探查會根據 VM 對健康狀態檢查的回應,以動態方式從負載平衡器輪替中新增或移除 VM。The health probe dynamically adds or removes VMs from the load balancer rotation based on their response to health checks.

  1. 選取左側功能表上的 [所有資源],然後從資源清單中選取 [MyLoadBalancer]。Select All resources on the left menu, and then select MyLoadBalancer from the resource list.

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

  3. 在 [新增健康情況探查]**** 頁面上,輸入或選取下列值:On the Add health probe page, type or select the following values:

    • Name:輸入 MyHealthProbe。Name: Type MyHealthProbe.
    • 通訊協定:下拉並選取 [HTTP]。Protocol: Drop down and select HTTP.
    • 連接埠:輸入 80。Port: Type 80.
    • 路徑:接受 / 作為預設 URI。Path: Accept / for the default URI. 您可以使用任何其他 URI 來取代此值。You can replace this value with any other URI.
    • 間隔:輸入 15。Interval: Type 15. 間隔是探查嘗試之間的秒數。Interval is the number of seconds between probe attempts.
    • 狀況不良閾值:輸入 2。Unhealthy threshold: Type 2. 這個值是將 VM 視為狀況不良之前,所發生的連續探查失敗次數。This value is the number of consecutive probe failures that occur before a VM is considered unhealthy.
  4. 選取 [確定]。Select OK.

    新增探查

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

負載平衡器規則可定義如何將流量分散至 VM。A load balancer rule defines how traffic is distributed to the VMs. 此規則會定義連入流量的前端 IP 組態、用來接收流量的後端 IP 集區,以及所需的來源和目的地連接埠。The rule defines the front-end IP configuration for incoming traffic, the back-end IP pool to receive the traffic, and the required source and destination ports.

名為 MyLoadBalancerRule 的負載平衡器規則會接聽前端 LoadBalancerFrontEnd 中的連接埠 80。The load balancer rule named MyLoadBalancerRule listens to port 80 in the front-end LoadBalancerFrontEnd. 此規則會將網路流量傳送到後端位址集區 MyBackendPool,也在連接埠 80 上。The rule sends network traffic to the back-end address pool MyBackendPool, also on port 80.

  1. 選取左側功能表上的 [所有資源],然後從資源清單中選取 [MyLoadBalancer]。Select All resources on the left menu, and then select MyLoadBalancer from the resource list.

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

  3. 在 [新增負載平衡規則]**** 頁面上,輸入或選取下列值:On the Add load balancing rule page, type or select the following values:

    • Name:輸入 MyLoadBalancerRule。Name: Type MyLoadBalancerRule.
    • 通訊協定:選取 [TCP]。Protocol: Select TCP.
    • 連接埠:輸入 80。Port: Type 80.
    • 後端連接埠:輸入 80。Backend port: Type 80.
    • 後端集區:選取 [MyBackendPool]。Backend pool: Select MyBackendPool.
    • 健康情況探查:選取 [MyHealthProbe]。Health probe: Select MyHealthProbe.
  4. 選取 [確定]。Select OK.

    新增負載平衡器規則

建立輸入 NAT 連接埠轉送規則Create an inbound NAT port-forwarding rule

建立負載平衡器的輸入網路位址轉譯 (NAT) 規則,將流量從前端 IP 位址的特定連接埠轉送至後端 VM 的特定連接埠。Create a load balancer inbound network address translation (NAT) rule to forward traffic from a specific port of the front-end IP address to a specific port of a back-end VM.

  1. 選取左側功能表中的 [所有資源]****,然後從資源清單中選取 [MyLoadBalancer]****。Select All resources in the left-hand menu, and then select MyLoadBalancer from the resource list.

  2. 在 [設定]**** 下,選取 [輸入 NAT 規則]****,然後選取 [新增]****。Under Settings, select Inbound NAT rules, and then select Add.

  3. 在 [新增輸入 NAT 規則]**** 頁面上,輸入或選取下列值:On the Add inbound NAT rule page, type or select the following values:

    • Name:輸入 MyNATRuleVM1。Name: Type MyNATRuleVM1.
    • 連接埠:輸入 4221。Port: Type 4221.
    • 目標虛擬機器:從下拉式清單選取 [MyVM1]。Target virtual machine: Select MyVM1 from the drop-down.
    • 網路 IP 設定:從下拉式選單中選取 [ipconfig1]。Network IP Configuration: Select ipconfig1 from the drop-down.
    • 連接埠對應:選取 [自訂]。Port mapping: Select Custom.
    • 目標連接埠:輸入 3389。Target port: Type 3389.
  4. 選取 [確定]。Select OK.

  5. 重複步驟以新增名為 MyNATRuleVM2 的輸入 NAT 規則,請使用連接埠:4222 及目標虛擬機器MyVM2Repeat the steps to add an inbound NAT rule named MyNATRuleVM2, using Port: 4222 and Target virtual machine: MyVM2.

測試負載平衡器Test the load balancer

在本節中,您將在後端伺服器上安裝 Internet Information Services (IIS),並自訂預設的網頁來顯示機器名稱。In this section, you'll install Internet Information Services (IIS) on the back-end servers, and customize the default web page to show the machine name. 然後,您將使用負載平衡器的公用 IP 位址來測試負載平衡器。Then, you'll use the load balancer's public IP address to test the load balancer.

每部後端 VM 都會提供不同版本的預設 IIS 網頁,以便您查看兩部 VM 之間的負載平衡器分散式要求。Each back-end VM serves a different version of the default IIS web page, so you can see the load balancer distribute requests between the two VMs.

使用 RDP 連線到 VMConnect to the VMs with RDP

使用遠端桌面 (RDP) 連線到每個 VM。Connect to each VM with Remote Desktop (RDP).

  1. 在入口網站的左側功能表上,選取 [所有資源]。In the portal, select All resources on the left menu. 從資源清單,選取 MyResourceGroupLB 資源群組中的每部 VM。From the resource list, select each VM in the MyResourceGroupLB resource group.

  2. 在 [概觀] 頁面上,選取 [連線],然後選取 [下載 RDP 檔案]。On the Overview page, select Connect, and then select Download RDP file.

  3. 開啟所下載的 RDP 檔案,然後選取 [連線]。Open the RDP file you downloaded, and select Connect.

  4. 在 [Windows 安全性] 畫面上,選取 [更多選擇],然後選取 [使用不同的帳戶]。On the Windows Security screen, select More choices and then Use a different account.

    輸入使用者名稱 azureuser** 和密碼 Azure1234567**,然後選取 [確定]****。Enter username azureuser and password Azure1234567, and select OK.

  5. 對任何憑證提示回應 [是]。Respond Yes to any certificate prompt.

    VM 桌面會在新視窗中開啟。The VM desktop opens in a new window.

安裝 IIS 並取代預設的 IIS 網頁Install IIS and replace the default IIS web page

使用 PowerShell 來安裝 IIS,並使用顯示 VM 名稱的頁面取代預設 IIS 網頁。Use PowerShell to install IIS and replace the default IIS web page with a page that displays the name of the VM.

  1. 在 MyVM1 和 MyVM2 上,從 [開始] 功能表啟動 Windows PowerShellOn MyVM1 and on MyVM2, launch Windows PowerShell from the Start menu.

  2. 執行下列命令來安裝 IIS 並取代預設 IIS 網頁:Run the following commands to install IIS and replace the default IIS web page:

     # Install IIS
       Install-WindowsFeature -name Web-Server -IncludeManagementTools
    
     # Remove default htm file
      remove-item  C:\inetpub\wwwroot\iisstart.htm
    
     #Add custom htm file that displays server name
      Add-Content -Path "C:\inetpub\wwwroot\iisstart.htm" -Value $("Hello World from " + $env:computername)
    
    
  3. 選取 [中斷連線],以關閉與 MyVM1 和 MyVM2 的 RDP 連線。Close the RDP connections with MyVM1 and MyVM2 by selecting Disconnect. 請勿關閉 VM。Don't shut down the VMs.

測試負載平衡Test load balancing

  1. 在入口網站中 MyLoadBalancer 的 [概觀]**** 頁面上,於 [公用 IP 位址]**** 之下複製公用 IP 位址。In the portal, on the Overview page for MyLoadBalancer, copy the public IP address under Public IP address. 將滑鼠停在該位址上,然後選取 [複製] 圖示來複製它。Hover over the address and select the Copy icon to copy it. 在此範例中為 40.67.218.235In this example, it is 40.67.218.235.

  2. 在網際網路瀏覽器的網址列中貼上或輸入負載平衡器的公用 IP 位址 (40.67.218.235**)。Paste or type the load balancer's public IP address (40.67.218.235) into the address bar of your internet browser.

    自訂的 IIS Web 伺服器預設頁面會出現在瀏覽器中。The customized IIS web server default page appears in the browser. 顯示的訊息如下:「來自 MyVM1 的 Hello World」或「來自 MyVM2 的 Hello World」。The message reads either Hello World from MyVM1, or Hello World from MyVM2.

    新的 IIS 預設網頁

  3. 重新整理瀏覽器,以查看負載平衡器如何將流量分散於 VM。Refresh the browser to see the load balancer distribute traffic across VMs. 有時候 MyVM1 頁面會出現,而有時候 MyVM2 頁面會出現,因為負載平衡器會將要求分散至每部後端 VM。Sometimes the MyVM1 page appears, and other times the MyVM2 page appears, as the load balancer distributes the requests to each back-end VM.

    注意

    在每一次的嘗試之間,您可能需要清除瀏覽器快取,或開啟新的瀏覽器視窗。You may need to clear your browser cache or open a new browser window between attempts.

測試連接埠轉送Test port forwarding

透過連接埠轉送,您可以使用負載平衡器的 IP 位址和 NAT 規則中所定義的前端連接埠值,以遠端桌面功能連線至後端 VM。With port forwarding, you can remote desktop to a back-end VM by using the IP address of the load balancer and the front-end port value defined in the NAT rule.

  1. 在入口網站中 MyLoadBalancer 的 [概觀]**** 頁面上,複製其公用 IP 位址。In the portal, on the Overview page for MyLoadBalancer, copy its public IP address. 將滑鼠停在該位址上,然後選取 [複製] 圖示來複製它。Hover over the address and select the Copy icon to copy it. 在此範例中為 40.67.218.235In this example, it is 40.67.218.235.

  2. 開啟命令提示字元,使用下列命令及負載平衡器的公用 IP 位址和 VM NAT 規則中定義的前端連接埠,建立 MyVM2 的遠端桌面工作階段。Open a command prompt, and use the following command to create a remote desktop session with MyVM2, using the load balancer's public IP address and the front-end port you defined in the VM's NAT rule.

    mstsc /v:40.67.218.235:4222
    
  3. 開啟所下載的 RDP 檔案,然後選取 [連線]。Open the downloaded RDP file, and select Connect.

  4. 在 [Windows 安全性] 畫面上,選取 [更多選擇],然後選取 [使用不同的帳戶]。On the Windows Security screen, select More choices and then Use a different account.

    輸入使用者名稱 azureuser** 和密碼 Azure1234567**,然後選取 [確定]****。Enter username azureuser and password Azure1234567, and select OK.

  5. 對任何憑證提示回應 [是]。Respond Yes to any certificate prompt.

    MyVM2 桌面會在新視窗中開啟。The MyVM2 desktop opens in a new window.

RDP 會連線成功,因為輸入 NAT 規則 MyNATRuleVM2 會將流量從負載平衡器的前端連接埠 4222 導向 MyVM2 的連接埠 3389 (RDP 連接埠)。The RDP connection succeeds, because the inbound NAT rule MyNATRuleVM2 directs traffic from the load balancer's front-end port 4222 to MyVM2's port 3389 (the RDP port).

清除資源Clean up resources

當您不再需要時,若要刪除負載平衡器和所有相關的資源,請開啟 MyResourceGroupLB 資源群組並選取 [刪除資源群組]。To delete the load balancer and all related resources when you no longer need them, open the MyResourceGroupLB resource group and select Delete resource group.

後續步驟Next steps

在本教學課程中,您建立了標準公用負載平衡器。In this tutorial, you created a Standard public load balancer. 您還建立及設定了資源群組、後端伺服器、健康情況探查,以及負載平衡器的規則。You created and configured network resources, back-end servers, a health probe, and rules for the load balancer. 您已在後端 VM 上安裝 IIS,並使用負載平衡器的公用 IP 位址來測試負載平衡器。You installed IIS on the back-end VMs and used the load balancer's public IP address to test the load balancer. 您已設定並測試負載平衡器上所指定連接埠與後端 VM 上連接埠之間的連接埠轉送。You set up and tested port forwarding from a specified port on the load balancer to a port on a back-end VM.

若要深入了解 Azure Load Balancer,請繼續進行更多的負載平衡器教學課程。To learn more about Azure Load Balancer, continue to more load balancer tutorials.