# 百度对象存储

本指南介绍了如何将[百度对象存储 (BOS)](https://cloud.baidu.com/doc/BOS/index.html) 配置为 Alluxio 的底层存储系统。百度对象存储 (BOS) 提供稳定、安全、高效且高度可扩展的存储服务。

## 先决条件

在使用 BOS 和 Alluxio 之前，请按照 [BOS 入门流程](https://intl.cloud.baidu.com/doc/BOS/s/Ik4xtp41n-en)注册 BOS 并创建一个 BOS 存储桶。

在开始之前，请确保您已具备下列所需信息：

| `<BOS_BUCKET>`            | 创建一个新的 BOS 存储桶或使用现有的存储桶                                                                                                                                                                            |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<BOS_DIRECTORY>`         | 您希望在存储桶中使用的目录，可以通过创建新目录或使用现有目录来实现                                                                                                                                                                  |
| `<BOS_ACCESS_KEY_ID>`     | <p>BOS 的<a href="https://intl.cloud.baidu.com/doc/Reference/s/jjwvz2e3p-en">访问密钥 ID</a>，<br>在<a href="https://intl.cloud.baidu.com/doc/Reference/s/9jwvz2egb-en">BOS AccessKey 管理控制台</a>中创建和管理</p> |
| `<BOS_ACCESS_KEY_SECRET>` | <p>BOS 的<a href="https://intl.cloud.baidu.com/doc/Reference/s/jjwvz2e3p-en">秘密访问密钥</a>，<br>在<a href="https://intl.cloud.baidu.com/doc/Reference/s/9jwvz2egb-en">BOS AccessKey 管理控制台</a>中创建和管理</p>  |
| `<BOS_ENDPOINT>`          | <p>存储桶的互联网端点，可以在存储桶概览页面中找到，其值为 <code>bj.bcebos.com</code> 和 <code>gz.bcebos.com</code>。<br>可用端点在<a href="https://cloud.baidu.com/doc/BOS/s/akrqd2wcx">区域与端点</a>中列出。</p>                            |
| `<BOS_REGION>`            | <p>存储桶所在的区域，例如 <code>cn-beijing</code> 或 <code>cn-guangzhou</code>。<br>可用区域在<a href="https://cloud.baidu.com/doc/BOS/s/akrqd2wcx">区域与端点</a>中列出。</p>                                                |

## 基本设置

通用挂载机制和 `UnderFileSystem` CR 字段参考，请参阅[底层存储](https://documentation.alluxio.io/ee-ai-cn/ufs/pages/QHxxAwAliFxrTQ5jOZw7#基本挂载配置)。

{% tabs %}
{% tab title="Kubernetes (Operator)" %}
使用 operator 创建 BOS 挂载点的 `ufs.yaml` 示例：

```yaml
apiVersion: k8s-operator.alluxio.com/v1
kind: UnderFileSystem
metadata:
  name: alluxio-bos
  namespace: alx-ns
spec:
  alluxioCluster: alluxio-cluster
  path: bos://<BOS_BUCKET>/<BOS_DIRECTORY>
  mountPath: /bos
  mountOptions:
    fs.bos.accessKeyId: <BOS_ACCESS_KEY>
    fs.bos.accessKeySecret: <BOS_ACCESS_KEY_SECRET>
    fs.bos.endpoint: <BOS_ENDPOINT>
```

{% endtab %}

{% tab title="Docker / 裸机" %}
如果不使用 operator，将 `bos://<BOS_BUCKET>/<BOS_DIRECTORY>` 挂载到 `/bos` 的示例命令：

```shell
bin/alluxio mount add --path /bos/ --ufs-uri bos://<BOS_BUCKET>/<BOS_DIRECTORY> \
  --option fs.bos.accessKeyId=<BOS_ACCESS_KEY> --option fs.bos.accessKeySecret=<BOS_ACCESS_KEY_SECRET> \
  --option fs.bos.endpoint=<BOS_ENDPOINT>
```

请注意，如果要挂载 BOS 存储桶的根目录，请在存储桶名称后添加一个尾随斜杠（例如 `bos://BOS_BUCKET/`）。
{% endtab %}
{% endtabs %}

## 高级设置

请注意，配置选项可以指定为挂载选项或 `conf/alluxio-site.properties` 中的配置属性。以下部分将介绍如何将配置设置为属性，但它们也可以通过 `--option <key>=<value>` 设置为挂载选项。

### 启用 HTTPS

要启用 HTTPS 协议以与 BOS 进行安全通信，并为数据传输提供额外的安全层，请在 conf/alluxio-site.properties 中配置以下设置：

```properties
fs.bos.endpoint=<BOS_ENDPOINT>
alluxio.underfs.bos.secure.http.enabled=true
```

### BOS 分段上传

我们使用分段上传方法通过多个部分上传一个文件，每个部分将在一个线程中上传。上传时不会生成任何临时文件。

您可以在 `conf/alluxio-site.properties` 中指定其他参数，以可能加快上传速度。

```properties
# Timeout for uploading part when using multipart upload.
alluxio.underfs.object.store.multipart.upload.timeout
```

```properties
# Thread pool size for BOS multipart upload.
alluxio.underfs.bos.multipart.upload.threads
```

<pre class="language-properties"><code class="lang-properties"><strong># Multipart upload partition size for BOS. The default partition size is 64MB.
</strong>alluxio.underfs.bos.multipart.upload.part.size
</code></pre>

禁用 BOS 分段上传，上传方法会一次性从头到尾完整上传一个文件。您需要修改 `conf/alluxio-site.properties` 以包含：

```properties
alluxio.underfs.bos.multipart.upload.enabled=false
```

### 设置请求重试策略

适用于所有对象存储 UFS 类型的重试配置，请参阅 UFS 概览中的[请求重试策略](https://documentation.alluxio.io/ee-ai-cn/ufs/pages/QHxxAwAliFxrTQ5jOZw7#请求重试策略)。

### 高并发调整

将 Alluxio 与 BOS 集成时，您可以通过调整以下配置来优化性能：

* `alluxio.underfs.bos.connection.max`：控制与 BOS 的最大连接数。默认值为 1024。
* `alluxio.underfs.bos.io.threads.num`：控制与 BOS 的 IO 线程。默认值为 256。
* `alluxio.underfs.bos.socket.timeout`：控制与 BOS 的套接字超时。默认值为 50 秒。
* `alluxio.underfs.bos.connect.timeout`：控制与 BOS 的连接超时。默认值为 50 秒。


---

# Agent Instructions: 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:

```
GET https://documentation.alluxio.io/ee-ai-cn/ufs/bos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
