在 Apache ZooKeeper 中使用 TLS 安全 - Amazon Managed Streaming for Apache Kafka
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

在 Apache ZooKeeper 中使用 TLS 安全

在客户端与 Apache ZooKeeeper 节点之间传输时,您可以使用 TLS 安全来进行加密。要在 Apache ZooKeeeper 节点上实现 TLS 安全,请执行以下操作:

  • 集群必须使用 Apache Kafka 版本 2.5.1 或更高版本,才能在 Apache ZooKeeeper 中使用 TLS 安全。

  • 在创建或配置集群时启用 TLS 安全。在启用 TLS 的情况下使用 Apache Kafka 版本 2.5.1 或更高版本创建集群,会自动对 Apache ZooKeeeper 端点使用 TLS 安全。有关设置 TLS 安全的信息,请参阅Amazon MSK 加密入门

  • 使用 DescribeCluster 操作检索 TLS Apache ZooKeeeper 端点。

  • 创建 Apache ZooKeeeper 配置文件,用于 kafka-configs.shkafka-acls.sh 工具或 ZooKeeeper 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 ZooKeeeper 参数。以下示例演示了如何将 KAFKA_OPTS 环境变量配置为将 Apache ZooKeeeper 参数传递到其他命令:

    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 ZooKeeeper 节点的更多信息,请参阅 KIP-515: Enable ZK client to use the new TLS supported authentication