我试着用卡夫卡。 所有配置都正确完成,但当我试图从控制台产生消息时,我一直得到以下错误
WARN Error while fetching metadata with correlation id 39 :
{4-3-16-topic1=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
Kafka版本:2.11-0.9.0.0
我试着用卡夫卡。 所有配置都正确完成,但当我试图从控制台产生消息时,我一直得到以下错误
WARN Error while fetching metadata with correlation id 39 :
{4-3-16-topic1=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
Kafka版本:2.11-0.9.0.0
当前回答
For all those struggling with the Kafka ssl setup and seeing this LEADER_NOT_AVAILABLE error. One of the reasons that might be broken is the keystore and truststore. In the keystore you need to have private key of the server + signed server certificate. In the client truststore, you need to have intermedidate CA certificate so that client can authenticate the kafka server. If you will use ssl for interbroker communication, you need this truststore also set in the server.properties of the brokers so they can authenticate each other.
我错误地漏掉了最后一篇文章,这让我痛苦地花了很多时间去寻找这个LEADER_NOT_AVAILABLE错误可能意味着什么。希望这能帮助到一些人。
其他回答
如果你得到这样重复的错误消息:
Error while fetching metadata with correlation id 3991 : {your.topic=LEADER_NOT_AVAILABLE}
Or
Discovered group coordinator 172.25.1.2:9092 (id: 2147483645 rack: null) (org.apache.kafka.clients.consumer.internals.AbstractCoordinator:677)
(Re-)joining group (org.apache.kafka.clients.consumer.internals.AbstractCoordinator:509)
Group coordinator 172.25.1.2:9092 (id: 2147483645 rack: null) is unavailable or invalid, will attempt rediscovery (org.apache.kafka.clients.consumer.internals.AbstractCoordinator:729)
Discovered group coordinator 172.25.40.219:9092 (id: 2147483645 rack: null) (org.apache.kafka.clients.consumer.internals.AbstractCoordinator:677)
Group coordinator 172.25.1.2:9092 (id: 2147483645 rack: null) is unavailable or invalid, will attempt rediscovery (org.apache.kafka.clients.consumer.internals.AbstractCoordinator:729)
然后,你需要像这样在kafka server.properties中配置监听器:
listeners=PLAINTEXT://your.server.ip:9092
这是在Kafka 2.5.0和confluent 5.4.1平台上尝试的解决方案。
我使用的是kafka_2.12-0.10.2.1:
vi problem / server . properties
加到下面一行:
listeners=PLAINTEXT://localhost:9092
不需要更改广告。当它拾取值时监听器 从STD侦听器属性。
代理将向生产者和消费者发布主机名和端口。如果没有设置,
如果配置了“监听器”,则使用该值
否则,它将使用从java.net.InetAddress.getCanonicalHostName()返回的值。
停止Kafka代理:
bin/kafka-server-stop.sh
重新启动代理:
bin/kafka-server-start.sh -daemon config/server.properties
现在你应该不会看到任何问题。
因为我想让我的kafka代理连接到远程生产者和消费者,所以我不想做广告。要注释掉的侦听器。在我的情况下,(在kubernetes上运行kafka),我发现我的kafka pod没有分配任何集群IP。通过从服务中删除行clusterIP: None。呵呵,kubernetes给kafka pod分配了一个内部ip。这解决了我的LEADER_NOT_AVAILABLE问题,也解决了kafka生产者/消费者的远程连接问题。
对我来说,原因是使用了一个特定的Zookeeper,这不是Kafka包的一部分。该Zookeeper已经安装在机器上用于其他目的。显然卡夫卡不会和任何一个动物园管理员合作。切换到卡夫卡附带的Zookeeper为我解决了这个问题。为了不与现有的Zookeeper发生冲突,我不得不修改我的配置,让Zookeeper监听不同的端口:
[root@host /opt/kafka/config]# grep 2182 *
server.properties:zookeeper.connect=localhost:2182
zookeeper.properties:clientPort=2182
这个警告(在0.10.2.1中)的另一种可能是,你试图对一个刚刚创建的主题进行投票,而这个主题分区的领导者还不可用,你正在进行领导者选举。
在主题创建和轮询之间等待一秒钟是一种变通方法。