> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/welcome/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/welcome/cn/elastic-compute/load-balancing/04-backend.md).

# 负载均衡器后端服务器

后端服务器是监听器后面实际提供流量服务的虚拟机。负载均衡器为每个新流选择其中一台，将数据包转发过去，并跟踪该流，以确保返回流量能够正确送达。

每台后端服务器仅属于一个监听器的池。如果同一台虚拟机需要为多个监听器提供服务（例如，443 端口的 HTTPS 监听器和 80 端口的 HTTP 重定向监听器），请在每个池中单独注册——每次注册都有独立的权重和健康状态。

## 后端服务器定义的内容

| 字段        | 说明                                                  |
| --------- | --------------------------------------------------- |
| **VM ID** | 后端引用的虚拟机。                                           |
| **私有 IP** | 附属全局 VPC 内用于流量转发的私有 IP 地址。                          |
| **端口**    | 监听器转发到的后端端口。`0` 表示"与监听器端口相同"——当后端与 VIP 监听同一端口时通常如此。 |
| **权重**    | 相对于同一池中其他后端的流量份额。供加权调度算法使用。                         |
| **健康状态**  | `健康` 或 `不健康`。不健康的后端被排除在调度之外。由健康检查器更新。               |

## 后端池规则

* 所有后端服务器必须与负载均衡器实例位于**同一全局 VPC 和同一地区**。目前不支持跨地区后端。
* 后端服务器可以跨越负载均衡器所在地区内的多个子网。
* 同一台虚拟机可以出现在多个监听器的池中；每次出现相互独立。

## 权重

每台后端服务器都有一个权重——一个整数，表示其相对于池中其他后端的流量份额。权重对加权算法（`wIc`）有效，对非加权算法（`wrr`、`lc`、`mh`）无效。

| 权重比例      | `wIc` 的效果                      |
| --------- | ------------------------------ |
| 1 : 1 : 1 | 三台后端均匀分配                       |
| 3 : 2 : 1 | 第一台的负载约为第二台的 3 倍；第二台约为第三台的 2 倍 |
| 1 : 1 : 0 | 第三台后端已排空——调度器不会为其分配新流量         |

**将权重设置为 0 进行排空。** 将后端的权重设置为 0 会阻止新连接被调度到该后端，同时现有连接继续完成。当后端没有活跃流量后，可以安全地移除它或下线虚拟机。这是滚动维护的标准模式——排空、替换、重新添加。

## 端口配置

* **监听器端口 = 后端端口。** 最常见的模式。将后端端口设置为 `0`（表示"与监听器端口相同"），每个连接到达所选后端的同一端口。
* **监听器端口 ≠ 后端端口。** 当后端在非标准端口上内部运行服务时很有用。例如，`tcp/443` 上的监听器可以转发至在 `tcp/8443` 上监听的后端。

## 客户端 IP 可见性

负载均衡器为直通模式。在 TCP 和 UDP 监听器上，后端均以**真实客户端 IP 作为源地址**——无需任何配置、内核模块或应用层头部。标准 Socket API（`getpeername`、访问日志、`REMOTE_ADDR` 等）返回原始客户端地址。

这使得基于源地址的访问控制、地理感知日志记录和按客户端 IP 的速率限制在后端上原生可用，如同客户端直接连接一般。

## 健康状态与流量资格

后端的当前健康状态决定调度器是否将其纳入新流量的考虑：

* **健康** — 纳入调度。新流量可以落到该后端。
* **不健康** — 排除在调度之外。现有连接继续，直到关闭或被清理，但不会发送新流量。

探测类型、阈值和全部失败时的回退行为请参见[健康检查](/welcome/cn/elastic-compute/load-balancing/05-health-check.md)。

## 添加和移除后端服务器

* **添加后端服务器** — 新后端进入池，但如果健康检查已开启，它只有在第一次成功探测后才开始接收流量。这避免了后端已注册但尚未就绪的短暂窗口。
* **移除后端服务器** — 新流量立即停止被调度到该后端。现有连接继续，直到自然关闭或空闲超时清理。为避免长连接的中途中断，请先将权重设为 0 进行排空，待活跃连接数降为零后再移除。
* **更改权重** — 在下一次调度决策时生效。已在进行中的流量继续在当前后端上运行。
* **更改端口** — 会中断该后端的现有连接（它们正在与旧端口通信）。对于生产环境的变更，请使用先排空再更改的模式。

## 限制与注意事项

* **同一 VPC，同一地区。** 后端必须与负载均衡器位于同一 VPC 和地区。目前不支持跨地区。
* **负载均衡器不进行会话终止。** 由于转发为直通模式，负载均衡器不充当 HTTP 代理——它不会重试失败的请求、干净地关闭半开连接或注入应用层头部。所有这些都是后端的职责。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.console.zenlayer.com/welcome/cn/elastic-compute/load-balancing/04-backend.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
