A monitor issues health monitor requests at regular intervals to evaluate the health of each endpoint within a pool.
When a pool becomes unhealthy, your load balancer takes that pool out of the endpoint rotation.
有关监视器的更多详情,请参阅监视器。
当健康检查超时时,Cloudflare 会立即发送重试——不会等待下一个间隔。retries 设置定义初始检查后的额外尝试次数。例如,使用五次重试:
- 总尝试次数:1(初始)+ 5(重试)= 6
- 超时 20 秒时:Cloudflare 在大约 120 秒(6 × 20 秒)后将端点标记为不健康
- 配置的间隔(例如 60 秒)仅适用于成功的探测周期之间,不适用于重试之间
设置监视器
您可以在负载均衡器工作流中或 Monitors(监视器) 选项卡内创建 monitor:
-
前往 Load Balancing(负载均衡)。
-
选择 Monitors(监视器) 选项卡。
-
选择 Create monitor(创建监视器)。
添加以下信息:
- Type(类型):健康 monitor 使用的协议
- 非 Enterprise 客户:选择 HTTP、HTTPS 或 TCP。
- Enterprise 客户:选择 HTTP、HTTPS、TCP、UDP ICMP、ICMP Ping 或 SMTP。
- Path(路径):运行健康 monitor 请求的 endpoint 路径
- Port(端口):健康 monitor 的目标端口
- Type(类型):健康 monitor 使用的协议
对于其他设置,选择 Advanced health monitor settings(高级运行状况监视器设置):
- Interval(时间间隔):
- 增加默认值可以缩短故障转移时间,但也可能增加 endpoint 负载。
- 最短间隔(秒)为 60(Pro)、15(Business)和 10(Enterprise)。
- Timeout(超时) 和 Retries(重试):
- 如果健康 monitor 请求超过 Timeout(超时) 指定的时长(且超过 Retries(重试) 指定的次数),将返回不健康。
- Expected Code(s)(预期状态码):预期的 HTTP 响应码,可单独列出(
200、302)或作为范围(例如,输入2xx将涵盖200范围内的所有响应码)。 - Response Body(响应正文):
- 在响应正文中查找不区分大小写的子字符串。
- 确保该值相对静态,且位于 HTML 页面前 10 KB 内。
- Simulate Zone(模拟区域):
- 建议使用负载均衡器所在的同一 zone。
- 更改健康 monitor 请求的出站 zone 设置,以确保与 Authenticated Origin Pulls (mTLS)、Argo Smart Routing、Bring your own CA (mTLS)、Dedicated CDN Egress IPs 和 HTTP/2 to Origin 等功能兼容。
- Follow Redirects(跟随重定向):
- 健康 monitor 请求会跟随重定向到最终 endpoint,而不是将
301或302码报告为不健康。
- 健康 monitor 请求会跟随重定向到最终 endpoint,而不是将
- Configure Request Header(s)(配置请求标头):
- 如果您的 endpoint 期望特定的传入标头,此选项很有用。
- Header(标头):
- 健康 monitor 中发送的 HTTP 请求标头。建议默认设置 Host 标头。User-Agent 标头无法覆盖。此参数仅对 HTTP 和 HTTPS monitor 有效。
- Interval(时间间隔):
-
选择 Save(保存)。
准备您的服务器
确保防火墙或 Web 服务器不会阻止或限速您配置的健康 monitor,或与 Cloudflare IP 地址 ↗ 关联的请求。
每个健康 monitor 的 HTTP user-agent 为 "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/; pool-id: $poolid)",其中 $poolid 是关联 pool 的前 16 个字符。
将监视器附加到池
创建监视器后,需要将其附加到池:
-
前往 Load Balancing(负载均衡)。
-
选择 Pools(池) 选项卡。
-
在特定池上,选择 Edit(编辑)。
-
更新以下信息:
- Monitor(监视器):选择您的监视器。
- Health Monitor Regions(健康监视器区域): 指定 Cloudflare 应从哪些地理区域发送健康监视器请求。由于监视器如何检查池健康状态,选择多个区域可能会增加服务器的负载。
- Notification E-mail(通知电子邮件): 包含接收通知的电子邮件地址(个人、邮件列表地址、PagerDuty 地址)。
-
选择 Save(保存)。健康监视器的状态在首次检查结果可用之前将为 unknown(未知)。
设置监视器
有关 monitor 属性的完整列表,请参阅 Create Monitor。如需 API 身份验证帮助,请参阅 Cloudflare API 文档。
Required API token permissions
At least one of the following token permissions is required:Load Balancing: Monitors and Pools Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/load_balancers/monitors" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"type": "https",
"description": "Login page monitor",
"method": "GET",
"path": "/health",
"header": {
"Host": [
"example.com"
],
"X-App-ID": [
"abc123"
]
},
"port": 8080,
"timeout": 3,
"retries": 0,
"interval": 90,
"expected_body": "alive",
"expected_codes": "2xx",
"follow_redirects": true,
"allow_insecure": true,
"consecutive_up": 3,
"consecutive_down": 2,
"probe_zone": "example.com"
}'响应包含新 monitor 的完整定义。
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": ":monitor-id",
"created_on": "2021-01-01T05:20:00.12345Z",
"modified_on": "2021-01-01T05:20:00.12345Z",
"type": "https",
"description": "Login page monitor",
"method": "GET",
"path": "/health",
"header": {
"Host": [
"example.com"
],
"X-App-ID": [
"abc123"
]
},
"port": 8080,
"timeout": 3,
"retries": 0,
"interval": 90,
"expected_body": "alive",
"expected_codes": "2xx",
"follow_redirects": true,
"allow_insecure": true,
"consecutive_up": 3,
"consecutive_down": 2,
"probe_zone": "example.com"
}
}准备您的服务器
确保防火墙或 Web 服务器不会阻止或限速您配置的健康 monitor,或与 Cloudflare IP 地址 ↗ 关联的请求。
每个健康 monitor 的 HTTP user-agent 为 "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/; pool-id: $poolid)",其中 $poolid 是关联 pool 的前 16 个字符。
将监视器附加到池
创建监视器后,保存其 id 属性。创建池 时,在 monitor 参数中包含此值。
要在仪表板中删除监视器:
- 前往 Load Balancing(负载均衡)。
- 选择 Monitors(监视器) 选项卡。
- 在特定监视器上,选择 Delete(删除)。
要使用 API 删除监视器,请发送 DELETE 请求。