我正在努力在Kafka Server和Spring(Boot)Kafka Client之间设置Kafka SSL。
我有一个运行SSL的Kafka服务器,如此处所述:http://kafka.apache.org/documentation/#security_ssl
listeners=SSL://test.test.de:9093
# ssl
security.inter.broker.protocol=SSL
ssl.keystore.location=/home/kafka/ssl/server.keystore.jks
ssl.keystore.password=secret
ssl.key.password=secret
ssl.truststore.location=/home/kafka/ssl/server.truststore.jks
ssl.truststore.password=secret
ssl.client.auth=required
ssl.enabled.protocols=TLSv1.2,TLSv1.1,TLSv1
ssl.keystore.type=JKS
ssl.truststore.type=JKS
ssl.secure.random.implementation=SHA1PRNG
我使用Spring Kafka设置了Spring Boot Library APP。这些是生产者配置:
Map<String, Object> props = new HashMap<>();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "test.test.de:9093");
props.put(ProducerConfig.RETRIES_CONFIG, 0);
props.put(ProducerConfig.BATCH_SIZE_CONFIG, 16384);
props.put(ProducerConfig.LINGER_MS_CONFIG, 1);
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 33554432);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL");
props.put("ssl.keystore.location", "C:\\dev\\tmp\\ssl\\client.keystore.jks");
props.put("ssl.truststore.location", "C:\\dev\\tmp\\ssl\\client.truststore.jks");
props.put("ssl.keystore.password", "secret");
props.put("ssl.truststore.password", "secret");
props.put("ssl.key.password", "secret");
props.put("ssl.enabled.protocols", "TLSv1.2,TLSv1.1,TLSv1");
props.put("ssl.keystore.type", "JKS");
props.put("ssl.truststore.type", "JKS");
当我通过kafkaTemplate.sendDefault
发送消息时,出现此异常:
java.net.ConnectException: Connection refused: no further information
at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:589) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:839) ~[na:na]
at org.apache.kafka.common.network.SslTransportLayer.finishConnect(SslTransportLayer.java:137) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.common.network.KafkaChannel.finishConnect(KafkaChannel.java:220) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:530) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.common.network.Selector.poll(Selector.java:485) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:549) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:324) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:239) ~[kafka-clients-2.5.0.jar:na]
at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
编辑:
其他一些调试日志:
2020-07-16 13:28:06.204 DEBUG 12516 --- [ad | producer-1]
org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Node -1 disconnected.
2020-07-16 13:28:06.204 WARN 12516 --- [ad | producer-1]
org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Connection to node -1 (test.test.de/192.192.192.192:9093) could not be established. Broker may not be available.
2020-07-16 13:28:06.204 WARN 12516 --- [ad | producer-1]
org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Bootstrap broker test.test.de:9093 (id: -1 rack: null) disconnected
2020-07-16 13:28:06.305 DEBUG 12516 --- [ad | producer-1]
org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Initialize connection to node test.test.de:9093 (id: -1 rack: null) for sending metadata request
2020-07-16 13:28:06.305 DEBUG 12516 --- [ad | producer-1]
org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Initiating connection to node test.test.de:9093 (id: -1 rack: null) using address test.test.de/192.192.192.192
2020-07-16 13:28:08.331 DEBUG 12516 --- [ad | producer-1]
o.apache.kafka.common.network.Selector : [Producer clientId=producer-1] Connection with test.test.de/192.192.192.192 disconnected
我不知道这是怎么回事。
我在服务器端和客户端都找不到错误详细信息。
我无法评估错误是无效的SSL握手还是其他原因。
答案 0 :(得分:0)
我刚刚找到了答案。谢谢你的帮助。正如Gary Russell正确建议的那样,没有SSL错误。在我看来,客户端由于某些奇怪的原因而无法访问服务器(ping正常)。
因此,事实证明,在(debian)(kafka)服务器上,其/ etc / hosts文件中的test.test.de条目设置为127.0.1.1。我将其更改为当前的IP地址,并且现在可以使用。 由于我不是系统管理员,所以我不知道为什么会有此IP设置。现在可以了。
答案 1 :(得分:0)
我尝试了另一种可行的解决方案:
/etc/hosts
离开127.0.1.1 test.test.de test
listeners
中的server.config
设置为listeners=SSL://:9093
在debian系统上,此处说明127.0.1.1的原因:
https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution
在这里:
http://bugs.debian.org/719621
我有两个选择:
test.test.de
(对于客户端连接)。如果您为dns test.test.de
提供从任何dhcp系统获得的IP地址(通常应保持静态),则侦听器配置将与listeners=SSL://test.test.de:9093
我不知道为什么,但这似乎可以解决ssl的客户端-服务器kafka通信错误。