mcr
kafka常⽤命令⾏操作(查看主题,⽣产数据,消费数据)⼀ topic相关操作
1.1 查看主题命令参数
[root@localhost kafka_2.12-2.1.0]# bin/kafka-topics.sh
1.2 查看集群中所有topic主题
[root@localhost kafka_2.12-2.1.0]# bin/kafka-topics.sh --list --zookeeper 192.168.152.138
kafka_test
英文简历范本[root@localhost kafka_2.12-2.1.0]#
1.3 创建主题
[root@localhost kafka_2.12-2.1.0]# bin/kafka-topics.sh --create --zookeeper 192.168.152.138:2181 --replication-factor 2 --partitions 3 --topic kafka_test
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to u either, but not both.
Created topic "kafka_test".
1.4 查看主题描述
[root@localhost kafka_2.12-2.1.0]# bin/kafka-topics.sh --describe --zookeeper 192.168.152.140:2181 --topic kafka_test Topic:kafka_test PartitionCount:3 ReplicationFactor:2 Configs:
evileyeTopic: kafka_test Partition: 0 Leader: 1 Replicas: 1,2 Isr: 2,1
Topic: kafka_test Partition: 1 Leader: 2 Replicas: 2,0 Isr: 2,0
Topic: kafka_test Partition: 2 Leader: 0 Replicas: 0,1 Isr: 1,0
解释:
第⼀⾏给出了所有分区的摘要。后⾯以下每⼀⾏给出⼀个partition中的信息,如果我们只有⼀个partition,则只显⽰⼀⾏。这⾥有3个分区,显⽰3⾏分区的详情信息。
集装箱 英文leader 是在给出的所有partitons中负责读写的节点(borker的id),每个节点都有可能成为leader
replicas 显⽰给定partiton所有副本所存储节点的节点列表(broker的id列表),不管该节点是否是leader或者是否存活。
isr 副本都已同步的的节点集合,这个集合中的所有节点都是存活状态,并且跟leader同步。
举例:
Topic: kafka_test Partition: 0 Leader: 1 Replicas: 1,2 Isr: 2,1
Topic: kafka_test Partition: 1 Leader: 2 Replicas: 2,0 Isr: 2,0
Topic: kafka_test Partition: 2 Leader: 0 Replicas: 0,1 Isr: 1,0
测试Kafka集群⼀共三个节点,第⼀⾏这个主题“kafka_test" 的编号为0的分区,leader(分区为0的的主分区)在borker的id为1的这个节点上,副本在borker的id为1,2的这两个节点上,并且所有副本都是存活的,并跟主节点broker.id=1这个节点进⾏同步。
tenleader:理解为分区 的主分区,replicas为分区的副本
考研网上确认leader,replicas后⾯的数字为borker的id值,节点的编号
1.5 ⽣产者
[root@localhost kafka_2.12-2.1.0]# bin/kafka-console-producer.sh --broker-list
192.168.152.136:9092,192.168.152.140:9092,192.168.152.138:9092 --topic kafka_test
>nihao changqingteng!
>Kafka是由Apache软件基⾦会开发的⼀个开源流处理平台compatible
>
1.6 消费者
[root@localhost kafka_2.12-2.1.0]# bin/kafka-console-consumer.sh --from-beginning --topic kafka_test --bootstrap-rver 192.168.152.136:9092,192.168.152.138:9092,192.168.152.140:9092
西安培华学院地址nihao changqingteng!
Kafka是由Apache软件基⾦会开发的⼀个开源流处理平台
1.7 修改主题
(注意:分区数只能增加,不能减少)
[root@localhost kafka_2.12-2.1.0]# bin/kafka-topics.sh --zookeeper 192.168.152.126:2181 --alter --topic kafka_test --partitions 5
^C[root@localhost kafka_2.12-2.1.0]# bin/kafka-topics.sh --zookeeper 192.168.152.136:2181 --alter --topic kafka_test --partitions 5
WARNING: If partitions are incread for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!
[root@localhost kafka_2.12-2.1.0]# bin/kafka-topics.sh --describe --zookeeper 192.168.152.140:2181 --topic kafka_test
Topic:kafka_test PartitionCount:5 ReplicationFactor:2 Configs:fuel是什么意思
Topic: kafka_test Partition: 0 Leader: 1 Replicas: 1,2 Isr: 2,1
Topic: kafka_test Partition: 1 Leader: 2 Replicas: 2,0 Isr: 2,0
Topic: kafka_test Partition: 2 Leader: 0 Replicas: 0,1 Isr: 1,0
Topic: kafka_test Partition: 3 Leader: 1 Replicas: 1,2 Isr: 1,2
Topic: kafka_test Partition: 4 Leader: 2 Replicas: 2,0 Isr: 2,0
[root@localhost kafka_2.12-2.1.0]#
1.8 删除主题
[root@localhost kafka_2.12-2.1.0]# b in/kafka-topics.sh --zookeeper 192.168.152.136:2181 --delete --topic kafka_test Topic kafka_test is marked for deletion.
英语 在线翻译Note: This will have no impact able is not t to true.
[root@localhost kafka_2.12-2.1.0]# bin/kafka-topics.sh --list --zookeeper 192.168.152.138
__consumer_offts
[root@localhost kafka_2.12-2.1.0]#
可以看到删除topic后,进⾏查看,查看不到了!