この記事では、PowerShell を使用して既存の Application Gateway にカスタム プローブを追加します。 カスタム プローブは、特定の正常性チェック ページがあるアプリケーションや、既定の Web アプリケーションに対して正常な応答を返さないアプリケーションに役立ちます。
注意
Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を始めるには、「Azure PowerShell をインストールする」を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。
前提条件: Azure PowerShell モジュールのインストール
この記事の手順を実行するには、Azure PowerShell モジュールをインストールして構成する必要があります。 必ず、すべての手順を完了してください。 インストールが完了したら、Azure にサインインし、サブスクリプションを選択します。
注意
これらの手順を完了するには Azure アカウントが必要です。 Azure アカウントがない場合は、無料で作成できます。
カスタム プローブを設定した Application Gateway の作成
サインインし、リソース グループを作成する
Connect-AzAccountを使用して認証を行います。Connect-AzAccountアカウントのサブスクリプションを取得します。
Get-AzSubscription使用する Azure サブスクリプションを選択します。
Select-AzSubscription -Subscriptionid '{subscriptionGuid}'リソース グループを作成する。 既存のリソース グループがある場合は、この手順をスキップしてください。
New-AzResourceGroup -Name appgw-rg -Location 'West US'
Azure リソース マネージャーでは、すべてのリソース グループの場所を指定する必要があります。 この場所がAzureがリソースグループのメタデータをどこに保存するかを決定します。 アプリケーション ゲートウェイを作成するためのすべてのコマンドで、同じリソース グループが使用されていることを確認します。
前の例では、West US という名前の場所に appgw-RG という名前のリソース グループを作成しました。
仮想ネットワークとサブネットの作成
次の例では、Application Gateway の仮想ネットワークとサブネットを作成します。 Azure Application Gateway には、専用のサブネットが必要です。 このため、Application Gateway 用に作成するサブネットは、他のサブネットを作成して使用できるように、VNET のアドアレス空間よりも小さくする必要があります。
# 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]
フロントエンド構成のパブリック IP アドレスを作成する
西米リージョン用に、リソースグループappgw-rgでpublicIP01という標準SKUの静的パブリックIPリソースを作成します。 Application Gateway v2は標準SKUの静的パブリックIPアドレスのみをサポートします。
$publicip = New-AzPublicIpAddress -ResourceGroupName appgw-rg -Name publicIP01 -Location 'West US' -AllocationMethod Static -Sku Standard
アプリケーション ゲートウェイの作成
アプリケーション ゲートウェイを作成する前に、すべての構成項目を設定します。 次の例では、Application Gateway のリソースに必要な構成項目を作成します。
| コンポーネント | 説明 |
|---|---|
| ゲートウェイ IP の構成 | Application Gateway の IP 構成。 |
| バックエンド プール | Web アプリケーションをホストするアプリケーション サーバーに対する IP アドレス、FQDN、または NIC のプール。 |
| 正常性プローブ | バックエンド プール メンバーの正常性の監視に使用されるカスタム プローブ。 |
| HTTP 設定 | ポート、プロトコル、cookie ベースのアフィニティ、プローブ、タイムアウトなど設定のコレクション。 これらの設定によって、バックエンド プール メンバーへのトラフィックのルーティング方法が決まります。 |
| フロントエンド ポート | Application Gateway がトラフィックをリッスンするポート |
| リスナー | プロトコル、フロントエンド IP 構成、およびフロントエンド ポートの組み合わせ。 これが受信要求をリッスンします。 |
| Rule | HTTP 設定に基づいてトラフィックを適切なバックエンドにルーティングします。 |
# 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
既存のアプリケーション ゲートウェイへのプローブの追加
次のコード スニペットは、既存の Application Gateway にプローブを追加します。
# 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
既存のアプリケーション ゲートウェイからのプローブの削除
次のコード スニペットは、既存の Application Gateway からプローブを削除します。
# 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
アプリケーションゲートウェイのパブリックIPアドレスを取得してください
ゲートウェイを作成したら、その静的パブリックIPアドレスを取得してください。 カスタムドメインを使用するには、ドメインをこのアドレスにマッピングするAレコードを作成します。 詳細については、「カスタムドメインをAzureリソースにマッピングする」をご覧ください。
$publicip = Get-AzPublicIpAddress -ResourceGroupName appgw-rg -Name publicIP01
$publicip.IpAddress
次のステップ
TLS オフロードの構成については、SSL オフロードの構成に関する記事を参照してください