kafka常用命令

啟動(dòng)kafka

kafka-server-start.sh $KAFKA_HOME/config/server.properties
kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties
首次啟動(dòng)成功后,會(huì)在$KAFKA_HOME/logs目錄下創(chuàng)建相應(yīng)的日志文件

獲取Kafka進(jìn)程的PID
PIDS=$(jps | grep -i 'Kafka' | awk '{print 1}') 查看Kafka進(jìn)程PID echo \PIDS
殺掉Kafka進(jìn)程
kill -9 $PIDS

執(zhí)行jps命令查看Java進(jìn)程,此時(shí)進(jìn)程信息至少包括以下幾項(xiàng):

  • Jps
  • QuorumPeerMain
  • Kafka

查看topic

kafka-topics.sh --list --zookeeper localhost:2181

創(chuàng)建topic

kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic topicname

啟動(dòng)生產(chǎn)者

kafka-console-producer.sh --broker-list localhost:9092 --topic topicname

啟動(dòng)消費(fèi)者

kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic topicname

刪除topic

kafka-topics.sh --delete --zookeeper localhost:2181 --topic topicname
如果topic被正常刪除,查詢不到,說(shuō)明topic沒有被引用;如果被標(biāo)記為--marked for deletion,說(shuō)明還有對(duì)這個(gè)topic的引用

查看數(shù)據(jù)過(guò)期時(shí)間

kafka-configs.sh --zookeeper localhost:2181 --describe --entity-name my_first_topic --entity-type topics

修改數(shù)據(jù)過(guò)期時(shí)間

kafka-configs.sh --zookeeper localhost:2181 --alter --entity-name my_first_topic --entity-type topics --add-config retention.ms=86400000

查看主題數(shù)據(jù)偏移量

kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic task_instance_info --time -1

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容