Maak een aangepaste probe voor Azure Application Gateway door PowerShell te gebruiken voor Azure Resource Manager

In dit artikel voeg je een aangepaste probe toe aan een bestaande applicatiegateway met PowerShell. Aangepaste probes zijn nuttig voor applicaties met een specifieke health check-pagina of voor applicaties die geen succesvol antwoord geven op de standaard webapplicatie.

Note

We raden u aan om de Azure Az PowerShell-module te gebruiken om met Azure te communiceren. Zie Azure PowerShell installeren om aan de slag te gaan. Om te leren hoe u naar de Az PowerShell-module kunt migreren, zie Migrate Azure PowerShell from AzureRM to Az.

Prerequisite: Install the Azure PowerShell module

Om de stappen in dit artikel uit te voeren, moet je de Azure PowerShell-module installeren en configureren. Zorg ervoor dat je alle instructies invult. Na voltooiing van de installatie log je in bij Azure en selecteer je je abonnement.

Note

Je hebt een Azure-account nodig om deze stappen te voltooien. Als u geen Azure-account hebt, kunt u er gratis een maken.

Maak een applicatiegateway aan met een aangepaste probe

Log in en maak een resourcegroep aan

  1. Gebruik Connect-AzAccount het om te authenticeren.

    Connect-AzAccount
    
  2. Haal de abonnementen voor het account.

    Get-AzSubscription
    
  3. Kies welke van je Azure-abonnementen je gebruikt.

    Select-AzSubscription -Subscriptionid '{subscriptionGuid}'
    
  4. Maak een resourcegroep. Je kunt deze stap overslaan als je een bestaande resourcegroep hebt.

    New-AzResourceGroup -Name appgw-rg -Location 'West US'
    

Azure Resource Manager vereist dat alle resourcegroepen een locatie specificeren. Deze locatie bepaalt waar Azure de metadata van de resourcegroep opslaat. Zorg ervoor dat alle opdrachten voor het maken van een toepassingsgateway dezelfde resourcegroep gebruiken.

In het voorgaande voorbeeld hebben we een resourcegroep aangemaakt genaamd appgw-RG op locatie West US.

Creëer een virtueel netwerk en een subnet

Het volgende voorbeeld creëert een virtueel netwerk en een subnet voor de applicatiegateway. De applicatiegateway vereist een eigen subnet voor gebruik. Om deze reden zou het subnet dat voor de applicatiegateway wordt aangemaakt kleiner moeten zijn dan de adresruimte van de VNET om andere subnetten te kunnen aanmaken en gebruiken.

# Assign the address range 10.0.0.0/24 to a subnet variable to be used to create a virtual network.
$subnet = New-AzVirtualNetworkSubnetConfig -Name subnet01 -AddressPrefix 10.0.0.0/24

# Create a virtual network named appgwvnet in resource group appgw-rg for the West US region using the prefix 10.0.0.0/16 with subnet 10.0.0.0/24.
$vnet = New-AzVirtualNetwork -Name appgwvnet -ResourceGroupName appgw-rg -Location 'West US' -AddressPrefix 10.0.0.0/16 -Subnet $subnet

# Assign a subnet variable for the next steps, which create an application gateway.
$subnet = $vnet.Subnets[0]

Een openbaar IP-adres maken voor de front-endconfiguratie

Maak een standaard SKU statische publieke IP-bron genaamd publicIP01 aan in resource group appgw-rg voor de regio West-VS. Application Gateway v2 ondersteunt alleen standaard SKU statische publieke IP-adressen.

$publicip = New-AzPublicIpAddress -ResourceGroupName appgw-rg -Name publicIP01 -Location 'West US' -AllocationMethod Static -Sku Standard

Een toepassingsgateway maken

Je stelt alle configuratie-items in voordat je de applicatiegateway aanmaakt. Het volgende voorbeeld creëert de configuratie-items die nodig zijn voor een applicatiegateway-resource.

Component Description
Gateway IP-configuratie Een IP-configuratie voor een applicatiegateway.
Backendpool Een pool van IP-adressen, FQDN's of NIC's die naar de applicatieservers zijn die de webapplicatie hosten
Gezondheidsonderzoek Een aangepaste probe die wordt gebruikt om de gezondheid van de backend-poolleden te monitoren
HTTP-instellingen Een verzameling instellingen, waaronder port, protocol, cookie-gebaseerde affiniteit, probe en timeout. Deze instellingen bepalen hoe het verkeer wordt gerouteerd naar de leden van de backend pool
Frontend-port De poort waarop de applicatiegateway naar verkeer luistert
Listener Een combinatie van een protocol, frontend IP-configuratie en frontendpoort. Dit is wat luistert naar binnenkomende verzoeken.
Rule Routeert het verkeer naar de juiste backend op basis van HTTP-instellingen.
# Creates an application gateway Frontend IP configuration named gatewayIP01
$gipconfig = New-AzApplicationGatewayIPConfiguration -Name gatewayIP01 -Subnet $subnet

#Creates a backend IP address pool named pool01 with IP addresses 134.170.185.46, 134.170.188.221, 134.170.185.50.
$pool = New-AzApplicationGatewayBackendAddressPool -Name pool01 -BackendIPAddresses 134.170.185.46, 134.170.188.221, 134.170.185.50

# Creates a probe that will check health at http://contoso.com/path/path.htm
$probe = New-AzApplicationGatewayProbeConfig -Name probe01 -Protocol Http -HostName 'contoso.com' -Path '/path/path.htm' -Interval 30 -Timeout 30 -UnhealthyThreshold 8

# Creates the backend http settings to be used. This component references the $probe created in the previous command.
$poolSetting = New-AzApplicationGatewayBackendHttpSettings -Name poolsetting01 -Port 80 -Protocol Http -CookieBasedAffinity Disabled -Probe $probe -RequestTimeout 80

# Creates a frontend port for the application gateway to listen on port 80 that will be used by the listener.
$fp = New-AzApplicationGatewayFrontendPort -Name frontendport01 -Port 80

# Creates a frontend IP configuration. This associates the $publicip variable defined previously with the frontend IP that will be used by the listener.
$fipconfig = New-AzApplicationGatewayFrontendIPConfig -Name fipconfig01 -PublicIPAddress $publicip

# Creates the listener. The listener is a combination of protocol and the frontend IP configuration $fipconfig and frontend port $fp created in previous steps.
$listener = New-AzApplicationGatewayHttpListener -Name listener01  -Protocol Http -FrontendIPConfiguration $fipconfig -FrontendPort $fp

# Creates the rule that routes traffic to the backend pools. In this example, we create a basic rule that uses the previously defined HTTP settings and backend address pool. It also associates the listener with the rule.
$rule = New-AzApplicationGatewayRequestRoutingRule -Name rule01 -RuleType Basic -BackendHttpSettings $poolSetting -HttpListener $listener -BackendAddressPool $pool -Priority 1

# Sets the SKU of the application gateway. In this example, we create a Standard v2 application gateway with two instances.
$sku = New-AzApplicationGatewaySku -Name Standard_v2 -Tier Standard_v2 -Capacity 2

# The final step creates the application gateway with all the previously defined components.
$appgw = New-AzApplicationGateway -Name appgwtest -ResourceGroupName appgw-rg -Location 'West US' -BackendAddressPools $pool -Probes $probe -BackendHttpSettingsCollection $poolSetting -FrontendIpConfigurations $fipconfig  -GatewayIpConfigurations $gipconfig -FrontendPorts $fp -HttpListeners $listener -RequestRoutingRules $rule -Sku $sku

Een test toevoegen aan een bestaande toepassingsgateway

Het volgende codefragment voegt een probe toe aan een bestaande applicatiegateway.

# Load the application gateway resource into a PowerShell variable by using Get-AzApplicationGateway.
$getgw =  Get-AzApplicationGateway -Name appgwtest -ResourceGroupName appgw-rg

# Create the probe object that will check health at http://contoso.com/path/path.htm
$probe = Add-AzApplicationGatewayProbeConfig -ApplicationGateway $getgw -Name probe01 -Protocol Http -HostName 'contoso.com' -Path '/path/custompath.htm' -Interval 30 -Timeout 30 -UnhealthyThreshold 8

# Set the backend HTTP settings to use the new probe
$getgw = Set-AzApplicationGatewayBackendHttpSettings -ApplicationGateway $getgw -Name $getgw.BackendHttpSettingsCollection.name -Port 80 -Protocol Http -CookieBasedAffinity Disabled -Probe $probe -RequestTimeout 120

# Save the application gateway with the configuration changes
Set-AzApplicationGateway -ApplicationGateway $getgw

Een test verwijderen uit een bestaande toepassingsgateway

Het volgende codefragment verwijdert een probe van een bestaande applicatiegateway.

# Load the application gateway resource into a PowerShell variable by using Get-AzApplicationGateway.
$getgw =  Get-AzApplicationGateway -Name appgwtest -ResourceGroupName appgw-rg

# Remove the probe from the application gateway configuration object
$getgw = Remove-AzApplicationGatewayProbeConfig -ApplicationGateway $getgw -Name $getgw.Probes.name

# Set the backend HTTP settings to remove the reference to the probe. The backend http settings now use the default probe
$getgw = Set-AzApplicationGatewayBackendHttpSettings -ApplicationGateway $getgw -Name $getgw.BackendHttpSettingsCollection.name -Port 80 -Protocol http -CookieBasedAffinity Disabled

# Save the application gateway with the configuration changes
Set-AzApplicationGateway -ApplicationGateway $getgw

Haal het publieke IP-adres van de applicatiegateway op

Nadat je de gateway hebt aangemaakt, haal je het statische publieke IP-adres op. Om een aangepast domein te gebruiken, maak je een A-record aan dat het domein aan dit adres koppelt. Voor meer informatie, zie Map a custom domain to a Azure resource.

$publicip = Get-AzPublicIpAddress -ResourceGroupName appgw-rg -Name publicIP01
$publicip.IpAddress

Volgende stappen 

Leer TLS-offloading configureren door te bezoeken: Configureer TLS Offload