我试着用卡夫卡。 所有配置都正确完成,但当我试图从控制台产生消息时,我一直得到以下错误
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错误可能意味着什么。希望这能帮助到一些人。
其他回答
上述答案中提到的广告听众可能是原因之一。其他可能的原因有:
主题可能还没有创建。你可以使用bin/kafka-topics——list——zookeeper <zookeeper ip>:<zookeeper port>来检查 检查您提供给生成器以获取元数据的引导服务器。如果引导服务器不包含关于主题的最新元数据(例如,当它丢失其zookeeper声明时)。您必须添加多个引导服务器。
另外,确保已将所发布的侦听器设置为IP:9092而不是localhost:9092。后者意味着只能通过本地主机访问代理。
当我遇到错误时,我记得在引导服务器(或代理列表)列表中使用了PLAINTEXT://<ip>:<PORT>,它工作了,奇怪的是。
bin/kafka-console-producer --topic sample --broker-list PLAINTEXT://<IP>:<PORT>
当LEADER_NOT_AVAILABLE错误抛出时,只需重新启动kafka代理:
/bin/kafka-server-stop.sh
紧随其后的是
/bin/kafka-server-start.sh config/server.properties
(注意:Zookeeper必须在这个时候运行,否则它不会工作)
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错误可能意味着什么。希望这能帮助到一些人。
在过去的两周里,当我和Kafka一起工作时,我一直在目睹同样的问题,从那时起我就一直在阅读这篇Stackoverflow的帖子。
经过2周的分析,我推断在我的情况下会发生这种情况 当尝试向不存在的主题生成消息时。
在我的例子中,结果是Kafka返回了一个错误消息,但在 同时,以前不存在的话题。因此,如果我尝试在此事件之后再次对该主题产生任何消息,错误将不再出现,因为主题已被创建。
请注意:这可能是我的特定Kafka安装配置为自动创建主题时,同样的不存在;这应该解释了为什么在我的情况下,我可以看到的问题只有一次为每个主题重置主题:你的配置可能是不同的,在这种情况下,你会一直收到相同的错误一遍又一遍。
对于任何试图在kubernetes上运行kafka并遇到这个错误的人来说,这是最终为我解决的问题:
你必须:
将主机名添加到pod规范中,这样kafka就可以找到自己。
or
如果使用hostPort,则需要hostNetwork: true和dnsPolicy: ClusterFirstWithHostNet
这样做的原因是因为Kafka需要与自身对话,它决定使用“广告”侦听器/主机名来找到自己,而不是使用localhost。 即使您有一个将所广告的主机名指向pod的Service,它在pod中也不可见。我真的不知道为什么会这样,但至少有一个变通办法。
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: zookeeper-cluster1
namespace: default
labels:
app: zookeeper-cluster1
spec:
replicas: 1
selector:
matchLabels:
app: zookeeper-cluster1
template:
metadata:
labels:
name: zookeeper-cluster1
app: zookeeper-cluster1
spec:
hostname: zookeeper-cluster1
containers:
- name: zookeeper-cluster1
image: wurstmeister/zookeeper:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 2181
- containerPort: 2888
- containerPort: 3888
---
apiVersion: v1
kind: Service
metadata:
name: zookeeper-cluster1
namespace: default
labels:
app: zookeeper-cluster1
spec:
type: NodePort
selector:
app: zookeeper-cluster1
ports:
- name: zookeeper-cluster1
protocol: TCP
port: 2181
targetPort: 2181
- name: zookeeper-follower-cluster1
protocol: TCP
port: 2888
targetPort: 2888
- name: zookeeper-leader-cluster1
protocol: TCP
port: 3888
targetPort: 3888
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: kafka-cluster
namespace: default
labels:
app: kafka-cluster
spec:
replicas: 1
selector:
matchLabels:
app: kafka-cluster
template:
metadata:
labels:
name: kafka-cluster
app: kafka-cluster
spec:
hostname: kafka-cluster
containers:
- name: kafka-cluster
image: wurstmeister/kafka:latest
imagePullPolicy: IfNotPresent
env:
- name: KAFKA_ADVERTISED_LISTENERS
value: PLAINTEXT://kafka-cluster:9092
- name: KAFKA_ZOOKEEPER_CONNECT
value: zookeeper-cluster1:2181
ports:
- containerPort: 9092
---
apiVersion: v1
kind: Service
metadata:
name: kafka-cluster
namespace: default
labels:
app: kafka-cluster
spec:
type: NodePort
selector:
app: kafka-cluster
ports:
- name: kafka-cluster
protocol: TCP
port: 9092
targetPort: 9092