

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用创建具有分层存储的 Amazon MSK 集群 Amazon CLI
<a name="msk-create-cluster-tiered-storage-cli"></a>

要在集群上启用分层存储，请使用正确的 Apache Kafka 版本和分层存储属性创建集群。请按照以下代码示例操作。此外，请完成下一节中的步骤，[创建启用分层存储的 Kafka 主题 Amazon CLI](#msk-create-topic-tiered-storage-cli)。

有关创建集群的支持属性的完整列表，请参阅 [create-cluster](https://docs.amazonaws.cn//cli/latest/reference/kafka/create-cluster.html)。

```
aws kafka create-cluster \
 —cluster-name "MessagingCluster" \
 —broker-node-group-info file://brokernodegroupinfo.json \
 —number-of-broker-nodes 3 \
--kafka-version "3.6.0" \
--storage-mode "TIERED"
```

## 创建启用分层存储的 Kafka 主题 Amazon CLI
<a name="msk-create-topic-tiered-storage-cli"></a>

要完成在创建启用了分层存储的集群时开始的过程，您还要创建一个启用了分层存储的主题，其中包含后文代码示例中的属性。分层存储的专门属性如下：
+ `local.retention.ms`（例如 10 分钟）为基于时间的保留设置，`local.retention.bytes` 为日志段大小限制。
+ `remote.storage.enable` 设置为 `true` 即可启用分层存储。

以下配置使用 local.retention.ms，但此属性可替换为 local.retention.bytes。此属性控制 Apache Kafka 将数据从主存储复制到分层存储之前可以经过的时长或 Apache Kafka 可以复制的字节数。有关支持的配置属性的更多详细信息，请参阅 [Topic-level configuration](https://docs.amazonaws.cn//msk/latest/developerguide/msk-configuration-properties.html#msk-topic-confinguration)。

**注意**  
您必须使用 Apache Kafka 客户端版本 3.0.0 及更高版本。这些版本仅在 `kafka-topics.sh` 的这些客户端版本中名为 `remote.storage.enable` 的设置。要对使用早期版本的 Apache Kafka 的现有主题启用分层存储，请参阅[在现有 Amazon MSK 主题上启用分层存储](msk-enable-disable-topic-tiered-storage-cli.md#msk-enable-topic-tiered-storage-cli)小节。

```
bin/kafka-topics.sh --create --bootstrap-server $bs --replication-factor 2 --partitions 6 --topic MSKTutorialTopic --config remote.storage.enable=true --config local.retention.ms=100000 --config retention.ms=604800000 --config segment.bytes=134217728
```