教學課程:使用流量管理員來改善網站回應Tutorial: Improve website response using Traffic Manager

本教學課程說明如何使用流量管理員將使用者流量導向具有最低延遲的網站,進而建立高度回應的網站。This tutorial describes how to use Traffic Manager to create a highly responsive website by directing user traffic to the website with the lowest latency. 通常,具有最低延遲的資料中心即為最短地理距離的資料中心。Typically, the datacenter with the lowest latency is the one that is closest in geographic distance.

在本教學課程中,您會了解如何:In this tutorial, you learn how to:

  • 在 IIS 上建立兩部執行基本網站的 VMCreate two VMs running a basic website on IIS
  • 建立兩部測試 VM 以檢視流量管理員的運作Create two test VMs to view Traffic Manager in action
  • 為執行 IIS 的 VM 設定 DNS 名稱Configure DNS name for the VMs running IIS
  • 建立流量管理員設定檔以改善網站效能Create a Traffic Manager profile for improved website performance
  • 在流量管理員設定檔中新增 VM 端點Add VM endpoints to the Traffic Manager profile
  • 檢視流量管理員的運作View Traffic Manager in action

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

PrerequisitesPrerequisites

若要查看流量管理員的運作,本教學課程會要求您部署下列項目:In order to see the Traffic Manager in action, this tutorial requires that you deploy the following:

  • 在不同 Azure 區域中執行的兩個基本網站執行個體 - 美國東部西歐Two instances of basic websites running in different Azure regions - East US and West Europe.
  • 用於測試流量管理員的兩個測試 VM - 一個 VM 位於美國東部,另一個 VM 位於西歐Two test VMs for testing the Traffic Manager - one VM in East US and the second VM in West Europe. 測試 VM 用來說明流量管理員如何將使用者流量路由傳送至在相同區域中執行的網站,因為該網站可提供最低延遲。The test VMs are used to illustrate how Traffic Manager routes user traffic to the website that is running in the same region as it provides the lowest latency.

登入 AzureSign in to Azure

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

建立網站Create websites

在本節中,您會建立兩個網站執行個體,這兩個執行個體可在兩個 Azure 區域中為流量管理員設定檔提供兩個服務端點。In this section, you create two website instances that provide the two service endpoints for the Traffic Manager profile in two Azure regions. 請執行下列步驟來建立這兩個網站:Creating the two websites includes the following steps:

  1. 建立兩個 VM 來執行基本網站 - 一個位於美國東部,另一個位於西歐Create two VMs for running a basic website - one in East US, and the other in West Europe.
  2. 在每個 VM 上安裝 IIS 伺服器並更新預設網站頁面,該頁面描述使用者在造訪網站時所連線的 VM 名稱。Install IIS server on each VM and update the default website page that describes the VM name that a user is connected to when visiting the website.

建立 VM 以供執行網站Create VMs for running websites

在本節中,您會在美國東部西歐的 Azure 區域中建立兩個 VM (myIISVMEastUS 和 myIISVMWestEurope )。In this section, you create two VMs myIISVMEastUS and myIISVMWestEurope in the East US and West Europe Azure regions.

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

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

    • [訂用帳戶] > [資源群組] :選取 [新建] ,然後輸入 myResourceGroupTM1Subscription > Resource Group: Select Create new and then type myResourceGroupTM1.
    • 執行個體詳細資料 > 虛擬機器名稱:輸入 myIISVMEastUS 。Instance Details > Virtual machine name: Type myIISVMEastUS.
    • 執行個體詳細資料 > 區域:選取 [美國東部] 。Instance Details > Region: Select East US.
    • 系統管理員帳戶 > 使用者名稱:輸入您選擇的使用者名稱。Administrator Account > Username: Enter a user name of your choosing.
    • 系統管理員帳戶 > 密碼:輸入您選擇的密碼。Administrator Account > Password: Enter a password of your choosing. 密碼長度至少必須有 12 個字元,而且符合定義的複雜度需求The password must be at least 12 characters long and meet the defined complexity requirements.
    • 輸入連接埠規則 > 公用輸入連接埠:選取 [允許選取的連接埠] 。Inbound Port Rules > Public inbound ports: Select Allow selected ports.
    • 輸入連接埠規則 > 選取輸入連接埠:在下拉式方塊中選取 [RDP] 和 [HTTP] 。Inbound Port Rules > Select inbound ports: Select RDP and HTTP in the pull down box.
  3. 選取 [管理] 索引標籤,或選取 [下一步:磁碟] ,然後選取 [下一步:網路功能] ,然後選取 [下一步:管理]Select the Management tab, or select Next: Disks, then Next: Networking, then Next: Management. 在 [監視] 下,將 [開機診斷] 設定為 [關閉] 。Under Monitoring, set Boot diagnostics to Off.

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

  5. 檢閱設定,然後按一下 [建立] 。Review the settings, and then click Create.

  6. 請依照步驟來建立名為 myIISVMWestEurope 的第二個 VM,並將 [資源群組] 命名為 myResourceGroupTM2 、將 [地區] 設定為 [西歐] ,然後將其他設定設成跟 myIISVMEastUS 一樣。Follow the steps to create a second VM named myIISVMWestEurope, with a Resource group name of myResourceGroupTM2, a location of West Europe, and all the other settings the same as myIISVMEastUS.

  7. 可能需要數分鐘才會建立虛擬機器。The VMs take a few minutes to create. 請等到這兩個虛擬機器都已建立,再繼續進行其餘步驟。Do not continue with the remaining steps until both VMs are created.

    建立 VM

安裝 IIS 和自訂預設網頁Install IIS and customize the default web page

在本節中,您會在兩個 VM (myIISVMEastUS 和 myIISVMWestEurope ) 上安裝 IIS 伺服器,然後更新預設網頁。In this section, you install the IIS server on the two VMs myIISVMEastUS and myIISVMWestEurope, and then update the default website page. 自訂的網站頁面會顯示當您從網頁瀏覽器瀏覽網站時,您所連線的 VM 名稱。The customized website page shows the name of the VM that you are connecting to when you visit the website from a web browser.

  1. 選取左側功能表中的 [所有資源] ,然後從資源清單按一下 myIISVMEastUS,其位於 myResourceGroupTM1 資源群組中。Select All resources in the left-hand menu, and then from the resources list click myIISVMEastUS that is located in the myResourceGroupTM1 resource group.

  2. 在 [概觀] 頁面上,按一下 [連線] ,然後在 [連線至虛擬機器] 中選取 [下載 RDP 檔案] 。On the Overview page, click Connect, and then in Connect to virtual machine, select Download RDP file.

  3. 開啟所下載的 rdp 檔案。Open the downloaded rdp file. 如果出現提示,請選取 [連接] 。If prompted, select Connect. 輸入您在建立 VM 時指定的使用者名稱和密碼。Enter the user name and password you specified when creating the VM. 您可能需要選取 [其他選擇] ,然後選取 [使用不同的帳戶] ,以指定您在建立 VM 時輸入的認證。You may need to select More choices, then Use a different account, to specify the credentials you entered when you created the VM.

  4. 選取 [確定] 。Select OK.

  5. 您可能會在登入過程中收到憑證警告。You may receive a certificate warning during the sign-in process. 如果您收到警告,請選取 [是] 或 [繼續] 以繼續進行連線。If you receive the warning, select Yes or Continue, to proceed with the connection.

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

  7. 啟動 VM1 上的 Windows PowerShell 上,並使用下列命令來安裝 IIS 伺服器及更新預設 htm 檔。Launch Windows PowerShell on VM1 and using the following commands to install IIS server and update the default htm file.

    # Install IIS
    Install-WindowsFeature -name Web-Server -IncludeManagementTools
    
    # Remove default htm file
    remove-item C:\inetpub\wwwroot\iisstart.htm
    
    #Add custom htm file
    Add-Content -Path "C:\inetpub\wwwroot\iisstart.htm" -Value $("Hello World from " + $env:computername)
    

    安裝 IIS 和自訂網頁

  8. 關閉與 myIISVMEastUS 的 RDP 連線。Close the RDP connection with myIISVMEastUS.

  9. 重複步驟 1-8,方法是與 myResourceGroupTM2 資源群組內的 myIISVMWestEurope VM 建立 RDP 連線,以安裝 IIS 並自訂其預設網頁。Repeat steps 1-8 with by creating an RDP connection with the VM myIISVMWestEurope within the myResourceGroupTM2 resource group to install IIS and customize its default web page.

為執行 IIS 的 VM 設定 DNS 名稱Configure DNS names for the VMs running IIS

流量管理員會根據服務端點的 DNS 名稱來路由傳送使用者流量。Traffic Manager routes user traffic based on DNS name of the service endpoints. 在本節中,您會設定 IIS 伺服器 myIISVMEastUS 和 myIISVMWestEurope 的 DNS 名稱。In this section, you configure the DNS names for the IIS servers - myIISVMEastUS and myIISVMWestEurope.

  1. 按一下左側功能表中的 [所有資源] ,然後從資源清單選取 myIISVMEastUS,其位於 myResourceGroupTM1 資源群組中。Click All resources in the left-hand menu, and then from the resources list, select myIISVMEastUS that is located in the myResourceGroupTM1 resource group.
  2. 在 [概觀] 頁面的 [DNS 名稱] 底下,選取 [設定] 。On the Overview page, under DNS name, select Configure.
  3. 在 [組態] 頁面的 [DNS 名稱] 標籤之下,新增唯一的名稱,然後選取 [儲存] 。On the Configuration page, under DNS name label, add a unique name, and then select Save.
  4. 針對 myResourceGroupTM2 資源群組中名為 myIISVMWestEurope 的 VM,重複步驟 1-3。Repeat steps 1-3, for the VM named myIISVMWestEurope that is located in the myResourceGroupTM2 resource group.

建立測試 VMCreate test VMs

在本節中,您會在每個 Azure 區域 (美國東部西歐) 中建立 VM (myVMEastUS 和 myVMWestEurope )。In this section, you create a VM (myVMEastUS and myVMWestEurope) in each Azure region (East US and West Europe). 當您瀏覽至網站時,您將使用這些 VM 來測試流量管理員如何將流量路由至最接近的 IIS 伺服器。You will use these VMs to test how Traffic Manager routes traffic to the nearest IIS server when you browse to the website.

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

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

    • [訂用帳戶] > [資源群組] :選取 [myResourceGroupTM1] 。Subscription > Resource Group: Select myResourceGroupTM1.
    • 執行個體詳細資料 > 虛擬機器名稱:輸入 myVMEastUS 。Instance Details > Virtual machine name: Type myVMEastUS.
    • 執行個體詳細資料 > 區域:選取 [美國東部] 。Instance Details > Region: Select East US.
    • 系統管理員帳戶 > 使用者名稱:輸入您選擇的使用者名稱。Administrator Account > Username: Enter a user name of your choosing.
    • 系統管理員帳戶 > 密碼:輸入您選擇的密碼。Administrator Account > Password: Enter a password of your choosing. 密碼長度至少必須有 12 個字元,而且符合定義的複雜度需求The password must be at least 12 characters long and meet the defined complexity requirements.
    • 輸入連接埠規則 > 公用輸入連接埠:選取 [允許選取的連接埠] 。Inbound Port Rules > Public inbound ports: Select Allow selected ports.
    • 輸入連接埠規則 > 選取輸入連接埠:在下拉式方塊中選取 [RDP] 。Inbound Port Rules > Select inbound ports: Select RDP in the pull down box.
  3. 選取 [管理] 索引標籤,或選取 [下一步:磁碟] ,然後選取 [下一步:網路功能] ,然後選取 [下一步:管理]Select the Management tab, or select Next: Disks, then Next: Networking, then Next: Management. 在 [監視] 下,將 [開機診斷] 設定為 [關閉] 。Under Monitoring, set Boot diagnostics to Off.

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

  5. 檢閱設定,然後按一下 [建立] 。Review the settings, and then click Create.

  6. 請依照步驟來建立名為 myVMWestEurope 的第二個 VM,並將 [資源群組] 命名為 myResourceGroupTM2 、將 [地區] 設定為 [西歐] ,然後將其他設定設成跟 myVMEastUS 一樣。Follow the steps to create a second VM named myVMWestEurope, with a Resource group name of myResourceGroupTM2, a location of West Europe, and all the other settings the same as myVMEastUS.

  7. 可能需要數分鐘才會建立虛擬機器。The VMs take a few minutes to create. 請等到這兩個虛擬機器都已建立,再繼續進行其餘步驟。Do not continue with the remaining steps until both VMs are created.

建立流量管理員設定檔Create a Traffic Manager profile

建立流量管理員設定檔,其導向使用者流量的方式是將使用者流量傳送至具有最低延遲的端點。Create a Traffic Manager profile that directs user traffic by sending them to the endpoint with lowest latency.

  1. 在畫面的左上方,選取 [建立資源] > [網路] > [流量管理員設定檔] > [建立] 。On the top left-hand side of the screen, select Create a resource > Networking > Traffic Manager profile > Create.

  2. 在 [建立流量管理員設定檔] 中,輸入或選取下列資訊、接受其餘設定的預設值,然後選取 [建立] :In the Create Traffic Manager profile, enter or select, the following information, accept the defaults for the remaining settings, and then select Create:

    設定Setting Value
    名稱Name 此名稱在 trafficmanager.net 區域內必須是唯一的,而且會產生 DNS 名稱 trafficmanager.net,用以存取您的流量管理員設定檔。This name needs to be unique within the trafficmanager.net zone and results in the DNS name, trafficmanager.net that is used to access your Traffic Manager profile.
    路由方法Routing method 選取 [效能] 路由方法。Select the Performance routing method.
    訂用帳戶Subscription 選取您的訂用帳戶。Select your subscription.
    資源群組Resource group 選取資源群組 myResourceGroupTM1 。Select the Resource group myResourceGroupTM1.
    LocationLocation 選取 [美國東部] 。Select East US. 這項設定是指資源群組的位置,完全不影響將部署到全球的流量管理員設定檔。This setting refers to the location of the resource group, and has no impact on the Traffic Manager profile that will be deployed globally.

    建立流量管理員設定檔

新增流量管理員端點Add Traffic Manager endpoints

新增兩部執行 IIS 伺服器的 VM (myIISVMEastUS & myIISVMWestEurope),以將使用者流量路由傳送至最接近使用者的端點。Add the two VMs running the IIS servers - myIISVMEastUS & myIISVMWestEurope to route user traffic to the closest endpoint to the user.

  1. 在入口網站的搜尋列中,搜尋您在上一節建立的流量管理員設定檔名稱,然後在顯示的結果中選取設定檔。In the portal’s search bar, search for the Traffic Manager profile name that you created in the preceding section and select the profile in the results that the displayed.

  2. 在 [流量管理員設定檔] 的 [設定] 區段中,按一下 [端點] ,然後按一下 [新增] 。In Traffic Manager profile, in the Settings section, click Endpoints, and then click Add.

  3. 輸入或選取下列資訊、接受其餘設定的預設值,然後選取 [確定] :Enter, or select, the following information, accept the defaults for the remaining settings, and then select OK:

    設定Setting Value
    類型Type Azure 端點Azure endpoint
    名稱Name myEastUSEndpointmyEastUSEndpoint
    目標資源類型Target resource type 公用 IP 位址Public IP Address
    目標資源Target resource 選擇公用 IP 位址以顯示具有相同訂用帳戶下公用 IP 位址的資源清單。Choose a Public IP address to show the listing of resources with Public IP addresses under the same subscription. 在 [資源] 中,選取名為 myIISVMEastUS-ip 的公用 IP 位址。In Resource, select the public IP address named myIISVMEastUS-ip. 這是美國東部 IIS 伺服器 VM 的公用 IP 位址。This is the public IP address of the IIS server VM in East US.
  4. 重複步驟 2 和 3,以針對與 IIS 伺服器 VM myIISVMWestEurope 相關聯的公用 IP 位址 myIISVMWestEurope-ip ,新增另一個名為 myWestEuropeEndpoint 的端點。Repeat steps 2 and 3 to add another endpoint named myWestEuropeEndpoint for the public IP address myIISVMWestEurope-ip that is associated with the IIS server VM named myIISVMWestEurope.

  5. 這兩個端點新增完畢後,它們會顯示在 [流量管理員設定檔] 中,而且監視狀態是 [線上] 。When the addition of both endpoints is complete, they are displayed in Traffic Manager profile along with their monitoring status as Online.

    新增流量管理員端點

測試流量管理員設定檔Test Traffic Manager profile

在本節中,您會測試流量管理員如何將使用者流量路由傳送至執行網站的最接近 VM,以提供最低延遲。In this section, you test how the Traffic Manager routes user traffic to the nearest VMs running the website to provide minimum latency. 若要查看運作中的流量管理員,請完成下列步驟:To view the Traffic Manager in action, complete the following steps:

  1. 決定流量管理員設定檔的 DNS 名稱。Determine the DNS name of your Traffic Manager profile.
  2. 檢視流量管理員的運作,如下所示:View Traffic Manager in action as follows:
    • 從位於美國東部區域的測試 VM (myVMEastUS),在網頁瀏覽器中瀏覽至您流量管理員設定檔的 DNS 名稱。From the test VM (myVMEastUS) that is located in the East US region, in a web browser, browse to the DNS name of your Traffic Manager profile.
    • 從位於西歐區域的測試 VM (myVMWestEurope ),在網頁瀏覽器中瀏覽至您流量管理員設定檔的 DNS 名稱。From the test VM (myVMWestEurope) that is located in the West Europe region, in a web browser, browse to the DNS name of your Traffic Manager profile.

決定流量管理員設定檔的 DNS 名稱Determine DNS name of Traffic Manager profile

在本教學課程中,為了簡單起見,您可使用流量管理員設定檔的 DNS 名稱來瀏覽網站。In this tutorial, for simplicity, you use the DNS name of the Traffic Manager profile to visit the websites.

您可以決定流量管理員設定檔的 DNS 名稱,如下所示:You can determine the DNS name of the Traffic Manager profile as follows:

  1. 在入口網站的搜尋列中,搜尋您在上一節建立的流量管理員設定檔名稱。In the portal’s search bar, search for the Traffic Manager profile name that you created in the preceding section. 在顯示的結果中,按一下流量管理員設定檔。In the results that are displayed, click the traffic manager profile.

  2. 按一下 [概觀] 。Click Overview.

  3. [流量管理員設定檔] 會顯示新建立之流量管理員設定檔的 DNS 名稱。The Traffic Manager profile displays the DNS name of your newly created Traffic Manager profile. 在生產部署中,您會使用 DNS CNAME 記錄,將虛名網域名稱設定為指向流量管理員網域名稱。In production deployments, you configure a vanity domain name to point to the Traffic Manager domain name, using a DNS CNAME record.

    流量管理員 DNS 名稱

檢視流量管理員的運作View Traffic Manager in action

在本節中,您可以看到流量管理員的運作。In this section, you can see the Traffic Manager is action.

  1. 選取左側功能表中的 [所有資源] ,然後從資源清單按一下 myVMEastUS,其位於 myResourceGroupTM1 資源群組中。Select All resources in the left-hand menu, and then from the resources list click myVMEastUS that is located in the myResourceGroupTM1 resource group.

  2. 在 [概觀] 頁面上,按一下 [連線] ,然後在 [連線至虛擬機器] 中選取 [下載 RDP 檔案] 。On the Overview page, click Connect, and then in Connect to virtual machine, select Download RDP file.

  3. 開啟所下載的 rdp 檔案。Open the downloaded rdp file. 如果出現提示,請選取 [連接] 。If prompted, select Connect. 輸入您在建立 VM 時指定的使用者名稱和密碼。Enter the user name and password you specified when creating the VM. 您可能需要選取 [其他選擇] ,然後選取 [使用不同的帳戶] ,以指定您在建立 VM 時輸入的認證。You may need to select More choices, then Use a different account, to specify the credentials you entered when you created the VM.

  4. 選取 [確定] 。Select OK.

  5. 您可能會在登入過程中收到憑證警告。You may receive a certificate warning during the sign-in process. 如果您收到警告,請選取 [是] 或 [繼續] 以繼續進行連線。If you receive the warning, select Yes or Continue, to proceed with the connection.

  6. 在 VM myVMEastUS 的網頁瀏覽器中,輸入流量管理員設定檔的 DNS 名稱,以檢視您的網站。In a web browser on the VM myVMEastUS, type the DNS name of your Traffic Manager profile to view your website. VM 位於美國東部,所以您會路由至在最接近 IIS 伺服器 myIISVMEastUS (位於美國東部) 上裝載的最接近網站。Since the VM located in East US, you are routed to the nearest website hosted on the nearest IIS server myIISVMEastUS that is located in East US.

    測試流量管理員設定檔

  7. 接下來,使用步驟 1-5 來連線到位於西歐的 VM myVMWestEurope,並從這個 VM 瀏覽到流量管理員設定檔網域名稱。Next, connect to the VM myVMWestEurope located in West Europe using steps 1-5 and browse to the Traffic Manager profile domain name from this VM. VM 位於西歐,所以您現在會路由至在最接近 IIS 伺服器 myIISVMWestEurope (位於西歐) 上裝載的網站。Since the VM located in West Europe, you are now routed to the website hosted on nearest the IIS server myIISVMWestEurope that is located in West Europe.

    測試流量管理員設定檔

刪除流量管理員設定檔Delete the Traffic Manager profile

如果不再需要,請刪除資源群組 (ResourceGroupTM1ResourceGroupTM2)。When no longer needed, delete the resource groups (ResourceGroupTM1 and ResourceGroupTM2). 若要這麼做,請選取資源群組 (ResourceGroupTM1ResourceGroupTM2),然後選取 [刪除] 。To do so, select the resource group (ResourceGroupTM1 or ResourceGroupTM2), and then select Delete.

後續步驟Next steps