跳转到内容
搜索文档

管理负载均衡器

最后更新 查看 MarkdownAgent 设置

负载均衡器根据 pool 健康状态流量导向策略在 pool 之间分配流量。每个负载均衡器由其 DNS 主机名(lb.example.comdev.example.com 等)或 IP 地址标识。


有关负载均衡器的更多详情,请参阅负载均衡器

创建负载均衡器

要在仪表板中创建 Public 或 Private 负载均衡器:

创建 Public 负载均衡器

  1. 前往 Load Balancing(负载均衡) 并选择 Create load balancer(创建负载均衡器)

  2. Load Balancer Setup(负载均衡器设置) 上,选择 Public load balancer(公共负载均衡器)

  3. 选择要添加此负载均衡器的网站。

  4. Hostname(主机名) 页面上:

    • 输入 Hostname(主机名),即负载均衡器可用的 DNS 名称。有关记录优先级的更多详情,请参阅负载均衡的 DNS 记录
    • Data Localization(数据本地化) 下拉菜单中选择要在域名上使用的区域
    • 切换橙色云图标以更新代理模式,这会影响流量路由方式和公布的 IP 地址。
    • 为负载均衡器添加描述。
    • 如果需要基于会话的负载均衡,切换 Session Affinity(会话亲和性) 开关。
    • 如果需要 Adaptive Routing,切换 Adaptive Routing(自适应路由) 开关。
  5. 选择 Next(下一步)

  6. Add a Pool 页面上:

    • 选择一个或多个现有 pool 或创建新 pool
    • 如果要将流量导向设置为 Off,请重新排序负载均衡器中的 pool 以调整故障转移顺序。
    • 如有需要,更新 Fallback Pool(备用池)
    • 如果选择将流量导向设置为 Random,可以通过 API 为 pool 设置 Weights 以确定发送到每个 pool 的流量百分比。
  7. 选择 Next(下一步)

  8. Monitors(监视器) 页面上:

    • 查看附加到 pool 的 monitor。
    • 如有需要,可以附加现有 monitor 或创建新 monitor
  9. 选择 Next(下一步)

  10. Traffic Steering(流量引导) 页面上,选择流量导向选项并选择 Next(下一步)

  11. Custom Rules 页面上,选择现有规则或创建新规则

  12. 选择 Next(下一步)

  13. Review 页面上:

    • 查看配置并进行任何更改。
    • 选择 Save as Draft(保存为草稿)Save and Deploy

创建 Private 负载均衡器

  1. 前往 Load Balancing(负载均衡) 并选择 Create load balancer(创建负载均衡器)

  2. Load Balancer Setup(负载均衡器设置) 上,选择 Private load balancer(私有负载均衡器)

  3. 将负载均衡器与 Cloudflare 私有 IP 或指定 IP 地址关联,并为负载均衡器创建描述。

  4. Add a Pool 页面上:

    • 选择一个或多个现有 pool 或创建新 pool
    • 如果要将流量导向设置为 Off,请重新排序负载均衡器中的 pool 以调整故障转移顺序。
    • 如有需要,更新 Fallback Pool(备用池)
    • 如果选择将流量导向设置为 Random,可以通过 API 为 pool 设置 Weights 以确定发送到每个 pool 的流量百分比。
  5. 选择 Next(下一步)

  6. Monitors(监视器) 页面上:

    • 查看附加到 pool 的 monitor。
    • 如有需要,可以附加现有 monitor 或创建新 monitor
  7. 选择 Next(下一步)

  8. Traffic Steering(流量引导) 页面上,选择流量导向选项并选择 Next(下一步)

  9. 选择 Next(下一步)

  10. Review 页面上:

    • 查看配置并进行任何更改。
    • 选择 Save as Draft(保存为草稿)Save and Deploy

有关完整属性列表,请参阅 Create Load Balancer。如需 API 身份验证帮助,请参阅 Cloudflare API 文档

Required API token permissions

At least one of the following token permissions is required:
  • Load Balancers Write
Create Load Balancerbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/load_balancers" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"description": "Load Balancer for lb.example.com",
		"name": "lb.example.com",
		"enabled": true,
		"ttl": 30,
		"fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
		"default_pools": [
				"17b5962d775c646f3f9725cbc7a53df4",
				"9290f38c5d07c2e2f4df57b1f61d4196",
				"00920f38ce07c2e2f4df50b1f61d4194"
		],
		"proxied": true,
		"steering_policy": "random_steering",
		"session_affinity": "cookie",
		"session_affinity_attributes": {
				"samesite": "Auto",
				"secure": "Auto",
				"drain_duration": 100,
				"zero_downtime_failover": "sticky"
		},
		"session_affinity_ttl": 5000,
		"adaptive_routing": {
				"failover_across_pools": true
		},
		"location_strategy": {
				"prefer_ecs": "always",
				"mode": "resolver_ip"
		},
		"random_steering": {
				"pool_weights": {
						"de90f38ced07c2e2f4df50b1f61d4194": 0.3,
						"9290f38c5d07c2e2f4df57b1f61d4196": 0.5
				},
				"default_weight": 0.2
		}
	}'

响应包含新负载均衡器的完整定义。

Responsejson
{
  "success": true,
  "errors": [],
  "messages": [],
  "result": {
    "id": "699d98642c564d2e855e9661899b7252",
    "created_on": "2021-01-01T05:20:00.12345Z",
    "modified_on": "2021-01-01T05:20:00.12345Z",
    "description": "Load Balancer for lb.example.com",
    "name": "lb.example.com",
    "enabled": true,
    "ttl": 30,
    "fallback_pool": "17b5962d775c646f3f9725cbc7a53df4",
    "default_pools": [
      "17b5962d775c646f3f9725cbc7a53df4",
      "9290f38c5d07c2e2f4df57b1f61d4196",
      "00920f38ce07c2e2f4df50b1f61d4194"
    ],
    "proxied": true,
    "steering_policy": "random_steering",
    "session_affinity": "cookie",
    "session_affinity_attributes": {
      "samesite": "Auto",
      "secure": "Auto",
      "drain_duration": 100,
      "zero_downtime_failover": "sticky"
    },
    "session_affinity_ttl": 5000,
    "random_steering": {
      "pool_weights": {
        "de90f38ced07c2e2f4df50b1f61d4194": 0.3,
        "9290f38c5d07c2e2f4df57b1f61d4196": 0.5
      },
      "default_weight": 0.2
    }
  }
}

与其他站点共享负载均衡器

您可以通过创建规范名称(CNAME)记录,与账户中的其他站点共享负载均衡器。这样可以在多个域之间共享配置,而无需为每个站点创建新的负载均衡器。

您也可以为每个域配置单独的负载均衡器,并复用监视器和池。这在为不同域更改故障转移顺序时特别有用,例如当您的 example.co.uk 服务器与 example.comexample.com.au 具有不同的故障转移优先级时。


编辑负载均衡器

要在仪表板中编辑负载均衡器:

  1. 前往 Load Balancing(负载均衡)
  2. 在特定负载均衡器上,选择 Edit(编辑)
  3. 创建流程中,根据需要更新设置。
  4. Review(审核) 步骤,选择 Save(保存)

使用 API 编辑负载均衡器时,请求类型取决于您要编辑的范围。

要更新特定设置而无需重新提交整个配置,请使用 PATCH 请求。如需更广泛的更改,请使用 PUT 请求。


删除负载均衡器

如果您删除或禁用负载均衡器,端点对请求的响应将取决于您的现有 DNS 记录

要在仪表板中删除负载均衡器:

  1. 前往 Load Balancing(负载均衡)
  2. 在特定负载均衡器上,点击 Delete(删除)

要使用 API 删除负载均衡器,请发送 DELETE 请求。


设置告警

您可以配置告警,以在池或端点健康状态发生变化时接收通知。

Load Balancing Health Alert

Who is it for?

Customers who want to be warned about changes in health status in their pools or origins.

Other options / filters

Available filters include:

  • You can search for and add pools from your list of pools, as well as Include future pools (if all pools are selected).
  • You can choose the trigger that fires the notification when the health status becomes unhealthy, healthy, or either unhealthy or healthy
  • You can choose the trigger that fires the notification when the event source health status changes in pool, origin, or either pool or origin.

Included with

Purchase of Load Balancing.

What should you do if you receive one?

Evaluate load balancing analytics to review changes in health status over time.

有关如何设置警报的更多信息,请参阅 Cloudflare Notifications

这篇文档对您有帮助吗?