Exercise - Create web sites

Completed

In the motor-vehicle department system, you decide to run the web app on two servers. You implement each server using a virtual machine.

In this exercise, you'll create a pair of virtual machines and install the vehicle-registration web app. You'll also configure a virtual network that Application Gateway can use to connect to the virtual machines. Finally, you'll deploy the license-renewal web site to an instance of Azure App Service.

Diagram showing the resources that will be deployed.

Create virtual machines and deploy the vehicle registration site

  1. Open the Azure Cloud Shell in your browser, and log in to the directory with access to the subscription in which you want to create resources.

  2. Run the following command in the Cloud Shell to create a variable to store your resource group name, and a resource group for your resources. Replace <resource group name> with a name for your resource group, and <location> with the Azure region in which you'd like to deploy your resources.

    Note

    If you need to find the location name, you can use the following command: az account list-locations -o table

    RG=<resource group name>
    az group create --name $RG --location <location>
    
  3. In the Cloud Shell window, run the following command. This command uses the Azure command-line interface to create a virtual network named vehicleappvnet. It's a private network that provides addresses in the range 10.0.0.0 to 10.0.255.255. The command also creates a subnet called webServerSubnet, with the address range 10.0.1.0 to 10.0.1.255. This subnet contains the virtual machines.

    az network vnet create \
      --resource-group $RG \
      --name vehicleAppVnet \
      --address-prefixes 10.0.0.0/16 \
      --subnet-name webServerSubnet \
      --subnet-prefixes 10.0.1.0/24
    
  4. To download the script that creates the virtual machines, run the following command:

    git clone https://github.com/MicrosoftDocs/mslearn-load-balance-web-traffic-with-application-gateway module-files
    
  5. To create and configure the virtual machines for the web servers, run the following commands. The virtual machines are called webServer1 and webServer2. Each virtual machine runs Ubuntu Server. An administrative user account is created for each virtual machine, with the login name azureuser. Each virtual machine has the vehicle registration web app installed.

    The first command runs asynchronously to enable both virtual machines to be created simultaneously.

    az vm create \
      --resource-group $RG \
      --name webServer1 \
      --image Ubuntu2204 \
      --admin-username azureuser \
      --generate-ssh-keys \
      --vnet-name vehicleAppVnet \
      --subnet webServerSubnet \
      --public-ip-address "" \
      --nsg "" \
      --custom-data module-files/scripts/vmconfig.sh \
      --no-wait
    
    az vm create \
      --resource-group $RG \
      --name webServer2 \
      --image Ubuntu2204 \
      --admin-username azureuser \
      --generate-ssh-keys \
      --vnet-name vehicleAppVnet \
      --subnet webServerSubnet \
      --public-ip-address "" \
      --nsg "" \
      --custom-data module-files/scripts/vmconfig.sh
    
  6. To confirm both virtual machines were created successfully, run the following command:

    az vm list \
      --resource-group $RG \
      --show-details \
      --output table
    

    You should get output similar to the following. Before continuing, ensure the PowerState is VM running for both virtual machines.

    Name          ResourceGroup      PowerState    PublicIps    Fqdns    Location        Zones
    ------------  -----------------  ------------  -----------  -------  --------------  -------
    webServer1    MyResourceGroup    VM running                          southcentralus
    webServer2    MyResourceGroup    VM running                          southcentralus
    

You've now created the virtual machines running the vehicle-registration web app. Both virtual machines are identical and are part of the same virtual network.

Create App Service and deploy the license renewal site

  1. To start, generate a unique name for the website by running the following command:

    APPSERVICE="licenserenewal$RANDOM"
    
  2. Next, create the App Service plan the web app uses by running the following command:

    az appservice plan create \
        --resource-group $RG \
        --name vehicleAppServicePlan \
        --sku S1
    
  3. Lastly, create the web app and deploy the license renewal site:

    az webapp create \
        --resource-group $RG \
        --name $APPSERVICE \
        --plan vehicleAppServicePlan \
        --deployment-source-url https://github.com/MicrosoftDocs/mslearn-load-balance-web-traffic-with-application-gateway \
        --deployment-source-branch appService 
    

Next, let's take a closer look at configuring Application Gateway.