启动kafka无反应_kafka consumer无法正常启动原因调查
生产环境三个服务分别消费kafka(version 1.1.0)不同topic里的日志分析结果,将其写入HBase,其中消费kafka使用的是consumer的subscribe API。服务稳定运行了几个月,某次因为HBase升级将其临时关闭,在重新启动过程中,诡异的问题发生了。
现象
三个服务中有一个可以正常启动,另外两个在启动过程中似乎卡在某个地方block住。打开info级别的日志,发现如下可疑信息
> 2018-12-28 16:58:22 WARN pool-1-thread-2 org.apache.kafka.clients.NetworkClient - [Consumer clientId=consumer-2, groupId=defy-rtlog-receiver-srcproxy] Connection to node -2 could not be established. Broker may not be available.
调整日志级别为debug,重新观察观察日志,发现服务不停打印如下信息
> Coordinator discovery failed, refreshing metadata
分析问题
从日志来看,服务中kafka consumer一直死循环寻找coordinator. 但coordinator是什么鬼?
话说源码之前了无秘密,翻下源码,可以从注释中可以看到GroupCoordinator角色的描述如下
即GroupCoordinator负责管理group的offset,每一个broker启动一个GroupCoordinator,负责管理一些consumer groups。
既然每一个broker都有一个GroupCoordinator,那么如何判断一个group归哪个GroupCoordinator来管呢?
这里涉及到kafka内部一个特殊的topic __consumer_offsets,其用于存储group的消费情况,默认有50个partition。
某一group消费情况要存在哪一个partition,通过以下方式得到def partitionFor(groupId: String): Int = Utils.abs(groupId.hashCode) % groupMetadataTopicPartitionCount
计算得到的partition的leader所在的Broker即为该group对应的GroupCoordinator。
有了上面的原理铺垫,再来看日志描述,排查方向变得清晰起来。用命令kafka-topic.sh看下topic __consumer_offsetsJMX_PORT=9844 ./kafka-topics.sh --zookeeper jjh715:2181/kafka-jjh-cluster1 --describe --topic __consumer_offsets
# output
Topic:__consumer_offsets PartitionCount:50 ReplicationFactor:1 Configs:segment.bytes=104857600,cleanup.policy=compact,compression.type=producer
Topic: __consumer_offsets Partition: 0 Leader: 5 Replicas: 5 Isr: 5
Topic: __consumer_offsets Partition: 1 Leader: 6 Replicas: 6 Isr: 6
Topic: __consumer_offsets Partition: 2 Leader: 7 Replicas: 7 Isr: 7
Topic: __consumer_offsets Partition: 3 Leader: 8 Replicas: 8 Isr: 8
Topic: __consumer_offsets Partition: 4 Leader: 9 Replicas: 9 Isr: 9
Topic: __consumer_offsets Partition: 5 Leader: 0 Replicas: 0 Isr: 0
Topic: __consumer_offsets Partition: 6 Leader: 1 Replicas: 1 Isr: 1
Topic: __consumer_offsets Partition: 7 Leader: 2 Replicas: 2 Isr: 2
Topic: __consumer_offsets Partition: 8 Leader: -1 Replicas: 3 Isr: 3
Topic: __consumer_offsets Partition: 9 Leader: 4 Replicas: 4 Isr: 4
Topic: __consumer_offsets Partition: 10 Leader: 5 Replicas: 5 Isr: 5
Topic: __consumer_offsets Partition: 11 Leader: 6 Replicas: 6 Isr: 6
Topic: __consumer_offsets Partition: 12 Leader: 7 Replicas: 7 Isr: 7
Topic: __consumer_offsets Partition: 13 Leader: 8 Replicas: 8 Isr: 8
Topic: __consumer_offsets Partition: 14 Leader: 9 Replicas: 9 Isr: 9
Topic: __consumer_offsets Partition: 15 Leader: 0 Replicas: 0 Isr: 0
Topic: __consumer_offsets Partition: 16 Leader: 1 Replicas: 1 Isr: 1
Topic: __consumer_offsets Partition: 17 Leader: 2 Replicas: 2 Isr: 2
Topic: __consumer_offsets Partition: 18 Leader: -1 Replicas: 3 Isr: 3
Topic: __consumer_offsets Partition: 19 Leader: 4 Replicas: 4 Isr: 4
Topic: __consumer_offsets Partition: 20 Leader: 5 Replicas: 5 Isr: 5
Topic: __consumer_offsets Partition: 21 Leader: 6 Replicas: 6 Isr: 6
Topic: __consumer_offsets Partition: 22 Leader: 7 Replicas: 7 Isr: 7
Topic: __consumer_offsets Partition: 23 Leader: 8 Replicas: 8 Isr: 8
Topic: __consumer_offsets Partition: 24 Leader: 9 Replicas: 9 Isr: 9
Topic: __consumer_offsets Partition: 25 Leader: 0 Replicas: 0 Isr: 0
Topic: __consumer_offsets Partition: 26 Leader: 1 Replicas: 1 Isr: 1
Topic: __consumer_offsets Partition: 27 Leader: 2 Replicas: 2 Isr: 2
Topic: __consumer_offsets Partition: 28 Leader: -1 Replicas: 3 Isr: 3
Topic: __consumer_offsets Partition: 29 Leader: 4 Replicas: 4 Isr: 4
Topic: __consumer_offsets Partition: 30 Leader: 5 Replicas: 5 Isr: 5
Topic: __consumer_offsets Partition: 31 Leader: 6 Replicas: 6 Isr: 6
Topic: __consumer_offsets Partition: 32 Leader: 7 Replicas: 7 Isr: 7
Topic: __consumer_offsets Partition: 33 Leader: 8 Replicas: 8 Isr: 8
Topic: __consumer_offsets Partition: 34 Leader: 9 Replicas: 9 Isr: 9
Topic: __consumer_offsets Partition: 35 Leader: 0 Replicas: 0 Isr: 0
Topic: __consumer_offsets Partition: 36 Leader: 1 Replicas: 1 Isr: 1
Topic: __consumer_offsets Partition: 37 Leader: 2 Replicas: 2 Isr: 2
Topic: __consumer_offsets Partition: 38 Leader: -1 Replicas: 3 Isr: 3
Topic: __consumer_offsets Partition: 39 Leader: 4 Replicas: 4 Isr: 4
Topic: __consumer_offsets Partition: 40 Leader: 5 Replicas: 5 Isr: 5
Topic: __consumer_offsets Partition: 41 Leader: 6 Replicas: 6 Isr: 6
Topic: __consumer_offsets Partition: 42 Leader: 7 Replicas: 7 Isr: 7
Topic: __consumer_offsets Partition: 43 Leader: 8 Replicas: 8 Isr: 8
Topic: __consumer_offsets Partition: 44 Leader: 9 Replicas: 9 Isr: 9
Topic: __consumer_offsets Partition: 45 Leader: 0 Replicas: 0 Isr: 0
Topic: __consumer_offsets Partition: 46 Leader: 1 Replicas: 1 Isr: 1
Topic: __consumer_offsets Partition: 47 Leader: 2 Replicas: 2 Isr: 2
Topic: __consumer_offsets Partition: 48 Leader: -1 Replicas: 3 Isr: 3
Topic: __consumer_offsets Partition: 49 Leader: 4 Replicas: 4 Isr: 4
仔细观察输出结果如下,发现部分partition(8,18,28,38,48)的leader为-1,replicas为3, 同时发现该topic的ReplicationFactor为1
![kafka-topic-output]()
leader为-1表明leader所在的broker目前not available,replicas为3表明之前该broker为3,现在broker3找不到了,自然也无法找到group对应的GroupCoordinator。
根据三个服务的group id,计算对应的partition值,真相大白,broker3找不到是真凶。scala> Math.abs("defy-rtlog-receiver-cdn".hashCode()) % 50 // 正常启动
res8: Int = 33
scala> Math.abs("defy-rtlog-receiver-midsrc".hashCode()) % 50 // 无法启动
res9: Int = 8
scala> Math.abs("defy-rtlog-receiver-srcproxy".hashCode()) % 50 // 无法启动
res10: Int = 38
解决问题
启动一台kafka broker id为3的机器即可。
另外将特殊topic副本设为3,这样即使一台机器挂掉,__consumer_offsets上该partition的leader可以选举到其它机器上,不会产生上述影响# server.properties 文档中
offsets.topic.replication.factor=3
进一步思考
kafka历史花絮
kafka 0.9.0版本之后,开始启用新的consumer config,采用bootstrap.servers替代之前版本的zookeeper.connect,弱化对zk的依赖,将对zk的依赖隐藏到broker后面。有如下两个相关改动:在server端增加了GroupCoordinator这个角色
将topic的offset信息存储从zk改到一个特殊的topic中(__consumer_offsets)
reference
启动kafka无反应_kafka consumer无法正常启动原因调查相关推荐
- 启动kafka过一会进程自动挂掉问题原因
这是因为kafka logs目录下的meta.properties文件中的broker.id与server.properties中的broker.id不一致所导致,只需把两者改为一致启动kafka后就 ...
- 启动ubuntu无反应_奔驰E200轿车启动无反应检修
一辆行驶里程约1.8万km.配置271.860发动机的2012年奔驰E200轿车.该车仪表灯点亮,无法换挡,挡位显示异常,车辆启动无反应.反复开钥匙去挂挡,无法换挡,挡位不显示.车辆启动时没有任何着车 ...
- kafka jar包_Kafka系列文章之安装测试-第2篇
前言 上篇文章讲解了 Kafka 的基础概念和架构,了解了基本概念之后,必须得实践一波了,所谓"实践才是检验真理的唯一办法",后续系列关于 Kafka 的文章都以 kafka_2 ...
- win7 装系统踩坑之无法进入到u盘启动或无法进到BIOS
无法进入到u盘启动或无法进到BIOS 可能是启动热键没找对(一般为Del或F2或F1或F10或esc)详细见下图 系统坏了 显示这个界面 首先插入做好的启动盘或者镜像 根据提示重启一下 不同电脑品牌型 ...
- kafka中topic默认属性_kafka consumer 配置详解
1.Consumer Group 与 topic 订阅 每个Consumer 进程都会划归到一个逻辑的Consumer Group中,逻辑的订阅者是Consumer Group.所以一条message ...
- kafka 启动_Kafka的安装与启动
安装 在mac上可以使用brew install kafka进行kafka的安装,在安装kafka时,会自动检测有无zookpeer,如果没有的话也会安装一个. 启动kafka 启动kafka,首先要 ...
- kafka 主动消费_Kafka核心API——Consumer消费者
Consumer之自动提交 在上文中介绍了Producer API的使用,现在我们已经知道如何将消息通过API发送到Kafka中了,那么现在的生产者/消费者模型就还差一位扮演消费者的角色了.因此,本文 ...
- kafka自带的zk启动_kafka单机安装和启动
1.下载并解压到/usr/local/src目录下 2.运行kafka需要使用Zookeeper,先启动Zookeeper,如果没有Zookeeper,可以使用kafka自带打包和配置好的Zookee ...
- Kafka(Go)教程(十一)---Consumer Group Rebalance
来自:指月 https://www.lixueduan.com 原文:https://www.lixueduan.com/post/kafka/11-consumer-group-rebalance/ ...
最新文章
- [置顶] 归并排序,逆序数
- 自己添加ODBC数据源的Access驱动
- java线程池并发_Java并发教程–线程池
- phpcmsV9 用seotitle后面的小横杠分隔符自定义
- 设计模式之单例模式8种实现方式,其五:懒汉式(线程不安全,同步代码块)
- LeetCode刷题——91. 解码方法
- Docker存储驱动之总览
- VS code 使用技巧-设置鼠标滚轮翻页速度(Mac版本)
- WaWa的奇妙冒险(第二周集训自闭现场)
- 51单片机控制TB6600驱动器驱动42步进电机
- selenium打开网页被检测,怎么屏蔽和绕过
- Triton针对工业系统的形势分析以及检测手段 || 后附今日情报资源
- c语言16进制转10进制
- 亚马逊、Lazada、ebay、速卖通、shopee、敦煌、mercari、沃尔玛、测评(补单)自养号技术篇(论ip的重要性)
- 斯坦福大学开源Alpaca模型源码,性能与GPT-3.5相当比GPT4逊色,训练成本不到100美元(教程含源码)
- 唐僧师徒四人,谁最适合编程?
- django讲解 模型一
- python画三维几何图形拼成的图案_Scratch3.0少儿编程案例:循环画窗花
- 使用 jQuery Jcrop 实现图像裁剪
- 小米MIUI大更新,新增5项隐藏功能,米粉说:好用到停不下来