打赏

1.3 Quick Start中 Step 3: Create a topic官网剖析(博主推荐)

 

 

不多说,直接上干货!

 

  一切来源于官网

http://kafka.apache.org/documentation/

 

 

 

 

Step 3: Create a topic

Step 3: 创建一个主题(topic)

 

  Let's create a topic named "test" with a single partition and only one replica:

创建一个名为“test”的Topic,只有一个分区和一个备份:
 
> bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

  We can now see that topic if we run the list topic command:

创建好之后,可以通过运行以下命令,查看已创建的topic信息:
> bin/kafka-topics.sh --list --zookeeper localhost:2181
test

  Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

或者,除了手工创建topic外,你也可以配置你的broker,当发布一个不存在的topic时自动创建topic。

 

 

 

  

 

  其实,这个很简单,比如--create就是创建,--list是查看。当然,不能局限于官网,大家要灵活多变,官网只是个参考和引子。

--topic test  名字为test的topic
--partitions 1   分区数为1
--replication-factor 1    复制因子是1(即每个分区在集群中有1份数据)
--zookeeper localhost:2181  这个不多说,太简单

 


   比如,我们一般写

bin/kafka-topics.sh --create --zookeeper master:2181 --replication-factor 3 --partitions 10 --topic t-behavior

bin/kafka-topics.sh --create --zookeeper hadoop1:2181 --replication-factor 3 --partitions 10 --topic t-behavior
说明:

--replication-factor 3     指定了复制因子3,即每个分区在集群中有3份数据

--partitions  10          指定topic的分区数10
--topic t-behavior       指定创建名为t-behavior的topic

 

 

 

 同时,查看topic详情

bin/kafka-topics.sh --zookeeper txy001:2181 --topic t-behavior --describe
打印如下:
Topic:t-behavior  PartitionCount:10       ReplicationFactor:3     Configs:
        Topic: t-behavior Partition: 0    Leader: 1       Replicas: 1,2,0 Isr: 0,1,2
        Topic: t-behavior Partition: 1    Leader: 2       Replicas: 2,0,1 Isr: 0,1,2
        Topic: t-behavior Partition: 2    Leader: 0       Replicas: 0,1,2 Isr: 0,1,2
        Topic: t-behavior Partition: 3    Leader: 1       Replicas: 1,0,2 Isr: 0,1,2
        Topic: t-behavior Partition: 4    Leader: 2       Replicas: 2,1,0 Isr: 0,1,2
        Topic: t-behavior Partition: 5    Leader: 0       Replicas: 0,2,1 Isr: 0,1,2
        Topic: t-behavior Partition: 6    Leader: 1       Replicas: 1,2,0 Isr: 0,1,2
        Topic: t-behavior Partition: 7    Leader: 2       Replicas: 2,0,1 Isr: 0,1,2
        Topic: t-behavior Partition: 8    Leader: 0       Replicas: 0,1,2 Isr: 0,1,2
        Topic: t-behavior Partition: 9    Leader: 1       Replicas: 1,0,2 Isr: 0,1,2
说明;
ReplicationFactor 表示复制因子,即每个分区有几份数据
Leader 分区的主在那个broker上
Replicas 表示分区数据分布在哪些broker上
Isr 表示可立即作为分区的主的broker,即标识3分数据已经保持一致了。

 

 

 

 

      over

posted @ 2017-04-26 09:01  大数据和AI躺过的坑  阅读(334)  评论(0编辑  收藏  举报