一 kafka本地目录结构

[root@hadoop ~]# cd /tmp/kafka-logs1

[root@hadoop kafka-logs1]# find .
.
./.lock
./recovery-point-offset-checkpoint
./log-start-offset-checkpoint
./cleaner-offset-checkpoint
./replication-offset-checkpoint
./meta.properties
./mytest-1
./mytest-1/leader-epoch-checkpoint
./mytest-1/00000000000000000000.log
./mytest-1/00000000000000000000.index
./mytest-1/00000000000000000000.timeindex
./mytest-0
./mytest-0/leader-epoch-checkpoint
./mytest-0/00000000000000000000.log
./mytest-0/00000000000000000000.index
./mytest-0/00000000000000000000.timeindex

搭建单节点多broker的kafka后,启动zk和kafka。

[root@hadoop ~]# cd /usr/local/kafka
[root@hadoop kafka]# zookeeper-server-start.sh config/zookeeper.properties
...
[root@hadoop kafka]# kafka-server-start.sh config/server0.properties &
...
[root@hadoop kafka]# kafka-server-start.sh config/server1.properties &
...
[root@hadoop kafka]# kafka-server-start.sh config/server2.properties &
... [root@hadoop ~]# jps
QuorumPeerMain
Kafka
Kafka
Kafka
Jps

创建kafka集群时我已经创建了一个主题test02,现在我们再创建一个主题mytest(2个分区)

[root@hadoop ~]# cd /usr/local/kafka
[root@hadoop kafka]# kafka-topics.sh --create --zookeeper localhost: --replication-factor --partitions --topic mytest
Created topic "mytest".

查看日志目录可以发现,3个日志目录几乎是一致的(__consumer_offsets-0是个什么鬼?)

test02和mytest副本数均是3,所以3个broker的log下面均有;
test02只有一个分区,mytest有2个分区,所以有一个test02目录,和2个mytest目录。

[root@hadoop ~]# ll /tmp/kafka-logs0
总用量
-rw-r--r-- root root 8月 : cleaner-offset-checkpoint
drwxr-xr-x root root 8月 : __consumer_offsets-
-rw-r--r-- root root 8月 : log-start-offset-checkpoint
-rw-r--r-- root root 8月 : meta.properties
drwxr-xr-x root root 8月 : mytest- #命名格式:主题-分区
drwxr-xr-x root root 8月 : mytest-
-rw-r--r-- root root 8月 : recovery-point-offset-checkpoint
-rw-r--r-- root root 8月 : replication-offset-checkpoint
drwxr-xr-x root root 8月 : test02- [root@hadoop ~]# ll /tmp/kafka-logs1
总用量
-rw-r--r-- root root 7月 : cleaner-offset-checkpoint
-rw-r--r-- root root 8月 : log-start-offset-checkpoint
-rw-r--r-- root root 7月 : meta.properties
drwxr-xr-x root root 8月 : mytest-
drwxr-xr-x root root 8月 : mytest-
-rw-r--r-- root root 8月 : recovery-point-offset-checkpoint
-rw-r--r-- root root 8月 : replication-offset-checkpoint
drwxr-xr-x root root 8月 : test02- [root@hadoop ~]# ll /tmp/kafka-logs2
总用量
-rw-r--r-- root root 7月 : cleaner-offset-checkpoint
-rw-r--r-- root root 8月 : log-start-offset-checkpoint
-rw-r--r-- root root 7月 : meta.properties
drwxr-xr-x root root 8月 : mytest-
drwxr-xr-x root root 8月 : mytest-
-rw-r--r-- root root 8月 : recovery-point-offset-checkpoint
-rw-r--r-- root root 8月 : replication-offset-checkpoint
drwxr-xr-x root root 8月 : test02-

查看主题目录

[root@hadoop ~]# ll /tmp/kafka-logs0/test02-/
总用量
-rw-r--r-- root root 8月 : .index
-rw-r--r-- root root 8月 : .log
-rw-r--r-- root root 8月 : .timeindex
-rw-r--r-- root root 8月 : .snapshot
-rw-r--r-- root root 8月 : leader-epoch-checkpoint

查看元数据信息

[root@hadoop ~]# cat /tmp/kafka-logs0/meta.properties
version=
broker.id=
[root@hadoop ~]# cat /tmp/kafka-logs1/meta.properties
version=
broker.id=
[root@hadoop ~]# cat /tmp/kafka-logs2/meta.properties
version=
broker.id=

向 mytest主题 生产消息并消费消息,可以看出消息分别保存在了不同分区的log里

#生产消息
[root@hadoop kafka]# kafka-console-producer.sh --broker-list localhost:,localhost:,localhost: --topic mytest
>hello kafka
>hello world #消费消息
[root@hadoop kafka]# kafka-console-consumer.sh --bootstrap-server localhost:,localhost:,localhost: --topic mytest --from-beginning
hello kafka
hello world #可以看出,消息分别保存在了不同分区的log里
[root@hadoop ~]# cat /tmp/kafka-logs0/mytest-/.log
C}_Me Ye Yÿÿÿÿÿÿÿÿÿÿÿÿÿÿ"hello kafka[root@hadoop ~]#
[root@hadoop ~]# cat /tmp/kafka-logs0/mytest-/.log
e ꛁe ꞿÿÿÿÿÿÿÿÿÿÿÿÿÿ"hello world[root@hadoop ~]#

二 kafka在zk上的znode

1./controller                //data = {"version":1,"brokerid":0,"timestamp":"1533396512695"}

2./controller_epoch     //data=27#不清楚什么意思,貌似第一次启动时是1,难道是kafka启动过的次数?

3./brokers/ids             //实时维护active的broker
   /brokers/ids/0          //data = {"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints": ["PLAINTEXT://hadoop:9092"],                                              //"jmx_port":-1,"host":"hadoop","timestamp":"1533399158574","port":9092,"version":4}
  /brokers/ids/1
  /brokers/ids/2

/brokers/topics
  /brokers/topics/mytest/partitions/0/state     //data = {"controller_epoch":28,"leader":0,"version":1,"leader_epoch":0,"isr":[0,2,1]}
  /brokers/topics/mytest/partitions/1/state     //data = {"controller_epoch":28,"leader":1,"version":1,"leader_epoch":0,"isr":[1,0,2]}

/brokers/seqid

4./admin/delete_topics

5./isr_change_notification

6./consumers

7./config
   /config/changes
  /config/clients
  /config/brokers
  /config/topics
  /config/users

注意:productor不在zk注册

启动zk客户端

[root@hadoop ~]# cd /usr/local/kafka
[root@hadoop kafka]# zkCli.sh -server hadoop: #启动zk客户端
...

查看根目录

[zk: hadoop:(CONNECTED) ] ls / #查看znode
[cluster, controller_epoch, controller, brokers, zookeeper, admin, isr_change_notification, consumers,
log_dir_event_notification, latest_producer_id_block, config]

查看/controller

[zk: hadoop:(CONNECTED) ] ls /controller
[]
[zk: hadoop:(CONNECTED) ] get /controller
#这里的brokerid为0意思是kafka集群的leader为0
#如果集群中有多个broker,将leader杀死后会发现这里的brokerid变化。
{"version":,"brokerid":,"timestamp":""}
cZxid = 0x513
ctime = Sat Aug :: CST
mZxid = 0x513
mtime = Sat Aug :: CST
pZxid = 0x513
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x10000711d710001
dataLength =
numChildren =

查看/controller_epoch

[zk: hadoop:(CONNECTED) ] ls /controller_epoch
[]
[zk: hadoop:(CONNECTED) ] get /controller_epoch cZxid = 0x1c
ctime = Tue Jul :: CST
mZxid = 0x514
mtime = Sat Aug :: CST
pZxid = 0x1c
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x0
dataLength =
numChildren =

查看/brokers

[zk: hadoop:(CONNECTED) ] get /brokers
null
cZxid = 0x4
ctime = Tue Jul :: CST
mZxid = 0x4
mtime = Tue Jul :: CST
pZxid = 0xd
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x0
dataLength =
numChildren = #3个孩子分别是ids, topics, seqid [zk: hadoop:(CONNECTED) ] ls /brokers
[ids, topics, seqid]

查看/brokers/ids

[zk: hadoop:(CONNECTED) ] ls /brokers/ids
#显示kafka集群中的所有active的brokerid
#如果杀死broker ,这里将会显示[, ]
[, , ] [zk: hadoop:(CONNECTED) 8] get /brokers/ids/
{"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":["PLAINTEXT://hadoop:9092"],
"jmx_port":-,"host":"hadoop","timestamp":"","port":,"version":}
cZxid = 0x55f
ctime = Sun Aug :: CST
mZxid = 0x55f
mtime = Sun Aug :: CST
pZxid = 0x55f
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x10000711d710005
dataLength =
numChildren =

查看/brokers/topics

[zk: hadoop:(CONNECTED) 9] ls /brokers/topics
[mytest, test02, __consumer_offsets] [zk: hadoop:(CONNECTED) ] ls /brokers/topics/mytest
[partitions]
[zk: hadoop:(CONNECTED) ] ls /brokers/topics/mytest/partitions #显示分区个数:mytest主题有2个分区,分别为0和1
[, ]
[zk: hadoop:(CONNECTED) 12] ls /brokers/topics/mytest/partitions/
[state]
[zk: hadoop:(CONNECTED) 13] ls /brokers/topics/mytest/partitions//state
[] #以下可以看出每个分区拥有不同的leader
[zk: hadoop:(CONNECTED) 14] get /brokers/topics/mytest/partitions//state
{"controller_epoch":,"leader":,"version":,"leader_epoch":,"isr":[,,]}
cZxid = 0x5a2
ctime = Sun Aug :: CST
mZxid = 0x5a2
mtime = Sun Aug :: CST
pZxid = 0x5a2
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x0
dataLength =
numChildren =
[zk: hadoop:(CONNECTED) ] get /brokers/topics/mytest/partitions//state
{"controller_epoch":,"leader":,"version":,"leader_epoch":,"isr":[,,]}
cZxid = 0x5a1
ctime = Sun Aug :: CST
mZxid = 0x5a1
mtime = Sun Aug :: CST
pZxid = 0x5a1
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x0
dataLength =
numChildren =

查看/brokers/seqid

[zk: hadoop:(CONNECTED) 16] ls /brokers/seqid
[]
[zk: hadoop:(CONNECTED) ] get /brokers/seqid
null
cZxid = 0xd
ctime = Tue Jul :: CST
mZxid = 0xd
mtime = Tue Jul :: CST
pZxid = 0xd
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x0
dataLength =
numChildren =

查看/admin/delete_topics

[zk: hadoop:(CONNECTED) ] ls /admin
[delete_topics]
[zk: hadoop:(CONNECTED) ] ls /admin/delete_topics
[]

查看/isr_change_notification

[zk: hadoop:(CONNECTED) 20] ls /isr_change_notification
[]
[zk: hadoop:(CONNECTED) ] get /isr_change_notification
null
cZxid = 0xe
ctime = Tue Jul :: CST
mZxid = 0xe
mtime = Tue Jul :: CST
pZxid = 0x544
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x0
dataLength =
numChildren =

查看/consumers

#不知为何,我这里一直显示为空,按理说启动消费者之后这里应该显示相应信息的
[zk: hadoop:(CONNECTED) ] ls /consumers
[]
[zk: hadoop:(CONNECTED) 23] get /consumers
null
cZxid = 0x2
ctime = Tue Jul :: CST
mZxid = 0x2
mtime = Tue Jul :: CST
pZxid = 0x2
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x0
dataLength =
numChildren =

查看/config

[zk: hadoop:(CONNECTED) 24] ls /config
[changes, clients, brokers, topics, users]
[zk: hadoop:(CONNECTED) 25] ls /config/changes
[]
[zk: hadoop:(CONNECTED) 26] ls /config/clients
[]
[zk: hadoop:(CONNECTED) ] ls /config/brokers
[]
[zk: hadoop:(CONNECTED) ] ls /config/topics #与ls /brokers/topics结果一致
[mytest, test02, __consumer_offsets]
[zk: hadoop:(CONNECTED) ] ls /config/users
[]

尝试杀死集群的leader后,查看相对应的znode变化

#.杀死leader
[root@hadoop ~]# ps -ef|grep server0.properties #找到server0的进程号为4791
root 8月04 pts/ :: ...信息太多,忽略.../server0.properties
root : pts/ :: grep --color=auto server0.properties
[root@hadoop ~]# kill - #杀死进程
[root@hadoop ~]# ps -ef|grep server0.properties #再次查看
root : pts/ :: grep --color=auto server0.properties #.查看/controller:brokerid由0变为1
[zk: hadoop:(CONNECTED) 30] get /controller
{"version":,"brokerid":,"timestamp":""}
cZxid = 0x54c
ctime = Sun Aug :: CST
mZxid = 0x54c
mtime = Sun Aug :: CST
pZxid = 0x54c
cversion =
dataVersion =
aclVersion =
ephemeralOwner = 0x10000711d710002
dataLength =
numChildren = #.查看/brokers/ids:active的broker只剩下1和2了
[zk: hadoop:(CONNECTED) ] ls /brokers/ids
[, ] #.重新启动broker
[root@hadoop kafka]# kafka-server-start.sh config/server0.properties &

尝试删除一个主题test02,查看相对应的znode变化

#.删除主题
[root@hadoop ~]# cd /usr/local/kafka
[root@hadoop kafka]# kafka-topics.sh --zookeeper localhost: --delete --topic test02
Topic test02 is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true. #.查看主题:没有结果(应该有结果?)
[root@hadoop kafka]# kafka-topics.sh --describe --zookeeper localhost: --topic test02 #.查看log目录下test02-0目录是否存在:不存在了
[root@hadoop kafka]# ll /tmp/kafka-logs0 #test02目录没有了
总用量
-rw-r--r-- root root 8月 : cleaner-offset-checkpoint
drwxr-xr-x root root 8月 : __consumer_offsets-
...
drwxr-xr-x root root 8月 : __consumer_offsets-
-rw-r--r-- root root 8月 : log-start-offset-checkpoint
-rw-r--r-- root root 8月 : meta.properties
drwxr-xr-x root root 8月 : mytest-
drwxr-xr-x root root 8月 : mytest-
-rw-r--r-- root root 8月 : recovery-point-offset-checkpoint
-rw-r--r-- root root 8月 : replication-offset-checkpoint #.查看/admin/delete_topics:为空。按理说这里应该显示删除的主题test02
[zk: hadoop:(CONNECTED) 32] ls /admin/delete_topics
[] #.查看/brokers/topics:这里显示test02确实被删除了
[zk: hadoop:(CONNECTED) 33] ls /brokers/topics
[mytest, __consumer_offsets] #.查看/config/topics:
[zk: hadoop:(CONNECTED) 34] ls /config/topics
[mytest, __consumer_offsets] #以上均是我的实际操作结果,与老师演示的有一些出入,暂时无法解释原因

kafka3 本地目录结构以及在在zk上的znode的更多相关文章

  1. svn本地目录结构for window

    演示内容: 使用svn目录结构来进行备份正式版和修复版本,最终合并修复版本.主干上的版本. 使用工具: visualSVN server 服务器软件工具 TortoiseSVN客户端工具 1.服务器的 ...

  2. Twitter Storm源代码分析之Nimbus/Supervisor本地目录结构

    storm集群里面工作机器分为两种一种是nimbus, 一种是supervisor, 他们通过zookeeper来进行交互,nimbus通过zookeeper来发布一些指令,supervisor去读z ...

  3. 浅谈android中的目录结构

    之前在android游戏开发中就遇到本地数据存储的问题:一般情形之下就将动态数据写入SD中存储,在没有SD卡的手机上就需另作处理了;再有在开发android应用的过程中,总要去调试APP,安装时又想去 ...

  4. Linux文件系统的目录结构

    Linux下的文件系统为树形结构,入口为/ 树形结构下的文件目录: 无论哪个版本的Linux系统,都有这些目录,这些目录应该是标准的.各个Linux发行版本会存在一些小小的差异,但总体来说,还是大体差 ...

  5. Linux 文件系统的目录结构

    http://www.jb51.net/LINUXjishu/151820.htmlLinux下的文件系统为树形结构,入口为/ 树形结构下的文件目录: 无论哪个版本的Linux系统,都有这些目录,这些 ...

  6. chromiun 学习《二》 目录结构 +启动流程

    1.chromium的目录结构. 2.先上分析图一张.主要是从BrowserMain进程进行分析的.

  7. thinkphp学习笔记1—目录结构和命名规则

    原文:thinkphp学习笔记1-目录结构和命名规则 最近开始学习thinkphp,在下不才,很多的问题看不明白所以想拿出来,恕我大胆发在首页上,希望看到的人能为我答疑解惑,这样大家有个互动,学起来快 ...

  8. CentOS版本区别及 Linux目录结构及其详解

    CentOS 7.0体验与之前版本的不同http://www.linuxidc.com/Linux/2014-07/104196.htm CentOS版本选择http://www.centoscn.c ...

  9. mybatis学习笔记(六)使用generator生成mybatis基础配置代码和目录结构

    原文:http://blog.csdn.net/oh_mourinho/article/details/51463413 创建maven项目 <span style="font-siz ...

随机推荐

  1. 如何修改DEDECMS文章标题长度

    方法一:      首先你要进入dedecms后台,系统——系统基本参数——其他选项——文档标题最大长度——在这修改为200或更大(其实200应该是足够了). 方法二:      进入phpmyadm ...

  2. android 编程之 PopupWindow 窗口的弹出

    PopupWindow 是一个可以显示在当前 Activity 之上的浮动容器,PopupWindow 弹出的位置是能够改变的,按照有无偏移量,可以分为无偏移和有偏移两种:按照参照对象的不同又可以分为 ...

  3. [JS] ECMAScript 6 - Object : compare with c#

    Ref: 对象的扩展 Outline: 属性的简洁表示法 属性名表达式 方法的 name 属性 Object.is() Object.assign() 属性的可枚举性和遍历 Object.getOwn ...

  4. ASP.NET MVC 4 - 上传图片到数据库

    这里演示如何在MVC WEB应用程序如何上传图片到数据库以及如何在WEB页面上显示图片.数据库表对应整个Model类,不单图片数据一个字段,我们从数据表的定义开始: CREATE TABLE [dbo ...

  5. Chrome浏览器端调试JavaScript

    1. 一个超级简单的html文件拉入chrome浏览器 2. 右键-->检查 3. 点击Sources 4. html的12行加个断点 5. 刷新页面,点开Console面板,输入变量num,我 ...

  6. Jenkins和Sonar集成

    Jenkins可以通过插件的形式和Sonar很好的集成. (1)Jenkin安装Sonar插件(这里我估计安装的插件有点多) 注意:之前安装Jenkins的时候我用的是JDK系统环境环境变量jdk1. ...

  7. iOS - UILabel添加图片之富文本的简单应用

    //创建富文本 NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@" ...

  8. db2 MON_GET_PKG_CACHE_STMT 表函数 抓取分析SQL

    MON_GET_PKG_CACHE_STMT 表函数 还可以使用 MON_GET_PKG_CACHE_STMT 表函数来查询当前 PACKAGE CACHE 中 SQL 语句(包括动态 SQL 和静态 ...

  9. PHP微信支付开发

    此链接https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=15_2,是微信官方的示例,无效,报错. 1.申请微信支付的开通条件?什么样的账号可以 ...

  10. PHP之魔术引号

    什么是魔术引号 Warning 本特性已自 PHP5.3.0起废弃并将自PHP5.4.0起移除. 当打开,所有的'(单引号),"(双引号),  (反斜线)和NULL 字符都会被自动加上一个反 ...