本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
在 Apache 中使用 TLS 安全 ZooKeeper
在客户端与 Apache ZooKeeper 节点之间传输时,您可以使用 TLS 安全来进行加密。要在 Apache ZooKeeper 节点上实现 TLS 安全,请执行以下操作:
集群必须使用 Apache Kafka 版本 2.5.1 或更高版本,才能在 Apache 中使用 TLS 安全。 ZooKeeper
在创建或配置集群时启用 TLS 安全。在启用 TLS 的情况下使用 Apache Kafka 版本 2.5.1 或更高版本创建集群,会自动对 Apache 端点使用 TLS 安全。 ZooKeeper 有关设置 TLS 安全的信息,请参阅Amazon MSK 加密入门。
使用DescribeCluster 操作检索 TLS Apache ZooKeeper 端点。
创建 Apache ZooKeeper 配置文件,以便与
kafka-configs.sh
和kafka-acls.sh
工具或 ZooKeeper 外壳一起使用。对于每个工具,您都使用 --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 命令。以下示例使用环境变量中的 Apache Kafka ZooKeeper 配置创建 Apache Kafka 主题:KAFKA_OPTS
<path-to-your-kafka-installation>
/bin/kafka-topics.sh --create --zookeeperZooKeeperTLSConnectString
--replication-factor 3 --partitions 1 --topic AWSKafkaTutorialTopic
注意
您在 Apache ZooKeeper 配置文件中使用的参数名称与您在KAFKA_OPTS
环境变量中使用的参数名称不一致。注意在配置文件和 KAFKA_OPTS
环境变量中与参数一起使用的名称。