【问题标题】:Kafka on SSL not workingSSL上的Kafka不起作用
【发布时间】:2022-02-18 09:54:20
【问题描述】:

我正在尝试设置一个支持 SSL 的 Kafka 代理,但是当我尝试在主题上发布消息时,它会超时。 这是我遵循的步骤:

openssl req -new -newkey rsa:4096 -days 365 -x509 -subj "/CN=Kafka-Security-CA" -keyout ca-key -out ca-cert -nodes

keytool -genkey -keystore kafka.server.keystore.jks -validity 365 -storepass xxx-keypass xxx -dname "CN=kafka_broker.net" -storetype pkcs12

keytool -keystore kafka.server.keystore.jks -certreq -file cert-file -storepass xxx -keypass xxx

openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days 365 -CAcreateserial -passin pass:xxx

keytool -keystore kafka.server.truststore.jks -alias CARoot -import -file ca-cert -storepass xxx -keypass xxx -noprompt

keytool -keystore kafka.server.keystore.jks -import -file cert-signed -storepass xxx -keypass xxx -noprompt

keytool -keystore kafka.client.truststore.jks -alias CARoot -import -file ca-cert -storepass xxx -keypass xxx -noprompt

我知道通过 SSL 的连接失败了,因为当我这样做时:

/kafka_2.11-1.1.0/bin/kafka-console-producer.sh --broker-list kafka_broker:9092 --topic test --producer.config client.properties
>ewqeq
[2018-07-04 14:53:18,022] ERROR Error when sending message to topic test with key: null, value: 5 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.

其中 client.properties 是一个配置文件,其内容是:

security.protocol=SSL
ssl.truststore.location=./kafka.server.truststore.jks
ssl.truststore.password=xxx

我尝试了很多次,但没有任何效果。 我尝试连接的客户端位于 docker 容器中,也是 kafka。它们在同一个网络下,并且 kafka 主机名是我在创建密钥库期间也提供给 CN 的 kafka_broker。

【问题讨论】:

  • 我建议看一下这个示例 docker setup docs.confluent.io/current/tutorials/cp-demo/docs/… 我还建议在完成该教程并可能采用那里提供的相同脚本后,您也可以按照故障排除步骤进行操作这里docs.confluent.io/current/tutorials/…
  • 对不起,只是链接,但是当您从 docker plus SSL 开始时,这很困难。我还建议消除其中之一,因此您处于变量较少的场景中。如果你让 docker 和纯文本工作或 SSL 而没有 docker 工作,它将简化故障排除。
  • 您需要将密钥库和信任库 jks 文件捆绑到您的 docker 映像中。您可以查看我不久前发布的this 问题,即使它不是特定于 docker 的。

标签: docker ssl openssl apache-kafka


【解决方案1】:

试试这个:

security.protocol=SSL
ssl.truststore.location=file:relativepath/kafka.server.truststore.jks
ssl.truststore.password=xxx`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    • 2015-10-23
    • 2019-01-07
    • 2011-08-05
    • 1970-01-01
    相关资源
    最近更新 更多