

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

# 搭配 Apache ZooKeeper 使用 TLS 安全功能
<a name="zookeeper-security-tls"></a>

您可以使用 TLS 安全功能加密用戶端與 Apache ZooKeeper 節點之間的傳輸。要搭配 Apache ZooKeeper 節點使用 TLS 安全功能，請執行以下操作：
+ 叢集必須使用 Apache Kafka 2.5.1 版或更高版本以搭配 Apache ZooKeeper 使用 TLS 安全功能。
+ 建立或設定叢集時啟用 TLS 安全功能。使用 Apache Kafka version 2.5.1 版或更高版本建立，且啟用 TLS 的叢集，會自動搭配 Apache ZooKeeper 端點使用 TLS 安全功能。如需有關 TLS 安全功能設定的資訊，請參閱 [開始使用 Amazon MSK 加密](msk-working-with-encryption.md)。
+ 使用 [DescribeCluste ](https://docs.aws.amazon.com/msk/1.0/apireference/clusters-clusterarn.html#DescribeCluster) 操作擷取 TLS Apache ZooKeeper 端點。
+ 建立 Apache ZooKeeper 組態檔案，以搭配 `kafka-configs.sh` 和 [https://kafka.apache.org/documentation/#security_authz_cli](https://kafka.apache.org/documentation/#security_authz_cli) 工具使用，或搭配 ZooKeeper Shell 使用。搭配各個工具，您可以使用 `--zk-tls-config-file` 參數來指定您的 Apache ZooKeeper 組態。

  以下範例顯示了一個典型的 Apache ZooKeeper 組態檔案：

  ```
  zookeeper.ssl.client.enable=true
  zookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty
  zookeeper.ssl.keystore.location=kafka.jks
  zookeeper.ssl.keystore.password=test1234
  zookeeper.ssl.truststore.location=truststore.jks
  zookeeper.ssl.truststore.password=test1234
  ```
+ 對於其他命令 (如 `kafka-topics`)，您必須使用 `KAFKA_OPTS` 環境變量來設定 Apache ZooKeeper 參數。以下範例演示了如何設定 `KAFKA_OPTS` 環境變量來將 Apache ZooKeeper 參數傳遞到其他命令：

  ```
  export KAFKA_OPTS="
  -Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty 
  -Dzookeeper.client.secure=true 
  -Dzookeeper.ssl.trustStore.location=/home/ec2-user/kafka.client.truststore.jks
  -Dzookeeper.ssl.trustStore.password=changeit"
  ```

  設定 `KAFKA_OPTS` 環境變數之後，就可以正常使用 CLI 命令。以下範例使用來自 `KAFKA_OPTS` 環境變量的 Apache ZooKeeper 組態建立 Apache Kafka 主題：

  ```
  <path-to-your-kafka-installation>/bin/kafka-topics.sh --create --zookeeper ZooKeeperTLSConnectString --replication-factor 3 --partitions 1 --topic AWSKafkaTutorialTopic
  ```

**注意**  
您在 Apache ZooKeeper 組態檔案中使用的參數名稱，與您在 `KAFKA_OPTS` 環境變量中使用的參數不一致。請注意您在組態檔案和 `KAFKA_OPTS` 環境變量中使用了哪些參數名稱。

如需有關透過 TLS 存取 Apache ZooKeeper 節點的詳細資訊，請參閱 [ KIP-515: Enable ZK client to use the new TLS supported authentication](https://cwiki.apache.org/confluence/display/KAFKA/KIP-515%3A+Enable+ZK+client+to+use+the+new+TLS+supported+authentication)。