Kafka 身份验证失败与客户端机制发生意外的握手请求 PLAIN 启用的机制是 []

问题描述 投票:0回答:2

我在 Windows 中尝试从 Java 程序连接 Ubuntu 中的 kafka 时遇到以下异常

[main] INFO org.apache.kafka.clients.producer.KafkaProducer - [Producer clientId=producer-1] Instantiated an idempotent producer.
[main] INFO org.apache.kafka.common.security.authenticator.AbstractLogin - Successfully logged in.
[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka version: 3.5.0
[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka commitId: c97b88d5db4de28d
[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka startTimeMs: 1689709198762
[kafka-producer-network-thread | producer-1] INFO org.apache.kafka.common.network.Selector -         
[Producer clientId=producer-1] Failed authentication with rakesh-virtual-machine/192.168.108.130 (channelId=-1) (Unexpected handshake request with client mechanism PLAIN, enabled mechanisms are [])
[kafka-producer-network-thread | producer-1] INFO org.apache.kafka.clients.NetworkClient - 
[Producer clientId=producer-1] Node -1 disconnected.
[kafka-producer-network-thread | producer-1] ERROR org.apache.kafka.clients.NetworkClient - 
[Producer clientId=producer-1] Connection to node -1 (rakesh-virtual-machine/x.x.x.x:9092) failed authentication due to: Unexpected handshake request with client mechanism PLAIN, enabled mechanisms are []
[kafka-producer-network-thread | producer-1] WARN org.apache.kafka.clients.NetworkClient -         
[Producer clientId=producer-1] Bootstrap broker rakesh-virtual-machine:9092 (id: -1 rack: null) disconnected
[main] INFO org.apache.kafka.clients.producer.KafkaProducer - [Producer clientId=producer-1] Closing the Kafka producer with timeoutMillis = 9223372036854775807 ms.
[main] INFO org.apache.kafka.common.metrics.Metrics - Metrics scheduler closed
[main] INFO org.apache.kafka.common.metrics.Metrics - Closing reporter 
org.apache.kafka.common.metrics.JmxReporter

我的 Java Cofig 是

    Properties properties = new Properties();
    properties.setProperty("bootstrap.servers", "rakesh-virtual-machine:9092");
    properties.put("security.protocol", "SASL_PLAINTEXT");
    properties.put("sasl.mechanism", "PLAIN");
    properties.put("sasl.jaas.config", PlainLoginModule.class.getName()
            + " required username=\"admin\" password=\"12345\";");

    properties.setProperty("key.serializer", StringSerializer.class.getName());
    properties.setProperty("value.serializer", StringSerializer.class.getName());

    KafkaProducer<String, String> producer = new KafkaProducer<>(properties);
    ProducerRecord<String, String> record = new ProducerRecord<>("test", "test_value");
    producer.send(record);
    producer.flush();
    producer.close();

Kafka server.properties 的配置如下。

listeners=PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093
inter.broker.listener.name=PLAINTEXT
advertised.listeners=PLAINTEXT://rakesh-virtual-machine:9092
sasl.mechanism.inter.broker.protocol=PLAIN
sasl.enabled.mechanisms=PLAIN
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

任何帮助将不胜感激。

java apache-kafka kafka-producer-api
2个回答
0
投票

您的

listeners
/
advertised.listeners
仅启用
PLAINTEXT
(所以什么也没有)。因此,错误显示
enabled mechanisms are []

将其替换为

SASL_PLAINTEXT
(如映射列表中所定义),并确保在运行
KAFKA_OPTS
 之前已将代理 JAAS 文件添加为 
kafka-server-start

环境变量的一部分

0
投票

当我将listeners/advertished.listeners更改为SASL_PLAINTEXT时,连接已建立,但Kafka命令在pod内不起作用

当我运行任何命令时,pod 内出现以下错误---

[2025-01-03 11:03:44,632] 信息 [AdminClient clientId=adminclient-1] 节点 -1 已断开连接。 (org.apache.kafka.clients.NetworkClient) [2025-01-03 11:03:44,632] 信息 [AdminClient clientId=adminclient-1] 由于节点 -1 断开连接,取消了关联 ID 293 的进行中 METADATA 请求(自创建以来经过的时间:294ms,自发送以来经过的时间:294ms,请求超时:492ms)(org.apache.kafka.clients.NetworkClient) [2025-01-03 11:03:44,831]信息[AdminClient clientId = adminclient-1]由于等待呼叫时超时而从-1断开连接(callName = fetchMetadata,deadlineMs = 1735902224830,tries = 76,nextAllowedTryMs = 1735902224732) (org.apache.kafka.clients.admin.KafkaAdminClient) [2025-01-03 11:03:44,831] 信息 [AdminClient clientId=adminclient-1] 客户端请求与节点 -1 (org.apache.kafka.clients.NetworkClient) 断开连接 [2025-01-03 11:03:44,831] 信息 [AdminClient clientId=adminclient-1] 由于节点 -1 断开连接,取消了关联 ID 295 的进行中 METADATA 请求(自创建以来经过的时间:97ms,自发送以来经过的时间:97ms,请求超时:96ms)(org.apache.kafka.clients.NetworkClient) [2025-01-03 11:03:44,831] 信息 [AdminClient clientId=adminclient-1] 元数据更新失败(org.apache.kafka.clients.admin.internals.AdminMetadataManager) org.apache.kafka.common.errors.TimeoutException:调用(callName = fetchMetadata,deadlineMs = 1735902224830,tries = 77,nextAllowedTryMs = 1735902224931)在77次尝试后在1735902224831超时 原因:org.apache.kafka.common.errors.DisconnectException:由于节点 -1 断开连接,取消了关联 ID 295 的 fetchMetadata 请求 执行主题命令时出错:等待节点分配超时。调用:listTopics [2025-01-03 11:03:44,841] 错误 org.apache.kafka.common.errors.TimeoutException:等待节点分配超时。调用:listTopics (kafka.admin.TopicCommand$) [2025-01-03 11:03:44,843] INFO 应用程序信息 kafka.admin.client for adminclient-1 未注册(org.apache.kafka.common.utils.AppInfoParser) [2025-01-03 11:03:44,843] 信息 [AdminClient clientId=adminclient-1] 元数据更新失败(org.apache.kafka.clients.admin.internals.AdminMetadataManager) org.apache.kafka.common.errors.TimeoutException:AdminClient 线程已退出。调用:获取元数据 [2025-01-03 11:03:44,843] 信息 [AdminClient clientId=adminclient-1] 关闭期间 1 个剩余操作超时。 (org.apache.kafka.clients.admin.KafkaAdminClient) [2025-01-03 11:03:44,855] INFO Metrics 调度程序已关闭(org.apache.kafka.common.metrics.Metrics) [2025-01-03 11:03:44,855] INFO 关闭记者 org.apache.kafka.common.metrics.JmxReporter (org.apache.kafka.common.metrics.Metrics) [2025-01-03 11:03:44,855] INFO Metrics 记者关闭(org.apache.kafka.common.metrics.Metrics)

© www.soinside.com 2019 - 2024. All rights reserved.