Monday, 1 July 2019

Knowledge Check

Knowledge Check

Check your knowledge

1. 
What is Azure?
Azure provides raw compute power and storage, as well as services to help you explore new software paradigms such as intelligent bots and mixed reality.
2. 
Which of the following is an example of an Azure compute service?
Azure Virtual Machines provide compute power and support both Windows and Linux operating systems.
3. 
When should you scale out your deployment?
Scaling out means adding additional systems, such as virtual machines. For example, you might create many virtual machines configured in the same way and use a load balancer to distribute work across them.

Next unit: Summary

Exercise - Scale up

Exercise - Scale up

Sandbox activated! Time remaining: 
Choose which platform you want to run in the cloud
Your web server is up and running, but you realize you need more computing power to make the experience great for your users. How can you make your VM run faster?
In your data center, you might move your web server to more powerful hardware to solve performance problems. The problem is you need to buy, rack, and power your new system. With Azure, the answer is much simpler.
Before you scale up your VM to a more powerful size, let's first define what scale means.
 Important
This exercise uses the virtual machine (VM) you created in the Exercise - Create a virtual machine unit. Please make sure you've completed that exercise before continuing.

What is scale?

Scale refers to adding network bandwidth, memory, storage, or compute power to achieve better performance.
You may have heard the terms scaling up and scaling out.
Scaling up, or vertical scaling, means to increase the memory, storage, or compute power on an existing virtual machine. For example, you can add additional memory to a web or database server to make it run faster.
Scaling out, or horizontal scaling, means to add extra virtual machines to power your application. For example, you might create many virtual machines configured in exactly the same way and use a load balancer to distribute work across them.
 Tip
The cloud is elastic. You can scale down or scale in your deployment if you needed to scale up or scale out only temporarily. Scaling down or scaling in can help you save money.

Azure Advisor and Azure Cost Management are two services that help you optimize cloud spend. You can use these services to identify where you're using more than you need, and then scale back to the capacity you're actually using.

Scale up your VM

Recall that you specified the size Standard_DS2_v2 when you created your VM. Your VM currently has two virtual CPUs and 7 GB of memory.
Let's bump up to the next size, Standard_DS3_v2. Your VM will then have four virtual CPUs and 14 GB of memory.


  1. From Cloud Shell, run az vm resize to increase your VM's size to Standard_DS3_v2.
    Azure CLI
    az vm resize \
      --resource-group Learn-8eb73ca3-d5f2-4ee1-89c5-cdcd999a132a \
      --name myVM \
      --size Standard_DS3_v2
    
    The update process takes about a minute. Your VM restarts during the process.
  2. Run az vm show to verify that your VM is running the new size.
    Azure CLI
    az vm show \
      --resource-group Learn-8eb73ca3-d5f2-4ee1-89c5-cdcd999a132a \
      --name myVM \
      --query "hardwareProfile" \
      --output tsv
    
    You see your new VM size, Standard_DS3_v2.
    output
    Standard_DS3_v2
    

Exercise - Add a web server

Exercise - Add a web server

Sandbox activated! Time remaining: 
Choose which platform you want to run in the cloud
Here you'll install a web server in your VM and serve up a basic web page that displays the VM's hostname.
 Important
This exercise uses the virtual machine (VM) you created in the Exercise - Create a virtual machine unit. Please make sure you've completed that exercise before continuing.
To configure a VM, you have several choices. You can connect directly and interactively configure your system. For example, on Windows systems you can create a Remote Desktop session to connect to the UI of your remote Windows computer as if you were seated at it. On Linux systems, you can create an SSH connection to securely work with your remote Linux system from the terminal.
Manual configuration is a good start, but as you add systems, you can automate your deployments. Automation involves running repeatable processes such as programs and scripts that take care of the heavy lifting for you.
Here, you'll configure IIS remotely from your Cloud Shell session using a feature of Windows-based Azure virtual machines called the Custom Script Extension.

What is IIS?

Internet Information Services, or IIS, is a web server that runs on Windows. You can use IIS to serve standard web content (HTML, CSS, and JavaScript) or run ASP.NET and other kinds of web applications. IIS comes with Windows Server, but you need to activate it to start serving web pages.

What's the Custom Script Extension?

The Custom Script Extension is an easy way to download and run scripts on your Azure VMs. It's just one of the many ways you can configure the system once your VM is up and running.
You can store your scripts in Azure storage or in a public location such as GitHub. You can run scripts manually or as part of a more automated deployment. Here, you'll run an Azure CLI command to download a PowerShell script from GitHub and execute it on your VM. The script configures IIS.

Configure IIS

Here you'll use the Custom Script Extension to configure IIS remotely on your VM from Cloud Shell. You'll also configure the firewall to allow inbound network access on port 80 (HTTP).
  1. From Cloud Shell, run this az vm extension set command to download and execute a PowerShell script that installs IIS and configures a basic home page.
    Azure CLI
    az vm extension set \
      --resource-group Learn-8eb73ca3-d5f2-4ee1-89c5-cdcd999a132a \
      --vm-name myVM \
      --name CustomScriptExtension \
      --publisher Microsoft.Compute \
      --settings "{'fileUris':['https://raw.githubusercontent.com/MicrosoftDocs/mslearn-welcome-to-azure/master/configure-iis.ps1']}" \
      --protected-settings "{'commandToExecute': 'powershell -ExecutionPolicy Unrestricted -File configure-iis.ps1'}"
    
    The process to configure IIS, set the contents of the homepage, and start the service takes a couple minutes to complete.
    In the meantime, you can examine the PowerShell script  from a separate browser tab if you'd like. The script installs IIS and configures the home page to display a welcome message along with the VM's computer name, "myVM".
  2. Run this az vm open-port command to open port 80 (HTTP) through the firewall.
    Azure CLI
    az vm open-port \
      --name myVM \
      --resource-group Learn-8eb73ca3-d5f2-4ee1-89c5-cdcd999a132a \
      --port 80
    

Verify the configuration

Now that IIS is set up, let's verify that it's running.
  1. Run this az vm show command to list your VM's public IP address.
    Azure CLI
    az vm show \
      --name myVM \
      --resource-group Learn-8eb73ca3-d5f2-4ee1-89c5-cdcd999a132a \
      --show-details \
      --query [publicIps] \
      --output tsv
    
    You see your VM's public IP address, for example, 104.211.9.245.
  2. In a new browser tab, navigate to your VM's IP address (http:// followed by the IP address). You'll see your welcome message and your VM's name.
    If you don't see your welcome message:
    • Verify that you're using your VM's IP address and not the IP address shown in any of the examples.
    • Verify that you ran the az vm open-port command shown earlier to open port 80 (HTTP) through the firewall.
    • Wait a few moments and refresh the page. Although IIS is installed, the service may not yet have fully started.

Next unit: Exercise - Scale up

Create Your VM

Create a Windows VM

Let's get your Windows VM up and running.
  1. In the Cloud Shell on the side of this page, run the following commands to create a username and generate a random password.
    bash
    USERNAME=azureuser
    PASSWORD=$(openssl rand -base64 32)
    
    The username and password here are stored as Bash variables. If you're a PowerShell user, just know that Bash variables are similar. You'll use these variables in the next step to set the Windows admin name and password.
    This example uses azureuser as the username. But the name can be whatever you'd like.
    There are many ways to generate passwords. The command shown here is just one of them.
  2. Run the following az vm create command to create your VM. The command creates the VM in the "East US" location, but you can change that to any of the locations listed above.
    Azure CLI
    az vm create \
      --name myVM \
      --resource-group Learn-8eb73ca3-d5f2-4ee1-89c5-cdcd999a132a \
      --image Win2019Datacenter \
      --size Standard_DS2_v2 \
      --location eastus \
      --admin-username $USERNAME \
      --admin-password $PASSWORD
    
     Tip
    You can use the Copy button to copy commands to the clipboard. To paste, right click on a new line in the Cloud Shell window and select Paste or use the Shift+Insert keyboard shortcut (⌘+V on macOS).
    Your VM will take four to five minutes to come up. Compare that to the time it takes to purchase, rack, and configure a system in your data center. Quite a difference!
While you're waiting, let's review the command you just ran.
  • The VM is named myVM. This name identifies the VM in Azure. It also becomes the VM's internal hostname, or computer name.
  • The resource group, or the VM's logical container, is named Learn-8eb73ca3-d5f2-4ee1-89c5-cdcd999a132a.
  • Win2019Datacenter specifies the Windows Server 2019 VM image.
  • Standard_DS2_v2 refers to the size of the VM. This size has two virtual CPUs and 7 GB of memory.
  • The username and password enable you to connect to your VM later. For example, you can connect over Remote Desktop or WinRM to work with and configure the system.
 Note
Although you have everything you need to connect directly to your VM, don't do so quite yet. In the next unit, you'll see one way to connect to the VM to make changes to its configuration.
By default, Azure assigns a public IP address to your VM. You can configure a VM to be accessible from the Internet or only from the internal network.
You can also check out this short video about some of the options you have to create and manage VMs.

Options to create and manage VMs

When the VM is ready, you see information about it. Here's an example.
JSON
{
  "fqdns": "",
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
  "location": "eastus",
  "macAddress": "00-0D-3A-1E-1B-3B",
  "powerState": "VM running",
  "privateIpAddress": "10.0.0.5",
  "publicIpAddress": "104.211.9.245",
  "resourceGroup": "myResourceGroup",
  "zones": ""
}
 Note
On Microsoft Learn, you'll often see sample output, like the output shown above. We show you these examples so you can compare them to the output you see. However, it's just an example, so don't enter it into the Cloud Shell session.

Verify your VM is running

The az vm create command succeeded, but let's verify that your VM is up and running.
  1. Run the following az vm get-instance-view command to verify that the VM was successfully created and is running.
    Azure CLI
    az vm get-instance-view \
      --name myVM \
      --resource-group Learn-8eb73ca3-d5f2-4ee1-89c5-cdcd999a132a \
      --output table
    
    The output you see resembles this.
    Azure CLI
    Name    ResourceGroup                         Location    ProvisioningState    PowerState
    ------  ------------------------------------  ----------  -------------------  ------------
    myVM    Learn-8eb73ca3-d5f2-4ee1-89c5-cdcd999a132a  eastus      Succeeded            VM running
    
    You see the VM's name, its resource group, and its location. You also see that the VM was provisioned, or created, successfully and that it's running.

Next unit: Exercise - Add a web server