

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

# 元数据管理
<a name="metadata-management"></a>

亚马逊 MSK 支持 Apache ZooKeeper 或 KRaft 元数据管理模式。

在 Amazon MSK 上的 Apache Kafka 3.7.x 版本中，你可以创建 KRaft 使用模式而不是模式的集群。 ZooKeeper KRaft基于 Kafka 的集群依赖 Kafka 中的控制器来管理元数据。

**Topics**
+ [ZooKeeper 模式](#msk-get-connection-string)
+ [KRaft 模式](#kraft-intro)

## ZooKeeper 模式
<a name="msk-get-connection-string"></a>

[Apache ZooKeeper](https://zookeeper.apache.org/) 是 “一项集中式服务，用于维护配置信息、命名、提供分布式同步和提供群组服务。分布式应用程序以某种形式使用所有这些类型的服务”，包括 Apache Kafka。

如果您的集群正在使用 ZooKeeper 模式，则可以使用以下步骤获取 Apache ZooKeeper 连接字符串。但是，我们建议您使用 `BootstrapServerString` 连接到您的集群并执行管理员操作，因为 `--zookeeper` 标志已在 Kafka 2.5 中被弃用，并已从 Kafka 3.0 中移除。

### 使用获取 Apache ZooKeeper 连接字符串 AWS 管理控制台
<a name="get-connection-string-console"></a>

1. 在 [https://console.aws.amazon.com/msk/](https://console.aws.amazon.com/msk/) 打开 Amazon MSK 控制台。

1. 该表显示了此账户下当前区域的所有集群。选择集群名称以查看其说明。

1. 在**集群摘要**页面上，选择**查看客户端信息**。这显示了引导程序代理以及 Apache ZooKeeper 连接字符串。

### 使用获取 Apache ZooKeeper 连接字符串 AWS CLI
<a name="get-connection-string-cli"></a>

1. 如果您不知道集群的 Amazon 资源名称 (ARN)，您可以通过列出您账户中的所有集群来找到它。有关更多信息，请参阅 [列出 Amazon MSK 集群](msk-list-clusters.md)。

1. 要获取 Apache ZooKeeper 连接字符串以及有关集群的其他信息，请运行以下命令，*ClusterArn*替换为集群的 ARN。

   ```
   aws kafka describe-cluster --cluster-arn ClusterArn
   ```

   该 `describe-cluster` 命令的输出如以下 JSON 示例所示。

   ```
   {
       "ClusterInfo": {
           "BrokerNodeGroupInfo": {
               "BrokerAZDistribution": "DEFAULT",
               "ClientSubnets": [
                   "subnet-0123456789abcdef0",
                   "subnet-2468013579abcdef1",
                   "subnet-1357902468abcdef2"
               ],
               "InstanceType": "kafka.m5.large",
               "StorageInfo": {
                   "EbsStorageInfo": {
                       "VolumeSize": 1000
                   }
               }
           },
           "ClusterArn": "arn:aws:kafka:us-east-1:111122223333:cluster/testcluster/12345678-abcd-4567-2345-abcdef123456-2",
           "ClusterName": "testcluster",
           "CreationTime": "2018-12-02T17:38:36.75Z",
           "CurrentBrokerSoftwareInfo": {
               "KafkaVersion": "2.2.1"
           },
           "CurrentVersion": "K13V1IB3VIYZZH",
           "EncryptionInfo": {
               "EncryptionAtRest": {
                   "DataVolumeKMSKeyId": "arn:aws:kms:us-east-1:555555555555:key/12345678-abcd-2345-ef01-abcdef123456"
               }
           },
           "EnhancedMonitoring": "DEFAULT",
           "NumberOfBrokerNodes": 3,
           "State": "ACTIVE",
           "ZookeeperConnectString": "10.0.1.101:2018,10.0.2.101:2018,10.0.3.101:2018"
       }
   }
   ```

   上一 JSON 示例在 `describe-cluster` 命令输出中显示 `ZookeeperConnectString` 键。复制与此键对应的值，并保存它以用于在集群上创建主题。
**重要**  
您的 Amazon MSK 集群必须处于`ACTIVE`状态才能获取 Apache ZooKeeper 连接字符串。当集群仍处于 `CREATING` 状态时，`describe-cluster` 命令的输出不包含 `ZookeeperConnectString`。如果发生这种情况，请等待几分钟，然后在集群进入 `ACTIVE` 状态后再次运行 `describe-cluster`。

### 使用 API 获取 Apache ZooKeeper 连接字符串
<a name="get-connection-string-api"></a>

要使用 API 获取 Apache ZooKeeper 连接字符串，请参阅[DescribeCluster](https://docs.aws.amazon.com//msk/1.0/apireference/clusters-clusterarn.html#DescribeCluster)。

## KRaft 模式
<a name="kraft-intro"></a>

亚马逊 MSK 在 Kafka 版本 3.7.x 中引入了对 KRaft （Apache Kafka Raft）的支持。Apache Kafka 社区旨在 KRaft 取代 Apache 在 [Apache](#msk-get-connection-string) Kafka 集群中 ZooKeeper进行元数据管理。在 KRaft 模式下，集群元数据在一组 Kafka 控制器中传播，这些控制器是 Kafka 集群的一部分，而不是跨节点传播。 ZooKeeper KRaft控制器包含在内，您无需支付任何额外费用，也不需要您进行额外的设置或管理。有关更多信息，请参阅 [KIP-500](https://cwiki.apache.org/confluence/display/KAFKA/KIP-500%3A+Replace+ZooKeeper+with+a+Self-Managed+Metadata+Quorum) KRaft。

以下是有关 MSK KRaft 模式的一些注意事项：
+ KRaft 模式仅适用于新集群。创建集群后，无法切换元数据模式。
+ 在 MSK 控制台上，您可以通过选择 Kafka 版本 3.7.x 并选中集群创建窗口中的 KRaft 复选框来创建基于 Kraft 的集群。
+ 要使用 MSK API [https://docs.aws.amazon.com/msk/1.0/apireference/clusters.html#CreateCluster](https://docs.aws.amazon.com/msk/1.0/apireference/clusters.html#CreateCluster)或[https://docs.aws.amazon.com/MSK/2.0/APIReference/v2-clusters.html#CreateClusterV2](https://docs.aws.amazon.com/MSK/2.0/APIReference/v2-clusters.html#CreateClusterV2)操作在 KRaft 模式下创建集群，应使用`3.7.x.kraft`作为版本。`3.7.x`用作在 ZooKeeper 模式下创建集群的版本。
+  ZooKeeper 基于 KRaft 和基于群集的每个代理的分区数相同。但是，通过在集群中配置更多代理， KRaft 允许您在每个集群[中托管更多](https://docs.aws.amazon.com/msk/latest/developerguide/limits.html)分区。
+ 在 Amazon MSK 上使用 KRaft 模式无需更改 API。但是，如果您的客户端今天仍在使用 `--zookeeper` 连接字符串，则应更新您的客户端，以使用 `--bootstrap-server` 连接字符串连接到您的集群。`--zookeeper` 标志在 Apache Kafka 2.5 版中已弃用，并从 Kafka 3.0 版开始移除。因此，我们建议您对与集群的所有连接使用最新的 Apache Kafka 客户端版本和 `--bootstrap-server` 连接字符串。
+ ZooKeeper 模式继续适用于所有已发布的版本，其中 Apache Kafka 也支持 zookeeper。有关 Apache Kafka 版本终止支持和未来更新的详细信息，请参阅[支持的 Apache Kafka 版本](supported-kafka-versions.md)。
+ 你应该检查你使用的任何工具是否能够在 APIs 没有 ZooKeeper 连接的情况下使用 Kafka Admin。有关将集群连接到 Cruise Control 的更新步骤，请参阅 [在 Amazon LinkedIn MSK 上使用 Apache Kafka 的巡航控制系统](cruise-control.md)。Cruise Control 还提供了[不带巡航控制系统的运行](https://github.com/linkedin/cruise-control/wiki/Run-without-ZooKeeper)说明 ZooKeeper。
+ 您无需直接访问集群的 KRaft 控制器即可执行任何管理操作。但是，如果使用开放监控来收集指标，您还需要控制器的 DNS 端点来收集有关集群的一些非控制器相关指标。您可以从 MSK 控制台或使用 [ListNodes](https://docs.aws.amazon.com/msk/1.0/apireference/clusters-clusterarn-nodes.html#ListNodes)API 操作获取这些 DNS 终端节点。有关[使用 Prometheus 监控预置 MSK 集群](open-monitoring.md)为 KRaft基于群集设置开放监控的更新步骤，请参阅。
+ 对于 KRaft 模式集群而不是 ZooKeeper 模式集群，您无需监控其他[CloudWatch 指标](https://docs.aws.amazon.com/msk/latest/developerguide/metrics-details.html)。MSK 管理您的集群中使用的 KRaft 控制器。
+ 您可以使用`--bootstrap-server`连接字符串在 KRaft 模式下 ACLs 使用集群继续进行管理。不应使用`--zookeeper`连接字符串进行管理 ACLs。请参阅[阿帕奇 Kafka ACLs](msk-acls.md)。
+ 在 KRaft 模式下，集群的元数据存储在 Kafka 中的 KRaft 控制器上，而不是外部 ZooKeeper 节点上。因此，您无需像控制节点那[样单独控制对控制器 ZooKeeper 节点的](https://docs.aws.amazon.com/msk/latest/developerguide/zookeeper-security.html)访问。