Kafka系列之--Kafka中的术语理解

1 概述

创建一个主题为topic_0618:分区数为5,副本数2

[root@master kafka_2.11-2.4.1]# bin/kafka-topics.sh --create --zookeeper master:2181/kafka --replication-factor 2 --partitions 5 --topic topic_0618 
[root@master kafka_2.11-2.4.1]# bin/kafka-topics.sh --zookeeper master:2181/kafka --describe --topic topic_0618
Topic: topic_0618 PartitionCount: 5 ReplicationFactor: 2 Configs: 

 Topic: topic_0618 Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1,2
 Topic: topic_0618 Partition: 1 Leader: 2 Replicas: 2,0 Isr: 2,0
 Topic: topic_0618 Partition: 2 Leader: 0 Replicas: 0,1 Isr: 0,1
 Topic: topic_0618 Partition: 3 Leader: 1 Replicas: 1,0 Isr: 1,0
 Topic: topic_0618 Partition: 4 Leader: 2 Replicas: 2,1 Isr: 2,1 

下图展示了Kafka的相关术语以及之间的关系:

在这里插入图片描述

2 broker

Kafka集群,包含一个或者多个服务器,服务器节点称为Broker。
broker存储Topic数据,
如果一个Topic包含N个Partition,集群有N个Broker,那么每个Broker存储该Topic的一个Partition。
topic:t_0616 brokers:3 partitions:3 replication_factor:3

[root@master kafka_2.11-2.4.1]# bin/kafka-topics.sh --zookeeper master:2181/kafka --describe --topic t_0616
Topic: t_0616	PartitionCount: 3	ReplicationFactor: 3	Configs: 
Topic: t_0616	Partition: 0	Leader: 1	Replicas: 1,2,0	Isr: 1,2,0
Topic: t_0616	Partition: 1	Leader: 2	Replicas: 2,0,1	Isr: 2,0,1
Topic: t_0616	Partition: 2	Leader: 0	Replicas: 0,1,2	Isr: 0,1,2

如果一个Topic包含N个Partition,集群有M+N个Broker,那么其中有N个Broker存储该Topic的一个Partition,剩下的M个Broker将不存储该Topic的Partition。
topic:topic_0618_01 brokers:3 partitions:2 replication_factor:3

[root@master kafka_2.11-2.4.1]# bin/kafka-topics.sh --zookeeper master:2181/kafka --describe --topic topic_0618_01
Topic: topic_0618_01	PartitionCount: 2	ReplicationFactor: 3	Configs: 
Topic: topic_0618_01	Partition: 0	Leader: 1	Replicas: 1,2,0	Isr: 1,2,0
Topic: topic_0618_01	Partition: 1	Leader: 2	Replicas: 2,0,1	Isr: 2,0,1

如果一个Topic包含N个Partition,集群中Broker的数量小于N,那么一个Broker存储该Topic的一个Partition或者多个Partiton。尽量避免这种现象的发生,容易导致Kafka集群负载不均衡。
topic:topic_0618_01 brokers:3 partitions:5 replication_factor:2

[root@master kafka_2.11-2.4.1]# bin/kafka-topics.sh --zookeeper master:2181/kafka --describe --topic topic_0618
Topic: topic_0618 PartitionCount: 5 ReplicationFactor: 2 Configs: 
Topic: topic_0618 Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1,2
Topic: topic_0618 Partition: 1 Leader: 2 Replicas: 2,0 Isr: 2,0
Topic: topic_0618 Partition: 2 Leader: 0 Replicas: 0,1 Isr: 0,1
Topic: topic_0618 Partition: 3 Leader: 1 Replicas: 1,0 Isr: 1,0
Topic: topic_0618 Partition: 4 Leader: 2 Replicas: 2,1 Isr: 2,1 

3 Topic

每条发布到Kafka集群的消息都有一个类别,这个类别被称为Topic。(物理上不同Topic的消息分开存储,逻辑上一个Topic的消息虽然保存于一个或多个broker上但用户只需指定消息的Topic即可生产或消费数据而不必关心数据存于何处)

类似于数据库的表名

3 Partition

topic中的数据分割为一个或多个partition。每个topic至少有一个partition。每个partition中的数据使用多个segment文件存储。partition中的数据是有序的,不同partition间的数据丢失了数据的顺序。如果topic有多个partition,消费数据时就不能保证数据的顺序。在需要严格保证消息的消费顺序的场景下,需要将partition数目设为1。

[root@master kafka-log]# ll
总用量 16
-rw-r--r-- 1 root root   0 616 17:32 cleaner-offset-checkpoint
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-11
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-14
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-17
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-2
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-20
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-23
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-26
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-29
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-32
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-35
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-38
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-41
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-44
drwxr-xr-x 2 root root 178 618 02:36 __consumer_offsets-47
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-5
drwxr-xr-x 2 root root 141 616 18:50 __consumer_offsets-8
-rw-r--r-- 1 root root   4 618 22:48 log-start-offset-checkpoint
-rw-r--r-- 1 root root  88 618 02:36 meta.properties
-rw-r--r-- 1 root root 575 618 22:48 recovery-point-offset-checkpoint
-rw-r--r-- 1 root root 194 618 22:49 replication-offset-checkpoint
drwxr-xr-x 2 root root 141 618 16:46 topic_0618-1
drwxr-xr-x 2 root root 141 618 16:46 topic_0618-2
drwxr-xr-x 2 root root 141 618 16:46 topic_0618-3
[root@master kafka-log]# cd topic_0618-1
[root@master topic_0618-1]# ll
总用量 20480
-rw-r--r-- 1 root root 10485760 618 16:46 00000000000000000000.index
-rw-r--r-- 1 root root        0 618 16:46 00000000000000000000.log
-rw-r--r-- 1 root root 10485756 618 16:46 00000000000000000000.timeindex
-rw-r--r-- 1 root root        0 618 16:46 leader-epoch-checkpoint 

4 Producer

生产者即数据的发布者,该角色将消息发布到Kafka的topic中。broker接收到生产者发送的消息后,broker将该消息追加到当前用于追加数据的segment文件中。生产者发送的消息,存储到一个partition中,生产者也可以指定数据存储的partition。

5 Consumer

消费者可以从broker中读取数据。消费者可以消费多个topic中的数据。

6 Consumer Group

每个Consumer属于一个特定的Consumer Group(可为每个Consumer指定group name,若不指定group name则属于默认的group)

7 Leader

每个partition有多个副本,其中有且仅有一个作为Leader,Leader是当前负责数据的读写的partition。

8 Follower

Follower跟随Leader,所有写请求都通过Leader路由,数据变更会广播给所有Follower,Follower与Leader保持数据同步。如果Leader失效,则从Follower中选举出一个新的Leader。当Follower与Leader挂掉、卡住或者同步太慢,leader会把这个follower从“in sync replicas”(ISR)列表中删除,重新创建一个Follower。

9 zookeeper

元数据管理、控制器选举等

[zk: master:2181(CONNECTED) 0] ls /kafka
[cluster, controller_epoch, controller, brokers, admin, isr_change_notification, consumers, log_dir_event_notification, latest_producer_id_block, config]

10 Replic

分区副本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值