> For the complete documentation index, see [llms.txt](https://hulining.gitbook.io/fluentbit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hulining.gitbook.io/fluentbit/administration/configuring-fluent-bit/upstream-servers.md).

# 上游服务负载均衡

Fluent Bit [输出插件](https://app.gitbook.com/s/-M7r4TRvogEqaAD3Fmce/administration/configuring-fluent-bit/pipeline/outputs)通过网络连接外部服务交付日志是很常见的，例如 [HTTP](/fluentbit/pipeline/outputs/http.md), [Elasticsearch](/fluentbit/pipeline/outputs/elasticsearch.md) 和 [Forward](https://app.gitbook.com/s/-M7r4TRvogEqaAD3Fmce/administration/configuring-fluent-bit/pipeline/outputs/forward.md) 等其他插件都是这种情况。比较常见的是连接到一个节点(主机)，可以满足许多应用场景，但是在某些情况下，则需要在不同节点进行负载均衡。 *Upstream* 特性提供了这种能力。

*`Upstream`* 定义了作为输出插件目标一组节点，根据实现的性质，输出插件**必须**支持 *Upstream* 功能。以下插件支持 *Upstream*:

* [Forward](https://app.gitbook.com/s/-M7r4TRvogEqaAD3Fmce/administration/configuring-fluent-bit/pipeline/outputs/forward.md)

当前实现的负载均衡模式是 *round-robin(轮询)*。

## 配置 <a href="#configuration" id="configuration"></a>

要定义 *Upstream*，需要创建一个特定的配置文件，其中包含 UPSTREAM 和一个或多个 NODE 配置段。下表描述了与每个配置段关联的属性。请注意，所有这些都是必须的:

| 配置段      | 配置项/键 | 描述                  |
| -------- | ----- | ------------------- |
| UPSTREAM | name  | 定义 *Upstream* 名称    |
| NODE     | name  | 定义 *Node* 名称,包含一个节点 |
|          | host  | 目标主机的 IP 地址或主机名     |
|          | port  | 目标服务的 TCP 端口        |

### NODE 和特定插件配置 <a href="#nodes-and-specific-plugin-configuration" id="nodes-and-specific-plugin-configuration"></a>

*NODE* 可能包含其他插件所需的配置项，这样我们为输出插件提供了足够的灵活性。一个常见的用例是 Forward 输出插件如果启用了TLS，则它需要一些共享的配置项(下面示例中包含更多详细信息)。

### Nodes and TLS (Transport Layer Security)

除了上表中定义的属性之外，可以通过使用 TLS 加密和证书完成对一个节点的网络进行加密。

可用的 TLS 选项在 [TLS/SSL](/fluentbit/administration/security.md) 部分中进行了描述，且可以添加到任何 *Node* 配置段中。

### 配置文件示例 <a href="#configuration-file-example" id="configuration-file-example"></a>

如下示例定义了一个名称为 `forward-balancing` 的*Upstream*，供 Forward 输出插件使用，它注册了三个 *Nodes*:

* node-1: 连接到 127.0.0.1:43000
* node-2: 连接到 127.0.0.1:44000
* node-3: 连接到 127.0.0.1:45000，使用 TLS 而无需验证。它还定义了名称 *`shared_key`* 的 Forward 输出插件所需的特定配置项。

```python
[UPSTREAM]
    name       forward-balancing

[NODE]
    name       node-1
    host       127.0.0.1
    port       43000

[NODE]
    name       node-2
    host       127.0.0.1
    port       44000

[NODE]
    name       node-3
    host       127.0.0.1
    port       45000
    tls        on
    tls.verify off
    shared_key secret
```

请注意，每个 *Upstream* **必须**定义在自己的配置文件中。不允许在同一文件或不同文件中添加多个 *Upstreams*。


---

# 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://hulining.gitbook.io/fluentbit/administration/configuring-fluent-bit/upstream-servers.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.
