编程语言
首页 > 编程语言> > java – Kafka – 经纪人:团队协调员不可用

java – Kafka – 经纪人:团队协调员不可用

作者:互联网

我有以下结构:

zookeeper: 3.4.12
kafka: kafka_2.11-1.1.0
server1: zookeeper + kafka
server2: zookeeper + kafka
server3: zookeeper + kafka

使用kafka-topics shell脚本创建具有复制因子3和分区3的主题.

./kafka-topics.sh --create --zookeeper localhost:2181 --topic test-flow --partitions 3 --replication-factor 3

并使用group localConsumers.当领导没事的时候它工作正常.

./kafka-topics.sh --describe --zookeeper localhost:2181 --topic test-flow
Topic:test-flow PartitionCount:3    ReplicationFactor:3 Configs:
    Topic: test-flow    Partition: 0    Leader: 3   Replicas: 3,2,1 Isr: 3,2,1
    Topic: test-flow    Partition: 1    Leader: 1   Replicas: 1,3,2 Isr: 1,3,2
    Topic: test-flow    Partition: 2    Leader: 2   Replicas: 2,1,3 Isr: 2,1,3

消费者的日志

Received FindCoordinator response ClientResponse(receivedTimeMs=1529508772673, latencyMs=217, disconnected=false, requestHeader=RequestHeader(apiKey=FIND_COORDINATOR, apiVersion=1, clientId=consumer-1, correlationId=0), responseBody=FindCoordinatorResponse(throttleTimeMs=0, errorMessage='null', error=NONE, node=myserver3:9092 (id: 3 rack: null)))

但是如果领导者失败了 – 我在消费者中得到了错误(systemctl stop kafka):

节点3不可用.好

./kafka-topics.sh --describe --zookeeper localhost:2181 --topic test-flow
Topic:test-flow PartitionCount:3    ReplicationFactor:3 Configs:
    Topic: test-flow    Partition: 0    Leader: 2   Replicas: 3,2,1 Isr: 2,1
    Topic: test-flow    Partition: 1    Leader: 1   Replicas: 1,3,2 Isr: 1,2
    Topic: test-flow    Partition: 2    Leader: 2   Replicas: 2,1,3 Isr: 2,1

消费者的日志

Received FindCoordinator response 
ClientResponse(receivedTimeMs=1529507314193, latencyMs=36, 
disconnected=false, 
requestHeader=RequestHeader(apiKey=FIND_COORDINATOR, apiVersion=1, 
clientId=consumer-1, correlationId=149), 
responseBody=FindCoordinatorResponse(throttleTimeMs=0, 
errorMessage='null', error=COORDINATOR_NOT_AVAILABLE, node=:-1 (id: -1 
rack: null)))

- Group coordinator lookup failed: The coordinator is not available.
- Coordinator discovery failed, refreshing metadata

消费者无法连接,直到领导者关闭或重新连接另一个消费者群体.

无法理解为什么会这样?
消费者应该重新平衡到另一个经纪人,但事实并非如此.

解决方法:

尝试将属性添加到server.conf并清理zookeeper缓存.
它应该有所帮助

offsets.topic.replication.factor=3
default.replication.factor=3

此问题的根本原因是不可能在节点之间分配主题偏移.

自动生成的主题:
__consumer_offsets

你可以通过以下方式检查:
./kafka-topics.sh –describe –zookeeper localhost:2181 –topic __consumer_offsets

注意这篇文章:
https://kafka.apache.org/documentation/#prodconfig

默认情况下,它会使用RF-1创建__consumer_offsets

重要的是在kafka / cluster启动之前配置复制因子.
否则,它可能会带来一些问题,例如在您的情况下重新配置实例.

标签:java,linux,apache-kafka,apache-zookeeper
来源: https://codeday.me/bug/20190910/1800898.html