Exercise - Create web sites
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.
Create virtual machines and deploy the vehicle registration site
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.
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>
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 calledwebServerSubnet
, 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
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
To create and configure the virtual machines for the web servers, run the following commands. The virtual machines are called
webServer1
andwebServer2
. Each virtual machine runs Ubuntu Server. An administrative user account is created for each virtual machine, with the login nameazureuser
. 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
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
To start, generate a unique name for the website by running the following command:
APPSERVICE="licenserenewal$RANDOM"
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
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.