Creating the backend servers

Finally, for the backend, we are going to create two VMs that are going to be used as backend servers for the application gateway. We are also going to deploy IIS and a web page to it for testing purposes. During execution, you will be prompted to provide a username and password for the VMs. Take the following steps:

  1. Set the credentials and the VM settings, as follows:
$vnet = Get-AzVirtualNetwork -ResourceGroupName PacktApplicationGateway -Name PacktVNet
$cred = Get-Credential
for ($i=1; $i -le 2; $i++)
{
# Create a virtual machine
$nic = New-AzNetworkInterface `
-Name PacktNic$i `
-ResourceGroupName PacktApplicationGateway ` -Location eastus `
-SubnetId $vnet.Subnets[1].Id
$vm = New-AzVMConfig `
-VMName PacktVM$i `
-VMSize Standard_D2
$vm = Set-AzVMOperatingSystem `
-VM $vm `
-Windows `
-ComputerName PAcktVM$i `
-Credential $cred `
-ProvisionVMAgent
$vm = Set-AzVMSourceImage `
-VM $vm `
-PublisherName MicrosoftWindowsServer `
-Offer WindowsServer `
-Skus 2016-Datacenter `
-Version latest
$vm = Add-AzVMNetworkInterface `
-VM $vm `
-Id $nic.Id
$vm = Set-AzVMBootDiagnostic `
-VM $vm `
-Disable
  1. Create the VMs and install IIS on the VMs, as follows:
New-AzVM -ResourceGroupName PacktApplicationGateway -Location eastus -VM $vm 
Set-AzVMExtension `
-ResourceGroupName PacktApplicationGateway `
-ExtensionName IIS `
-VMName PacktVM$i `
-Publisher Microsoft.Compute `
-ExtensionType CustomScriptExtension `
-TypeHandlerVersion 1.4 `
-SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path "C:\inetpub\wwwroot\Default.htm" -Value $($env:computername)"}' `
-Location EastUS
}

In the next section, we will look at IP configurations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset