1. 程式人生 > >kafka基本操作命令收集----持續更新中

kafka基本操作命令收集----持續更新中

檢視幫助資訊

bin/kafka-topics.sh --help

建立Topic

bin/kafka-topics.sh --create --topic test0 --zookeeper 192.168.187.146:2181 --config max.message.bytes=12800000 --config flush.messages=1 --partitions 5 --replication-factor 1

--create: 指定建立topic動作

--topic:指定新建topic的名稱

--zookeeper: 指定kafka連線zk的連線url,該值和server.properties檔案中的配置項{zookeeper.connect}一樣

--config:指定當前topic上有效的引數值

--partitions:指定當前建立的kafka分割槽數量,預設為1個

--replication-factor:指定每個分割槽的複製因子個數,預設1個

檢視當前Kafka叢集中Topic的情況

bin/kafka-topics.sh --list --zookeeper 192.168.187.146:2181

檢視Topic的分割槽和副本情況

bin/kafka-topics.sh --describe --zookeeper 192.168.187.146:2181  --topic test0

--describe: 指定是展示詳細資訊命令

--zookeeper: 指定kafka連線zk的連線url,該值和server.properties檔案中的配置項{zookeeper.connect}一樣

--topic:指定需要展示資料的topic名稱

Topic資訊修改

bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --config max.message.bytes=128000
bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --delete-config max.message.bytes
bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --partitions 10 
bin/kafka-topics.sh --zookeeper 192.168.187.146:2181 --alter --topic test0 --partitions 3 ## Kafka分割槽數量只允許增加,不允許減少

Topic刪除

預設情況下Kafka的Topic是沒法直接刪除的,需要進行相關引數配置

bin/kafka-topics.sh --delete --topic test0 --zookeeper 192.168.187.146:2181

Note: This will have no impact if delete.topic.enable is not set to true.## 預設情況下,刪除是標記刪除,沒有實際刪除這個Topic;如果執行刪除Topic,兩種方式:
方式一:通過delete命令刪除後,手動將本地磁碟以及zk上的相關topic的資訊刪除即可
方式二:配置server.properties檔案,給定引數delete.topic.enable=true,重啟kafka服務,此時執行delete命令表示允許進行Topic的刪除

檢視topic消費到的offset

命令:

bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 127.0.0.1:9092 --topic test0 --time -1