处理 Could not find a 'KafkaClient' entry in the JAAS configuration. System property 'java.security.auth.login.config'

场景

某监控进程需要访问多个集群的Kafka

INFO - org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
INFO - 	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:765)
INFO - 	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:633)
INFO - 	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:615)
INFO - Caused by: java.lang.IllegalArgumentException: Could not find a 'KafkaClient' entry in the JAAS configuration. System property 'java.security.auth.login.config' is /opt/kafka/kafka_client_jaas_usekeytab.conf
INFO - 	at org.apache.kafka.common.security.JaasContext.defaultContext(JaasContext.java:131)
INFO - 	at org.apache.kafka.common.security.JaasContext.load(JaasContext.java:96)
INFO - 	at org.apache.kafka.common.security.JaasContext.load(JaasContext.java:78)
INFO - 	at org.apache.kafka.common.network.ChannelBuilders.create(ChannelBuilders.java:100)
INFO - 	at org.apache.kafka.common.network.ChannelBuilders.clientChannelBuilder(ChannelBuilders.java:58)
INFO - 	at org.apache.kafka.clients.ClientUtils.createChannelBuilder(ClientUtils.java:88)
INFO - 	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:695)
INFO - 	... 6 common frames omitted
INFO - org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
INFO - 	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:765)
INFO - 	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:633)
INFO - 	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:615)
INFO - Caused by: java.lang.IllegalArgumentException: Could not find a 'KafkaClient' entry in the JAAS configuration. System property 'java.security.auth.login.config' is /opt/kafka/kafka_client_jaas_usekeytab.conf
INFO - 	at org.apache.kafka.common.security.JaasContext.defaultContext(JaasContext.java:131)
INFO - 	at org.apache.kafka.common.security.JaasContext.load(JaasContext.java:96)
INFO - 	at org.apache.kafka.common.security.JaasContext.load(JaasContext.java:78)
INFO - 	at org.apache.kafka.common.network.ChannelBuilders.create(ChannelBuilders.java:100)
INFO - 	at org.apache.kafka.common.network.ChannelBuilders.clientChannelBuilder(ChannelBuilders.java:58)
INFO - 	at org.apache.kafka.clients.ClientUtils.createChannelBuilder(ClientUtils.java:88)
INFO - 	at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:695)
INFO - 	... 6 more

Kafka官方文档:
https://kafka.apache.org/0110/documentation.html#security_sasl

Clients may specify JAAS configuration as a producer or consumer property without creating a physical configuration file. 
This mode also enables different producers and consumers within the same JVM to use different credentials by specifying different properties for each client. 
If both static JAAS configuration system property java.security.auth.login.config and client property sasl.jaas.config are specified, the client property will be used.

表示如果同时设置了这两个,则启用sasl.jaas.config。所以需要检查是哪个生效了,并且去对应的文件内检查这个ClientConfig是否正确。

java.security.auth.login.config and  sasl.jaas.config

结论

java.security.auth.login.config 和 sasl.jaas.config 同时使用,则 sasl.jaas.config优先。

需要检查对应文件内的ClientConfig

posted @ 2019-04-30 11:27  一杯半盏  阅读(17409)  评论(0编辑  收藏  举报