

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 中繼資料管理
<a name="metadata-management"></a>

Amazon MSK 支援 Apache ZooKeeper 或 KRaft 中繼資料管理模式。

從 Amazon MSK 上的 Apache Kafka 3.7.x 版，您可以建立使用 KRaft 模式而非 ZooKeeper 模式的叢集。KRaft 型叢集依賴 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` 連線到叢集和 Perfom 管理操作，因為 Kafka 2.5 中已棄用`--zookeeper`旗標，並從 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 Resource Name (ARN)，可以透過列出帳戶中的所有叢集來找到該 ARN。如需詳細資訊，請參閱[列出 Amazon MSK 叢集](msk-list-clusters.md)。

1. 若要獲得 Apache ZooKeeper 連線字串，以及叢集的其他相關資訊，請執行以下命令，使用叢集的 ARN 取代 *ClusterArn*。

   ```
   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>

Amazon MSK 在 Kafka 3.7.x 版中推出對 KRaft (Apache Kafka Raft) 的支援。Apache Kafka 社群開發 KRaft 來取代 [Apache ZooKeeper](#msk-get-connection-string)，以在 Apache Kafka 叢集中進行中繼資料管理。在 KRaft 模式中，叢集中繼資料會在 Kafka 控制器群組中傳播，這是 Kafka 叢集的一部分，而不是跨 ZooKeeper 節點。包含 KRaft 控制器，您無需支付額外費用，也不需要您進行額外的設定或管理。如需 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 模式建立叢集。
+ 在 KRaft 和 ZooKeeper 型叢集上，每個代理程式的分割區數量相同。不過，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 版開始移除。因此，我們建議您針對叢集的所有`--bootstrap-server`連線使用最新的 Apache Kafka 用戶端版本和連線字串。
+ ZooKeeper 模式繼續可用於 Apache Kafka 也支援 zookeeper 的所有發行版本。[支援的 Apache Kafka 版本](supported-kafka-versions.md) 如需 Apache Kafka 版本和未來更新終止支援的詳細資訊，請參閱 。
+ 您應該檢查您使用的任何工具是否能夠在沒有 ZooKeeper 連線的情況下使用 Kafka Admin APIs。如需將叢集連線至 Cruise Control [將 LinkedIn 的 Apache Kafka 定速控制與 Amazon MSK 搭配使用](cruise-control.md) 的更新步驟，請參閱 。Cruise Control 也有在沒有 [ ZooKeeper 的情況下執行 Cruise Control](https://github.com/linkedin/cruise-control/wiki/Run-without-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 型叢集的開放式監控的更新步驟，請參閱 。
+ 您不需要透過 ZooKeeper 模式叢集監控 KRaft 模式叢集的其他 [CloudWatch 指標](https://docs.aws.amazon.com/msk/latest/developerguide/metrics-details.html)。MSK 會管理叢集中使用的 KRaft 控制器。
+ 您可以使用連線`--bootstrap-server`字串在 KRaft 模式叢集中使用 繼續管理 ACLs。您不應該使用`--zookeeper`連線字串來管理 ACLs。請參閱 [Apache Kafka ACL](msk-acls.md)。
+ 在 KRaft 模式中，叢集的中繼資料存放在 Kafka 內的 KRaft 控制器上，而不是外部 ZooKeeper 節點。因此，您不需要像[使用 ZooKeeper 節點一樣分別控制對控制器節點](https://docs.aws.amazon.com/msk/latest/developerguide/zookeeper-security.html)的存取。