Use Azure BlobStore offloader with Pulsar

本章将一步一步的指导你完成在 Pulsar 中安装和配置 Azure BlobStore offloader。

安装

请按照以下步骤安装 Azure BlobStore offloader。

前提条件

  • Pulsar:2.6.2 或更高版本

步骤

下列示例将使用 Pulsar 2.6.2。

  1. 使用下列方式下载 Pulsar 压缩包:

    • Apache 镜像下载

    • 从 Pulsar 官网下载页下载

    • 使用 wget 命令下载:

      1. wget https://archive.apache.org/dist/pulsar/pulsar-2.6.2/apache-pulsar-2.6.2-bin.tar.gz
  2. 下载并解压 Pulsar offloaders 程序包。

    1. wget https://downloads.apache.org/pulsar/pulsar-2.6.2/apache-pulsar-offloaders-2.6.2-bin.tar.gz
    2. tar xvfz apache-pulsar-offloaders-2.6.2-bin.tar.gz
  3. 将 Pulsar offloaders 作为offloaders复制到Pulsar目录中。

    1. mv apache-pulsar-offloaders-2.6.2/offloaders apache-pulsar-2.6.2/offloaders
    2. ls offloaders

    输出

    如输出所示,Pulsar使用 Apache jclouds 来支持 AWS S3GCSAzure 进行长期存储。

    1. tiered-storage-file-system-2.6.2.nar
    2. tiered-storage-jcloud-2.6.2.nar

    Note

    • 如果在一个裸机集群中运行 Pulsar,请确保offloaders安装包已经在 broker 的所有 pulsar 目录下解压缩。

    • 如果你在 Docker 中运行 Pulsar 或者通过 Docker 镜像 (如K8s和DCOS) 部署 Pulsar,你可以使用 apachepulsar/pulsar-all 镜像代替 apachepulsar/pulsar 镜像。 apachepulsar/pulsar-all image has already bundled tiered storage offloaders.

Configuration

Note

在将数据从 BookKeeper 转移到 Azure BlobStore, 之前,你需要配置 Azure BlobStore offload 驱动程序的一些属性。

此外,你还可以配置 Azure BlobStore offloader 的自动触发和手动触发机制。

配置 Azure BlobStore offloader driver

你可以在配置文件 broker.confstandalone.conf 中配置 Azure BlobStore offloader driver。

  • 以下为必选 配置。

    必选配置|说明|示例值 managedLedgerOffloadDriver | Offloader 驱动程序名称 | azureblob offloadersDirectory | Offloader 目录 | offloaders managedLedgerOffloadBucket | Bucket | pulsar-topic-offload

  • 以下为可选 配置。

    可选 | 描述 | 示例值 |—-|—-|—- managedLedgerOffloadReadBufferSizeInBytes|读取数据块的大小|1 MB managedLedgerOffloadMaxBlockSizeInBytes|写数据块的大小|64 MB managedLedgerMinLedgerRolloverTimeMinutes|一个 Topic 的 Ledger 翻转之间的最小时间

    注意: 不建议你在生产环境中设置此配置。 managedLedgerMaxEntriesPerLedger|在触发翻转之前追加到 Topic ledger 的最大条目数。

    注意:不建议你在生产环境中设置此配置。|5000

Bucket (必选)

一个 bucket 就是一个存储数据的基本容器。 你在 Azure BlobStore 中存储的所有东西都必须包含在一个 bucket 里。 您可以使用 bucket 来管理数据并控制对数据的访问,但与目录和文件夹不同,你不能嵌套 bucket。

示例

该示例将 bucket 命名为 pulsar-topic-offload

  1. managedLedgerOffloadBucket=pulsar-topic-offload

身份验证 (必选)

为了能够访问 Azure BlobStore ,你需要对 Azure BlobStore 进行认证。

  • conf/pulsar_env.sh 中设置环境变量 AZURE_STORAGE_ACCOUNTAZURE_STORAGE_ACCESS_KEY

    “export” 命令很重要,以便变量在生成进程的环境中可用。

    1. export AZURE_STORAGE_ACCOUNT=ABC123456789
    2. export AZURE_STORAGE_ACCESS_KEY=ded7db27a4558e2ea8bbf0bf37ae0e8521618f366c

读取/写入的数据块大小

你可以在配置文件broker.confstandalone.conf中配置发送到 Azure BlobStore 或从 Azure BlobStore 读取的请求大小。

配置 | 描述 | 默认值 |—-|—-|— managedLedgerOffloadReadBufferSizeInBytes | 从 Azure BlobStore 读回数据时,每个单独读的块大小。|1 MB managedLedgerOffloadMaxBlockSizeInBytes | 在多部分上传至 Azure BlobStore 存储时,每一部分的最大尺寸。 它不能小于5MB。 |64 MB

配置 Azure BlobStore 自动运行

命名空间策略可以配置成一旦到达阈值就自动卸载数据。 该阈值基于一个 topic 在 Pulsar 集群的数据存储大小而定。 一旦 topic 到达阈值,就自动触发卸载操作。

阈值|动作 |—-|—-

0 | 如果 topic 存储达到其阈值,它就会触发 offloading 操作。 = 0| 它使 broker 竭尽全力地 offload 数据。 < 0 | 它将禁用自动 offloading 操作。

当一个新 segment 添加到 topic 日志后会自动运行卸载。 如果你在命名空间上设置了阈值,但向该 topic 生产的消息很少,offloader 将会停止工作,直至当前 segment 达到饱和。

你可以通过命令行工具(CLI)设置阈值大小,比如 pulsar-admin。

broker.confstandalone.conf 中的卸载配置文件,主要适用于没有命名空间级别卸载策略的命名空间中。 每个命名空间可以有自己的卸载策略。 If you want to set offload policy for each namespace, use the command pulsar-admin namespaces set-offload-policies options command.

示例

该示例使用 pulsar-admin 将Azure BlobStore offloader 的阈值大小设置为10MB。

  1. bin/pulsar-admin namespaces set-offload-threshold --size 10M my-tenant/my-namespace

提示

For more information about the pulsar-admin namespaces set-offload-threshold options command, including flags, descriptions, and default values, see here.

配置 Azure BlobStore 手动运行

对于每一个 topic,你可以使用下列方法来手动触发 Azure BlobStore offloader:

  • 使用 REST endpoint。

  • 使用命令行工具(例如 pulsar-admin)。

    要想用命令行工具触发,你要指定一个 Topic 应该保留在 Pulsar 集群中的最大数据量(阈值)。 如果 Pulsar 集群上 topic 的数据大小超过了这个阈值,那么该 topic 下的 segment 就会被陆续转移到 Azure BlobStore 上,直到不再超过这个阈值。 优先移动旧的 segment。

示例

  • 该示例使用 pulsar-admin 手动触发了 Azure BlobStore offloader 的运行。

    1. bin/pulsar-admin topics offload --size-threshold 10M my-tenant/my-namespace/topic1

    输出

    1. Offload triggered for persistent://my-tenant/my-namespace/topic1 for messages before 2:0:-1

    提示

    For more information about the pulsar-admin topics offload options command, including flags, descriptions, and default values, see here.

  • 该示例使用 pulsar-admin 检查 Azure BlobStore offloader 的状态。

    1. bin/pulsar-admin topics offload-status persistent://my-tenant/my-namespace/topic1

    输出

    1. Offload is currently running

    要等待 Azure BlobStore offloader 完成任务,请添加 -w 参数。

    1. bin/pulsar-admin topics offload-status -w persistent://my-tenant/my-namespace/topic1

    输出

    1. Offload was a success
  1. 如果卸载时出现错误,错误会返回到 `pulsar-admin topics offload-status` 命令。
  2. ```bash
  3. bin/pulsar-admin topics offload-status persistent://my-tenant/my-namespace/topic1
  4. ```
  5. **输出**
  1. Reason: Error offloading: org.apache.bookkeeper.mledger.ManagedLedgerException: `
  1. > #### 提示
  2. >
  3. > For more information about the `pulsar-admin topics offload-status options` command, including flags, descriptions, and default values, see [here](https://pulsar.apache.org/tools/pulsar-admin/2.6.0-SNAPSHOT/#-em-offload-status-em-).

```