# 腾讯云 COS

本指南介绍了如何将 Alluxio 配置为使用腾讯云[对象存储 (COS)](https://cloud.tencent.com/product/cos) 作为底层存储系统。 腾讯云对象存储 (COS) 是腾讯云提供的一种分布式存储服务，用于海量数据，可通过 HTTP/HTTPS 协议访问。它可以存储海量数据，并具有无感知的带宽和容量扩展，使其成为大数据计算和分析的完美数据池。

## 先决条件

Alluxio 在集群模式下运行在多台机器上，因此其二进制包需要部署在这些机器上。

在使用 COS 和 Alluxio 之前，请创建一个新存储桶或使用现有存储桶。此外，请确定您希望在该存储桶中使用的目录，无论是创建新目录还是选择现有目录。在本指南中，COS 存储桶名称为 `COS_BUCKET`，存储桶中的目录为 `COS_DATA`，存储桶区域为 `COS_REGION`。

## 基本设置

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

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

```yaml
apiVersion: k8s-operator.alluxio.com/v1
kind: UnderFileSystem
metadata:
  name: alluxio-cos
  namespace: alx-ns
spec:
  alluxioCluster: alluxio-cluster
  path: cos://<COS_BUCKET>/<COS_DIRECTORY>
  mountPath: /cos
  mountOptions:
    fs.cos.access.key: <COS_ACCESS_KEY>
    fs.cos.secret.key: <COS_ACCESS_KEY_SECRET>
    fs.cos.region: <COS_REGION>
    fs.cos.app.id: <COS_APP_ID>
```

{% endtab %}

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

```shell
bin/alluxio mount add --path /cos/ --ufs-uri cos://<COS_BUCKET>/<COS_DATA> \
  --option fs.cos.access.key=<COS_SECRET_ID> --option fs.cos.secret.key=<COS_SECRET_KEY> \
  --option fs.cos.region=<COS_REGION> --option fs.cos.app.id=<COS_APP_ID>
```

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

{% hint style="info" %}
COS 存储桶的全名是 `<COS_BUCKET>-<COS_APP_ID>`。`path` 的值应仅包含 `<COS_BUCKET>` 部分，省略 `<COS_APP_ID>` 部分，从而得到 `cos://<COS_BUCKET>/<COS_DIRECTORY>`。此外，请确保将 `fs.cos.app.id` 设置为 `<COS_APP_ID>`。
{% endhint %}

## 高级设置

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

### 启用 HTTPS

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

```properties
alluxio.underfs.cos.secure.http.enabled=true
```

### COS 分段上传

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

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

```properties
# Timeout for uploading part when using multipart upload.
alluxio.underfs.object.store.multipart.upload.timeout
​
# Thread pool size for COS multipart upload.
alluxio.underfs.cos.multipart.upload.threads
​
# Multipart upload partition size for COS. The default partition size is 16MB.
alluxio.underfs.cos.multipart.upload.part.size
```

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

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

### 设置请求重试策略

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


---

# 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/cos.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.
