Search This Blog

2020-09-16

LAB 08 : Azure VM

 Step 1 : Create VM

SettingValue
Subscriptionthe name of the Azure subscription you will be using in this lab
Resource groupthe name of a new resource group az104-08-rg01
Virtual machine nameaz104-08-vm0
Regionselect one of the regions that support availability zones and where you can provision Azure virtual machines
Availability optionsAvailability zone
Availability zone1
ImageWindows Server 2019 Datacenter - Gen1
Azure Spot instanceNo
SizeStandard D2s v3
UsernameStudent
PasswordPa55w.rd1234
Public inbound portsNone
Already have a Windows Server licenseNo


SettingValue
OS disk typeStandard HDD
Enable Ultra Disk compatibilityNo

SettingValue
Nameaz104-08-rg01-vnet
Address range10.80.0.0/20
Subnet namesubnet0
Subnet range10.80.0.0/24
SettingValue
Public IPNone
NIC network security groupNone
Accelerated networkingOff
Place this virtual machine behind an existing load balancing solution?No
SettingValue
Boot diagnosticsEnable with custom storage account
Diagnostics storage accountCreate new
Create storage accountEnter a globally unique name all in lower case > Click OK



Step 2 : On the deployment blade, click TemplateReview the template representing the deployment in progress and click DeployOn the Custom deployment blade, specify the following settings 

SettingValue
Resource groupaz104-08-rg01
Network Interface Nameaz104-08-vm1-nic1
Virtual Machine Nameaz104-08-vm1
Virtual Machine Computer Nameaz104-08-vm1
Admin UsernameStudent
Admin PasswordPa55w.rd1234
Zone2






Step 3: Configure Azure virtual machines by using virtual machine extensions

We will install Windows Server Web Server role on the two Azure virtual machines you deployed in the previous task by using the Custom Script virtual machine extension.


In the Azure portal, search for and select Storage accounts and, on the Storage accounts blade, click the entry representing the diagnostics storage account you created in the previous task.
On the storage account blade, click Containers and then click + Container.

SettingValue
Namescripts
Public access levelPrivate (no anonymous access)








Upload file from https://github.com/MicrosoftLearning/AZ-104-MicrosoftAzureAdministrator/tree/master/Allfiles/Labs/08/az104-08-install_IIS.ps1





In the Azure portal, search for and select Virtual machines and, on the Virtual machines blade, click az104-08-vm0. On the az104-08-vm0 virtual machine blade, in the Settings section, click Extensions, and the click + Add.  On the New resource blade, click Custom Script Extension and then click Create.


On the Storage accounts blade, click the name of the storage account into which you uploaded the az104-08-install_IIS.ps1 script, on the Containers blade, click scripts, on the scripts blade, click az104-08-install_IIS.ps1, and then click Select.



The below section of the template defines the same Azure virtual machine custom script extension into VM1 that you deployed earlier to the first virtual machine via Azure PowerShell.

On the az104-08-vm1 blade, in the Settings section, click Export templateOn the az104-08-vm1 - Export template blade, click DeployOn the Custom deployment blade, click Edit templateOn the Edit template blade, in the section displaying the content of the template, insert the following code

 {
         "type": "Microsoft.Compute/virtualMachines/extensions",
         "name": "az104-08-vm1/customScriptExtension",
         "apiVersion": "2018-06-01",
         "location": "[resourceGroup().location]",
         "dependsOn": [
             "az104-08-vm1"
         ],
         "properties": {
             "publisher": "Microsoft.Compute",
             "type": "CustomScriptExtension",
             "typeHandlerVersion": "1.7",
             "autoUpgradeMinorVersion": true,
             "settings": {
                 "commandToExecute": "powershell.exe Install-WindowsFeature -name Web-Server -IncludeManagementTools && powershell.exe remove-item 'C:\\inetpub\\wwwroot\\iisstart.htm' && powershell.exe Add-Content -Path 'C:\\inetpub\\wwwroot\\iisstart.htm' -Value $('Hello World from ' + $env:computername)"
           }
         }
     },  



On the Run Command Script blade, type the following and click Run to access the web site hosted on az104-08-vm0:
You can also connect to az104-08-vm0 and run Invoke-WebRequest -URI http://10.80.0.5 to access the web site hosted on az104-08-vm1.

Step 3 : Scale compute and storage for Azure virtual machines

We will scale compute for Azure virtual machines by changing their size and scale their storage by attaching and configuring their data disks.

On the az104-08-vm0 virtual machine blade, click Size and set the virtual machine size to Standard DS1_v2 and click Resize



On the az104-08-vm0 virtual machine blade, click Disks, Under Data disks click + Create and attach a new disk.

SettingValue
Disk nameaz104-08-vm0-datadisk-0
Source typeNone
Account typePremium SSD
Size1024 GiB
SettingValue
Disk nameaz104-08-vm0-datadisk-1
Source typeNone
Account typePremium SSD
Size1024 GiB
On the Run Command Script blade, type the following and click Run to create a drive Z: consisting of the two newly attached disks with the simple layout and fixed provisioning:
New-StoragePool -FriendlyName storagepool1 -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks (Get-PhysicalDisk -CanPool $true)

New-VirtualDisk -StoragePoolFriendlyName storagepool1 -FriendlyName virtualdisk1 -Size 2046GB -ResiliencySettingName Simple -ProvisioningType Fixed

Initialize-Disk -VirtualDisk (Get-VirtualDisk -FriendlyName virtualdisk1)

New-Partition -DiskNumber 4 -UseMaximumSize -DriveLetter Z

Also it can be resized in the following process
On the az104-08-vm1 - Export template blade, click DeployOn the Custom deployment blade, click Edit templateOn the Edit template blade, in the section displaying the content of the template, replace the line 30 "vmSize": "Standard_D2s_v3" with the following line):
  "vmSize": "Standard_DS1_v2"

On the Edit template blade, in the section displaying the content of the template, replace line 49 ( "dataDisks": [ ] line) with the following code :

 "dataDisks": [
                   {
                     "lun": 0,
                     "name": "az104-08-vm1-datadisk0",
                     "diskSizeGB": "1024",
                     "caching": "ReadOnly",
                     "createOption": "Empty"
                   },
                   {
                     "lun": 1,
                     "name": "az104-08-vm1-datadisk1",
                     "diskSizeGB": "1024",
                     "caching": "ReadOnly",
                     "createOption": "Empty"
                   }
                 ]

Also we can deploy zone-resilient Azure virtual machine scale sets by using the Azure portal

virtual machine scale set allows you to deploy and manage a set of auto-scaling virtual machines. You can scale the number of VMs in the scale set manually, or define rules to autoscale based on resource usage like CPU, memory demand, or network traffic.

SettingValue
Subscriptionthe name of the Azure subscription you are using in this lab
Resource groupthe name of a new resource group az104-08-rg02
Virtual machine scale set nameaz10408vmss0
Regionselect one of the regions that support availability zones and where you can provision Azure virtual machines different from the one you used to deploy virtual machines earlier in this lab
Availability zoneZones 1, 2, 3
ImageWindows Server 2016 Datacenter
Azure Spot instanceNo
SizeStandard D2s_v3
UsernameStudent
PasswordPa55w.rd1234
Already have a Windows Server license?No

Scale compute and storage for Azure virtual machine scale sets


On the az10408vmss0 - Scaling blade, select the Custom autoscale option and configure autoscale with the following settings (leave others with their default values):

SettingValue
Scale modeScale based on a metric    

Click the + Add a rule link and, on the Scale rule blade, specify the following settings (leave others with their default values):

SettingValue
Metric sourceCurrent resource (az10480vmss0)
Time aggregationAverage
Metric namespaceVirtual Machine Host
Metric nameNetwork In Total
OperatorGreater than
Metric threshold to trigger scale action10
Duration (in minutes)1
Time grain statisticAverage
OperationIncrease count by
Instance count1
Cool down (minutes)5
Click Add and, back on the az10408vmss0 - Scaling blade, specify the following settings (leave others with their default values):
  1. SettingValue
    Instance limits Minimum1
    Instance limits Maximum3
    Instance limits Default1
    Command for clean up : Get-AzResourceGroup -Name 'az104-08*' | Remove-AzResourceGroup -Force -AsJob

No comments: