日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

查看当前服务器中的所有的topic,创建topic,删除topic,通过shell命令发送消息,通过shell消费消息,查看topic详情,对分区数进行修改

發布時間:2024/9/27 46 豆豆

一、 Kafka常用操作命令

? 查看當前服務器中的所有topic

[root@hadoop3 kafka]# bin/kafka-topics.sh --list --zookeeper hadoop11:2181 [root@hadoop3 kafka]#

信息寫入到
? 創建topic

[root@hadoop3 kafka]# bin/kafka-topics.sh --create --zookeeper hadoop11:2181 --replication-factor 1 -partitions 1 --topic test Created topic "test". [root@hadoop3 kafka]# bin/kafka-topics.sh --list --zookeeper hadoop11:2181 test

通過上面,可以看到已經創建了一個test的topic

? 刪除topic

[root@hadoop2 kafka]# bin/kafka-topics.sh --create --zookeeper hadoop11:2181 --replication-factor 1 -partitions 1 --topic test2 Created topic "test2". [root@hadoop2 kafka]# bin/kafka-topics.sh --list --zookeeper hadoop11:2181 itheima test test2 [root@hadoop2 kafka]# bin/kafka-topics.sh --delete --zookeeper hadoop11:2181 --topic test2 Topic test2 is marked for deletion. Note: This will have no impact if delete.topic.enable is not set to true. [root@hadoop2 kafka]# bin/kafka-topics.sh --list --zookeeper hadoop11:2181 itheima test [root@hadoop2 kafka]#

需要server.properties中設置delete.topic.enable=true否則只是標記刪除或者直接重啟。
? 通過shell命令發送消息
要注意的是要指定topic,表示要在哪個topic中生產消息,這里的topic需要時上面創建的topic

[root@hadoop3 kafka]# bin/kafka-console-producer.sh --broker-list hadoop1:9092 --topic test asdfasdfasd asdfasdf asdfasdf toto test tuto test2

注意命令中指定的–block-list hadoop1:9092,當改成hadoop2:9092時,也可以。

? 通過shell消費消息
要指明的是要使用哪個topic中的數據,這里的topic需要時上面創建的topic:

[root@hadoop3 kafka]# sh bin/kafka-console-consumer.sh --zookeeper hadoop11:2181 --from-beginning --topic test asdfasdfasd asdfasdf asdfasdf toto test tuto test2

注意:這里要指定消費那個topic,這里使用的是test.

? 查看消費位置

[root@hadoop3 kafka]# sh bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper hadoop11:2181 --group testGroup

? 查看某個Topic的詳情

[root@hadoop3 kafka]# sh bin/kafka-topics.sh --topic test --describe --zookeeper hadoop11:2181 Topic:test PartitionCount:1 ReplicationFactor:1 Configs:Topic: test Partition: 0 Leader: 0 Replicas: 0 Isr: 0 [root@hadoop3 kafka]#

? 對分區數進行修改

[root@hadoop3 kafka]# bin/kafka-topics.sh --zookeeper hadoop11:2181 -alter --partitions 15 --topic test WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected Adding partitions succeeded! [root@hadoop3 kafka]# 與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的查看当前服务器中的所有的topic,创建topic,删除topic,通过shell命令发送消息,通过shell消费消息,查看topic详情,对分区数进行修改的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。