HOL : 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:
- Create two VMs running a basic website on IIS
- Create two test VMs to view Traffic Manager in action
- Configure DNS name for the VMs running IIS
- Create a Traffic Manager profile for improved website performance
- Add VM endpoints to the Traffic Manager profile
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:
- Create two VMs for running a basic website — one in East US, and the other in West Europe.
- 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.
Create VMs for running websites
In this section, you create two VMs myIISVMEastUS and myIISVMWestEurope in the East US and West Europe Azure regions.
- On the upper, left corner of the Azure portal, select Create a resource > Compute > Windows Server 2019 Datacenter.
- In Create a virtual machine, type or select the following values in the Basics tab:
- Subscription > Resource Group: Select Create new and then type myResourceGroupTM1.
- 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. 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.
- 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. 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.
Install IIS and customize the default web page
In this section, you install the IIS server on the two VMs myIISVMEastUS and myIISVMWestEurope, and then update the default website page. The customized website page shows the name of the VM that you are connecting to when you visit the website from a web browser.
- Select All resources in the left-hand menu, and then from the resources list click myIISVMEastUS that is located in the myResourceGroupTM1 resource group.
- On the Overview page, click Connect, and then in Connect to virtual machine, select Download RDP file.
- Open the downloaded rdp file. If prompted, select Connect. Enter the user name and password you specified when creating the VM. You may need to select More choices, then Use a different account, to specify the credentials you entered when you created the VM.
- Select OK.
- 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.
- On the server desktop, navigate to Windows Administrative Tools>Server Manager.
- 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
#Add custom htm file
Add-Content -Path “C:\inetpub\wwwroot\iisstart.htm” -Value $(“Hello World from “ + $env:computername)
8. Close the RDP connection with myIISVMEastUS.
9. 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.
Configure DNS names for the VMs running IIS
Traffic Manager routes user traffic based on DNS name of the service endpoints. In this section, you configure the DNS names for the IIS servers — myIISVMEastUS and myIISVMWestEurope.
- Click All resources in the left-hand menu, and then from the resources list, select myIISVMEastUS that is located in the myResourceGroupTM1 resource group.
- On the Overview page, under DNS name, select Configure.
- On the Configuration page, under DNS name label, add a unique name, and then select Save.
- Repeat steps 1–3, for the VM named myIISVMWestEurope that is located in the myResourceGroupTM2 resource group.
How to Add above Virtual machines to Traffic manager endpoint.
Create a Traffic Manager profile
Create a Traffic Manager profile that directs user traffic by sending them to the endpoint with lowest latency.
- On the top left-hand side of the screen, select Create a resource > Networking > Traffic Manager profile > Create.
- In the Create Traffic Manager profile, enter or select, the following information, accept the defaults for the remaining settings, and then select Create:
Add Traffic Manager endpoints
Add the two VMs running the IIS servers — myIISVMEastUS & myIISVMWestEurope to route user traffic to the closest endpoint to the user.
- 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.
- In Traffic Manager profile, in the Settings section, click Endpoints, and then click Add.
- Enter, or select, the following information, accept the defaults for the remaining settings, and then select OK:
4. 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
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:
- Determine the DNS name of your Traffic Manager profile.
- View Traffic Manager in action as follows:
- 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.
- 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.