Een aangepaste test maken voor Azure-toepassing Gateway met behulp van PowerShell voor Azure Resource Manager

In dit artikel voegt u een aangepaste test toe aan een bestaande toepassingsgateway met PowerShell. Aangepaste tests zijn handig voor toepassingen met een specifieke statuscontrolepagina of voor toepassingen die geen geslaagde reactie bieden op de standaardwebtoepassing.

Notitie

Het wordt aanbevolen de Azure Az PowerShell-module te gebruiken om te communiceren met Azure. Zie Azure PowerShell installeren om aan de slag te gaan. Raadpleeg Azure PowerShell migreren van AzureRM naar Az om te leren hoe u naar de Azure PowerShell-module migreert.

Voorwaarde: installeer de Azure PowerShell-module

Als u de stappen in dit artikel wilt uitvoeren, moet u de Azure PowerShell-module installeren en configureren. Voltooi alle instructies. Nadat de installatie is voltooid, meldt u zich aan bij Azure en selecteert u uw abonnement.

Notitie

U hebt een Azure-account nodig om deze stappen uit te voeren. Als u nog geen Azure-account hebt, kunt u zich registreren voor een gratis proefversie.

Een toepassingsgateway maken met een aangepaste test

Aanmelden en resourcegroep maken

  1. Gebruik Connect-AzAccount dit om te verifiëren.

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

    Get-AzSubscription
    
  3. Kies welk Azure-abonnement u wilt gebruiken.

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

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

Azure Resource Manager vereist dat er voor alle resourcegroepen een locatie wordt opgegeven. Deze locatie wordt gebruikt als de standaardlocatie voor resources in die resourcegroep. Zorg ervoor dat alle opdrachten voor het maken van een toepassingsgateway dezelfde resourcegroep gebruiken.

In het voorgaande voorbeeld hebben we een resourcegroep gemaakt met de naam appgw-RG op locatie VS - west.

Een virtueel netwerk en een subnet maken

In het volgende voorbeeld worden een virtueel netwerk en een subnet voor de toepassingsgateway gemaakt. Toepassingsgateway vereist een eigen subnet voor gebruik. Daarom moet het subnet dat is gemaakt voor de toepassingsgateway kleiner zijn dan de adresruimte van het VNET, zodat andere subnetten kunnen worden gemaakt en gebruikt.

# 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 de openbare IP-resource publicIP01 in de resourcegroep appgw-rg voor de regio VS - west. In dit voorbeeld wordt een openbaar IP-adres gebruikt voor het front-end-IP-adres van de toepassingsgateway. Voor de toepassingsgateway moet het openbare IP-adres een dynamisch gemaakte DNS-naam hebben. Daarom kan het -DomainNameLabel niet worden opgegeven tijdens het maken van het openbare IP-adres.

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

Een toepassingsgateway maken

U stelt alle configuratie-items in voordat u de toepassingsgateway maakt. In het volgende voorbeeld worden de configuratie-items gemaakt die nodig zijn voor een toepassingsgatewayresource.

Onderdeel Beschrijving
IP-configuratie van gateway Een IP-configuratie voor een toepassingsgateway.
Back-endpool Een groep IP-adressen, FQDN's of NIC's die betrekking hebben op de toepassingsservers die de webtoepassing hosten
Statustest Een aangepaste test die wordt gebruikt om de status van de leden van de back-endpool te controleren
HTTP-instellingen Een verzameling instellingen, waaronder poort, protocol, affiniteit op basis van cookies, tests en time-outs. Deze instellingen bepalen hoe verkeer wordt gerouteerd naar de leden van de back-endpool
Front-endpoort De poort waarop de toepassingsgateway luistert naar verkeer op
Listener Een combinatie van een protocol, front-end-IP-configuratie en front-endpoort. Dit is wat luistert naar binnenkomende aanvragen.
Regel Routeert het verkeer naar de juiste back-end 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 120 -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 previous defined http settings and backend address pool.  It also associates the listener to the rule
$rule = New-AzApplicationGatewayRequestRoutingRule -Name rule01 -RuleType Basic -BackendHttpSettings $poolSetting -HttpListener $listener -BackendAddressPool $pool

# Sets the SKU of the application gateway, in this example we create a small standard application gateway with 2 instances.
$sku = New-AzApplicationGatewaySku -Name Standard_Small -Tier Standard -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

Met het volgende codefragment wordt een test toegevoegd aan een bestaande toepassingsgateway.

# 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 120 -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

Met het volgende codefragment wordt een test verwijderd uit een bestaande toepassingsgateway.

# 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

DNS-naam van toepassingsgateway verkrijgen

Wanneer de gateway is gemaakt, gaat u in de volgende stap de front-end voor communicatie configureren. Wanneer u een openbaar IP-adres gebruikt, vereist de toepassingsgateway een dynamisch toegewezen DNS-naam, wat niet vriendelijk is. Opdat eindgebruikers de toepassingsgateway kunnen bereiken, kan een CNAME-record worden gebruikt om te wijzen naar het openbare eindpunt van de toepassingsgateway. Een aangepaste domeinnaam configureren voor in Azure. Daartoe haalt u details van de toepassingsgateway en de bijbehorende IP-/ DNS-naam op met het PublicIPAddress-element gekoppeld aan de toepassingsgateway. De DNS-naam van de toepassingsgateway moet worden gebruikt om een CNAME-record te maken die de twee webtoepassingen naar deze DNS-naam wijst. Het gebruik van A-records wordt niet aanbevolen, omdat het VIP kan veranderen wanneer de toepassingsgateway opnieuw wordt gestart.

Get-AzPublicIpAddress -ResourceGroupName appgw-RG -Name publicIP01
Name                     : publicIP01
ResourceGroupName        : appgw-RG
Location                 : westus
Id                       : /subscriptions/<subscription_id>/resourceGroups/appgw-RG/providers/Microsoft.Network/publicIPAddresses/publicIP01
Etag                     : W/"00000d5b-54ed-4907-bae8-99bd5766d0e5"
ResourceGuid             : 00000000-0000-0000-0000-000000000000
ProvisioningState        : Succeeded
Tags                     : 
PublicIpAllocationMethod : Dynamic
IpAddress                : xx.xx.xxx.xx
PublicIpAddressVersion   : IPv4
IdleTimeoutInMinutes     : 4
IpConfiguration          : {
                                "Id": "/subscriptions/<subscription_id>/resourceGroups/appgw-RG/providers/Microsoft.Network/applicationGateways/appgwtest/frontendIP
                            Configurations/frontend1"
                            }
DnsSettings              : {
                                "Fqdn": "00000000-0000-xxxx-xxxx-xxxxxxxxxxxx.cloudapp.net"
                            }

Volgende stappen

Meer informatie over het configureren van TLS-offloading door naar: TLS-offload configureren