java 组协调员不可用-Kafka

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40316862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 05:07:03  来源:igfitidea点击:

The group coordinator is not available-Kafka

javaapache-kafka

提问by Dolphin

When I am write a topic to kafka,there is an error:Offset commit failed:

当我向kafka写主题时,出现错误Offset commit failed::

2016-10-29 14:52:56.387 INFO [nioEventLoopGroup-3-1][org.apache.kafka.common.utils.AppInfoParser$AppInfo:82] - Kafka version : 0.9.0.1
2016-10-29 14:52:56.387 INFO [nioEventLoopGroup-3-1][org.apache.kafka.common.utils.AppInfoParser$AppInfo:83] - Kafka commitId : 23c69d62a0cabf06
2016-10-29 14:52:56.409 ERROR [nioEventLoopGroup-3-1][org.apache.kafka.clients.consumer.internals.ConsumerCoordinator$DefaultOffsetCommitCallback:489] - Offset commit failed.
org.apache.kafka.common.errors.GroupCoordinatorNotAvailableException: The group coordinator is not available.
2016-10-29 14:52:56.519 WARN [kafka-producer-network-thread | producer-1][org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater:582] - Error while fetching metadata with correlation id 0 : {0085000=LEADER_NOT_AVAILABLE}
2016-10-29 14:52:56.612 WARN [pool-6-thread-1][org.apache.kafka.clients.NetworkClient$DefaultMetadataUpdater:582] - Error while fetching metadata with correlation id 1 : {0085000=LEADER_NOT_AVAILABLE}

When create a new topic using command,it is ok.

当使用命令创建一个新主题时,就可以了。

./kafka-topics.sh --zookeeper localhost:2181 --create --topic test1 --partitions 1 --replication-factor 1 --config max.message.bytes=64000 --config flush.messages=1

This is the producer code using Java:

这是使用Java的生产者代码:

public void create() {
        Properties props = new Properties();
        props.clear();
        String producerServer = PropertyReadHelper.properties.getProperty("kafka.producer.bootstrap.servers");
        String zookeeperConnect = PropertyReadHelper.properties.getProperty("kafka.producer.zookeeper.connect");
        String metaBrokerList = PropertyReadHelper.properties.getProperty("kafka.metadata.broker.list");
        props.put("bootstrap.servers", producerServer);
        props.put("zookeeper.connect", zookeeperConnect);//声明ZooKeeper
        props.put("metadata.broker.list", metaBrokerList);//声明kafka broker
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 1000);
        props.put("linger.ms", 10000);
        props.put("buffer.memory", 10000);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        producer = new KafkaProducer<String, String>(props);
    }

Where is wrong?

哪里错了?

回答by Vishal Akkalkote

I faced the same issue. The problem I had was, when you start your kafka broker there is a property associated with it, "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR". If you are working with single node cluster make sure you set this property with value '1'. As its default value is 3. This change resolved my problem. (you can check the value in kafka.properties file) Note: I was using base image of confluent kafka version 4.0.0 ( confluentinc/cp-kafka:4.0.0)

我遇到了同样的问题。我遇到的问题是,当您启动 kafka 代理时,有一个与之关联的属性“KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR”。如果您正在使用单节点集群,请确保将此属性设置为“1”。由于其默认值为 3。此更改解决了我的问题。(您可以检查 kafka.properties 文件中的值) 注意:我使用的是 confluent kafka 版本 4.0.0 的基础映像( confluentinc/cp-kafka:4.0.0)

回答by Rafa? Solarski

Looking at your logs the problem is that cluster probably don't have connection to node which is the only one know replica of given topic in zookeeper.

查看您的日志,问题在于集群可能没有连接到节点,而节点是 Zookeeper 中给定主题的唯一已知副本。

You can check it using given command:
kafka-topics.sh --describe --zookeeper localhost:2181 --topic test1

您可以使用给定的命令检查它:
kafka-topics.sh --describe --zookeeper localhost:2181 --topic test1

or using kafkacat:
kafkacat -L -b localhost:9092

或使用 kafkacat:
kafkacat -L -b localhost:9092

Example result:

结果示例:

Metadata for all topics (from broker 1003: localhost:9092/1003):
 1 brokers:
  broker 1003 at localhost:9092
 1 topics:
  topic "topic1" with 1 partitions:
    partition 0, leader -1, replicas: 1001, isrs: , Broker: Leader not available

If you have single node cluster then broker id(1001) should match leader of topic1 partition.
But as you can see the only one known replica of topic1was 1001- which is not available now, so there is no possibility to recreate topic on different node.

如果您有单节点集群,那么 broker id( 1001) 应该匹配 topic1 分区的领导者。
但是正如您所看到的,topic1的唯一已知副本是1001- 现在不可用,因此不可能在不同的节点上重新创建主题。

The source of the problem can be an automatic generation of broker id(if you don't have specified broker.idor it is set to -1).
Then on starting the broker(the same single broker) you probably receive broker id different that previouslyand different than was marked in zookeeper (this a reason why partition deletion can help - but it is not a production solution).

问题的根源可能是代理 ID 的自动生成(如果您没有指定broker.id或设置为-1)。
然后在启动代理(同一个代理)时,您可能会收到与以前不同的代理 ID,并且与 Zookeeper 中标记的不同(这是分区删除可以提供帮助的原因 - 但它不是生产解决方案)。

The solution may be setting broker.id value in node configto fixed value - according to documentation it should be done on produciton environment:
broker.id=1

解决方案可能是将节点配置中的 broker.id 值设置为固定值 - 根据文档,它应该在生产环境中完成:
broker.id=1

If everything is alright you should receive sth like this:

如果一切正常,你应该会收到这样的信息:

Metadata for all topics (from broker 1: localhost:9092/1001):
 1 brokers:
  broker 1 at localhost:9092
 1 topics:
  topic "topic1" with 1 partitions:
    partition 0, leader 1, replicas: 1, isrs: 1

Kafka Documentation: https://kafka.apache.org/documentation/#prodconfig

Kafka 文档:https: //kafka.apache.org/documentation/#prodconfig

回答by Amit Ahuja

Hi you have to keep your kafka replicas and replication factor for your code same.

嗨,您必须保持代码的 kafka 副本和复制因子相同。

for me i keep 3 as replicas and 3 as replication factor.

对我来说,我保留 3 个作为副本,3 个作为复制因子。

回答by Mauvis Ledford

The solution for me was that I had to make sure KAFKA_ADVERTISED_HOST_NAMEwas the correct IP address of the server.

对我来说,解决方案是我必须确保KAFKA_ADVERTISED_HOST_NAME服务器的 IP 地址正确。

回答by Kannan Msk

We faced same issue in production too. The code was working fine for long time suddenly we got this exception.

我们在生产中也遇到了同样的问题。代码运行良好很长时间突然我们得到了这个异常。

We analyzed that there is no issue in code. So we asked deployment team to restart the zookeeper. Restarting it solved the issue.

我们分析,代码没有问题。所以我们要求部署团队重新启动zookeeper。重新启动它解决了问题。