使用门户创建应用程序网关的自定义探测Create a custom probe for Application Gateway by using the portal

本文介绍如何通过 Azure 门户向现有应用程序网关添加自定义运行状况探测。In this article, you add a custom health probe to an existing application gateway through the Azure portal. Azure 应用程序网关使用运行状况探测来监视后端池中资源的运行状况。Using the health probes, Azure Application Gateway monitors the health of the resources in the back-end pool.

准备阶段Before you begin

如果还没有应用程序网关,请访问创建应用程序网关,创建要使用的应用程序网关。If you do not already have an application gateway, visit Create an Application Gateway to create an application gateway to work with.

为应用程序网关 v2 SKU 创建探测Create probe for Application Gateway v2 SKU

可通过门户分两步配置探测。Probes are configured in a two-step process through the portal. 第一个步骤是输入探测配置所需的值。The first step is to enter the values required for the probe configuration. 第二个步骤使用此探测配置测试后端运行状况,然后保存探测。In the second step, you test the backend health using this probe configuration and save the probe.

输入探测属性Enter probe properties

  1. 登录到 Azure 门户Sign in to the Azure portal. 如果还没有帐户,可以注册 1 元试用版If you don't already have an account, you can sign up for a 1rmb-trial

  2. 在 Azure 门户的“收藏夹”窗格中单击“所有资源”。In the Azure portal Favorites pane, click All resources. 在“所有资源”边栏选项卡中单击应用程序网关。Click the application gateway in the All resources blade. 如果所选订阅中已包含多个资源,则可在“按名称筛选…”框中输入“partners.contoso.net”,If the subscription you selected already has several resources in it, you can enter partners.contoso.net in the Filter by name… 轻松访问应用程序网关。box to easily access the application gateway.

  3. 选择“运行状况探测”,然后选择“添加”以添加新的运行状况探测。 Select Health probes and then select Add to add a new health probe.

    添加新探测

  4. 在“添加运行状况探测”页上填写探测的所需信息,并在完成后选择“确定”。 On the Add health probe page, fill out the required information for the probe, and when complete select OK.

    设置Setting Value 详细信息Details
    名称Name customProbecustomProbe 此值是可在门户中访问的探测的易记名称。This value is a friendly name given to the probe that is accessible in the portal.
    协议Protocol HTTP 或 HTTPSHTTP or HTTPS 运行状况探测使用的协议。The protocol that the health probe uses.
    主机Host 例如i.e contoso.comcontoso.com 此值是应用程序服务器上运行的虚拟主机的名称(不同于 VM 主机名)。This value is the name of the virtual host (different from the VM host name) running on the application server. 探测将发送到 <protocol>://<host name>:<port>/<urlPath>The probe is sent to <protocol>://<host name>:<port>/<urlPath>
    从后端 HTTP 设置中选取主机名Pick host name from backend HTTP settings 是或否Yes or No 将探测中的主机头设置为与此探测关联的 HTTP 设置中的主机名。Sets the host header in the probe to the host name from the HTTP settings to which this probe is associated to. 对于 Azure 应用服务等多租户后端,特别需要注意提供正确的值。Specially required in case of multi-tenant backends such as Azure app service. 了解详细信息Learn more
    从后端 HTTP 设置中选取端口Pick port from backend HTTP settings 是或否Yes or No 将运行状况探测的端口设置为与此探测关联的 HTTP 设置中的端口。Sets the port of the health probe to the port from HTTP settings to which this probe is associated to. 如果选择“否”,则可以输入要使用的自定义目标端口If you choose no, you can enter a custom destination port to use
    端口Port 1-655351-65535 用于运行状况探测的自定义端口Custom port to be used for the health probes
    路径Path /或任何有效的路径/ or any valid path 自定义探测的完整 URL 的其余部分。The remainder of the full url for the custom probe. 有效路径以“/”开头。A valid path starts with '/'. 对于默认路径 http://contoso.com,只需使用“/”For the default path of http://contoso.com just use '/'
    间隔(秒)Interval (secs) 3030 运行探测来检查运行状况的频率。How often the probe is run to check for health. 建议不要将时间间隔设置为短于 30 秒。It is not recommended to set the lower than 30 seconds.
    超时(秒)Timeout (secs) 3030 超时之前探测的等待时间。如果在此超时期间内未收到有效响应,则将探测标记为失败。The amount of time the probe waits before timing out. If a valid response is not received within this time-out period, the probe is marked as failed. 超时间隔必须足够长,以便进行 http 调用,确保后端运行状况页可用。The timeout interval needs to be high enough that an http call can be made to ensure the backend health page is available. 请注意,超时值不能大于此探测设置中使用的“间隔”值,或者要与此探测关联的 HTTP 设置中的“请求超时”值。Note that the time-out value should not be more than the ‘Interval’ value used in this probe setting or the ‘Request timeout’ value in the HTTP setting which will be associated with this probe.
    不正常阈值Unhealthy threshold 33 系统认为不正常的连续失败尝试次数。Number of consecutive failed attempts to be considered unhealthy. 阈值可以设置为 1 或更大值。The threshold can be set to 1 or more.
    使用匹配条件的探测Use probe matching conditions 是或否Yes or No 默认情况下,状态代码为 200 到 399 的 HTTP(S) 响应被视为正常。By default, an HTTP(S) response with status code between 200 and 399 is considered healthy. 可以更改后端响应代码或后端响应正文的可接受范围。You can change the acceptable range of backend response code or backend response body. 了解详细信息Learn more
    HTTP 设置HTTP Settings 下拉列表中的选项selection from dropdown 探测将与此处选择的 HTTP 设置相关联,因此,它会监视与所选 HTTP 设置关联的后端池的运行状况。Probe will get associated with the HTTP setting(s) selected here and therefore, will monitor the health of that backend pool which is associated with the selected HTTP setting. 它将对探测请求使用所选 HTTP 设置中所用的同一端口。It will use the same port for the probe request as the one being used in the selected HTTP setting. 只能选择不与任何其他自定义探测关联的 HTTP 设置。You can only choose those HTTP setting(s) which are not associated with any other custom probe.
    请注意,只有这些 HTTP 设置可用于关联,它们的协议与在此探测配置中选择的协议相同,并且采用相同的“从后端 HTTP 设置中选取主机名”开关状态。Note that only those HTTP setting(s) are available for association which have the same protocol as the protocol chosen in this probe configuration and have the same state for the Pick Host Name From Backend HTTP setting switch.

    重要

    仅当探测已关联到一个或多个 HTTP 设置时,它才会监视后端的运行状况。The probe will monitor health of the backend only when it is associated with one or more HTTP Setting(s). 它会监视已关联到与其自身关联的 HTTP 设置的后端池的后端资源。It will monitor back-end resources of those back-end pools which are associated to the HTTP setting(s) to which this probe is associated with. 探测请求将作为 <protocol>://<hostName>:<port>/<urlPath> 发送。The probe request will be sent as <protocol>://<hostName>:<port>/<urlPath>.

使用探测测试后端运行状况Test backend health with the probe

输入探测属性后,可以测试后端资源的运行状况,以验证探测配置是否正确,并且后端资源是否按预期运行。After entering the probe properties, you can test the health of the back-end resources to verify that the probe configuration is correct and that the back-end resources are working as expected.

  1. 选择“测试”并记下探测结果。Select Test and note the result of the probe. 应用程序网关将测试后端池中所有后端资源的运行状况,这些池已关联到用于此探测的 HTTP 设置。The Application gateway tests the health of all the backend resources in the backend pools associated with the HTTP Setting(s) used for this probe.

    测试后端运行状况

  2. 如果存在任何不正常的后端资源,请查看“详细信息”列来了解资源处于不正常状态的原因。If there are any unhealthy backend resources, then check the Details column to understand the reason for unhealthy state of the resource. 如果由于探测配置错误而将资源标记为不正常,请选择“返回探测”链接并编辑探测配置。If the resource has been marked unhealthy due to an incorrect probe configuration, then select the Go back to probe link and edit the probe configuration. 否则,如果由于后端问题而将该资源标记为不正常,请解决后端资源问题,然后依次选择“返回探测”链接、“测试”再次测试后端。 Otherwise, if the resource has been marked unhealthy due to an issue with the backend, then resolve the issues with the backend resource and then test the backend again by selecting the Go back to probe link and select Test.

    备注

    即使后端资源不正常,也可以选择保存探测,但不建议这样做。You can choose to save the probe even with unhealthy backend resources, but it is not recommended. 这是因为,应用程序网关不会将请求转发到后端池中被探测判定为运行不正常的后端服务器。This is because the Application Gateway will not forward requests to the backend servers from the backend pool which are determined to be unhealthy by the probe. 如果后端池中没有任何正常的资源,则无法访问应用程序,并会出现 HTTP 502 错误。In case there are no healthy resources in a backend pool, you will not be able to access your application and will get a HTTP 502 error.

    查看探测结果

  3. 选择“添加”以保存探测。Select Add to save the probe.

为应用程序网关 v1 SKU 创建探测Create probe for Application Gateway v1 SKU

可通过门户分两步配置探测。Probes are configured in a two-step process through the portal. 第一步是创建探测。The first step is to create the probe. 第二步是将探测添加到应用程序网关的后端 http 设置。In the second step, you add the probe to the backend http settings of the application gateway.

创建探测Create the probe

  1. 登录到 Azure 门户Sign in to the Azure portal. 如果还没有帐户,可以注册 1 元试用版If you don't already have an account, you can sign up for a 1rmb-trial

  2. 在 Azure 门户上的“收藏夹”窗格中,选择“所有资源”。In the Azure portal Favorites pane, select All resources. 在“所有资源”页中选择应用程序网关。Select the application gateway in the All resources page. 如果所选订阅中已包含多个资源,则可在“按名称筛选…”框中输入“partners.contoso.net”,If the subscription you selected already has several resources in it, you can enter partners.contoso.net in the Filter by name… 轻松访问应用程序网关。box to easily access the application gateway.

  3. 选择“探测”,然后选择“添加”以添加探测。 Select Probes and then select Add to add a probe.

    添加填写了信息的“探测”边栏选项卡

  4. 在“添加运行状况探测”边栏选项卡上填写探测的所需信息,完成后选择“确定”。 On the Add health probe blade, fill out the required information for the probe, and when complete select OK.

    设置Setting Value 详细信息Details
    名称Name customProbecustomProbe 此值是可在门户中访问的探测的易记名称。This value is a friendly name given to the probe that is accessible in the portal.
    协议Protocol HTTP 或 HTTPSHTTP or HTTPS 运行状况探测使用的协议。The protocol that the health probe uses.
    主机Host 例如i.e contoso.comcontoso.com 此值是应用程序服务器上运行的虚拟主机的名称(不同于 VM 主机名)。This value is the name of the virtual host (different from the VM host name) running on the application server. 探测发送到 (协议)://(主机名):(http 设置中的端口)/urlPath。The probe is sent to (protocol)://(host name):(port from httpsetting)/urlPath. 仅当应用程序网关上配置了多站点时,此项设置才适用。This is applicable when multi-site is configured on Application Gateway. 如果应用程序网关是为单个站点配置的,请输入“127.0.0.1”。If the Application Gateway is configured for a single site, then enter '127.0.0.1'.
    从后端 HTTP 设置中选取主机名Pick host name from backend HTTP settings 是或否Yes or No 将探测中的 host 标头设置为与此探测关联到的 HTTP 设置相关联的后端池中后端资源的主机名。Sets the host header in the probe to the host name of the back-end resource in the back-end pool associated with the HTTP Setting to which this probe is associated to. 对于 Azure 应用服务等多租户后端,特别需要注意提供正确的值。Specially required in case of multi-tenant backends such as Azure app service. 了解详细信息Learn more
    路径Path /或任何有效的路径/ or any valid path 自定义探测的完整 URL 的其余部分。The remainder of the full url for the custom probe. 有效路径以“/”开头。A valid path starts with '/'. 对于默认路径 http://contoso.com,只需使用“/”For the default path of http://contoso.com just use '/'
    间隔(秒)Interval (secs) 3030 运行探测来检查运行状况的频率。How often the probe is run to check for health. 建议不要将时间间隔设置为短于 30 秒。It is not recommended to set the lower than 30 seconds.
    超时(秒)Timeout (secs) 3030 超时之前探测的等待时间。如果在此超时期间内未收到有效响应,则将探测标记为失败。The amount of time the probe waits before timing out. If a valid response is not received within this time-out period, the probe is marked as failed. 超时间隔必须足够长,以便进行 http 调用,确保后端运行状况页可用。The timeout interval needs to be high enough that an http call can be made to ensure the backend health page is available. 请注意,超时值不能大于此探测设置中使用的“间隔”值,或者要与此探测关联的 HTTP 设置中的“请求超时”值。Note that the time-out value should not be more than the ‘Interval’ value used in this probe setting or the ‘Request timeout’ value in the HTTP setting which will be associated with this probe.
    不正常阈值Unhealthy threshold 33 系统认为不正常的连续失败尝试次数。Number of consecutive failed attempts to be considered unhealthy. 阈值可以设置为 1 或更大值。The threshold can be set to 1 or more.
    使用匹配条件的探测Use probe matching conditions 是或否Yes or No 默认情况下,状态代码为 200 到 399 的 HTTP(S) 响应被视为正常。By default, an HTTP(S) response with status code between 200 and 399 is considered healthy. 可以更改后端响应代码或后端响应正文的可接受范围。You can change the acceptable range of backend response code or backend response body. 了解详细信息Learn more

    重要

    主机名不同于服务器名。The host name is not the same as server name. 此值是运行在应用程序服务器上的虚拟主机的名称。This value is the name of the virtual host running on the application server. 探测将发送到 <protocol>://<hostName>:<port from http settings>/<urlPath>The probe is sent to <protocol>://<hostName>:<port from http settings>/<urlPath>

向网关添加探测Add probe to the gateway

创建探测以后,即可将其添加到网关。Now that the probe has been created, it is time to add it to the gateway. 探测设置在应用程序网关的后端 http 设置中设置。Probe settings are set on the backend http settings of the application gateway.

  1. 单机应用程序网关的“HTTP 设置”,然后单击窗口中列出的当前后端 http 设置,以便显示“配置”边栏选项卡。Click HTTP settings on the application gateway, to bring up the configuration blade click the current backend http settings listed in the window.

    https 设置窗口

  2. 在“appGatewayBackEndHttpSettings”设置页上,选中“使用自定义探测”复选框,然后在“自定义探测”下拉列表中选择在创建探测部分创建的探测。 On the appGatewayBackEndHttpSettings settings page, check the Use custom probe checkbox and choose the probe created in the Create the probe section on the Custom probe drop-down. 完成后,单击“保存”即可应用相关设置。When complete, click Save and the settings are applied.

后续步骤Next steps

使用后端运行状况视图查看探测确定的后端资源运行状况。View the health of the backend resources as determined by the probe using the backend health view.