kafka的簡單shell命令管理

2021-08-18 20:43:34 字數 3993 閱讀 5738

啟動kafka步驟

1、先啟動zookeeper(kafka自帶zookeeper的,可以啟動自身的)當前目錄為bin目錄上一級

./bin/zookeeper-server-start.sh config/zookeeper.properties &

(啟動後,基本上當前節點被日誌佔據了,後續操作另開視窗)

2、啟動kafka服務   當前目錄為bin目錄上一級

./bin/kafka-server-start.sh config/server.properties &

(啟動後,基本上當前節點被日誌佔據了,後續操作另開視窗)

3、建立乙個1備份1partitions的topic名為steve 

./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic steve

[root@vm_0_7_centos kafka2.10]# ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic stevetao

error while executing topic command topic "stevetao" already exists.

kafka.common.topicexist***ception: topic "stevetao" already exists.

at kafka.admin.adminutils$.createorupdatetopicpartitionassignmentpathinzk(adminutils.scala:187)

at kafka.admin.adminutils$.createtopic(adminutils.scala:172)

at kafka.admin.topiccommand$.createtopic(topiccommand.scala:93)

at kafka.admin.topiccommand$.main(topiccommand.scala:55)

at kafka.admin.topiccommand.main(topiccommand.scala)

[root@vm_0_7_centos kafka2.10]# ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic steven

created topic "steven".

檢視所有topic列表

[root@hdp1 kafka-0.10.0]# ./bin/kafka-topics.sh --zookeeper 172.17.70.14:2181 --list

[root@vm_0_7_centos kafka2.10]# ./bin/kafka-topics.sh --zookeeper localhost:2181 --list

hive-mdatabase-hostsltable

steve

steven

stevetao

檢視指定topic資訊

[root@hdp1 kafka-0.10.0]# ./bin/kafka-topics.sh --zookeeper 172.17.70.14:2181 --topic iot_ds_data(主題名) --describe

檢視consumer group列表,使用--list引數

檢視新版(資訊儲存在broker中)

./bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server  172.17.70.14:6667(kafkaip位址) --list

老版(資訊儲存在zookeeper中)

./bin/kafka-consumer-groups.sh --zookeeper  127.0.0.1:2181(zookeeperip位址) --list

./bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server  172.17.70.14:6667(kafkaip位址) --group mongods(組名) --describe

控制台向topic生產資料(steve為topic名;)         alt+c可以結束操作

./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic steve

[root@vm_0_7_centos kafka2.10]# ./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic steve

[2018-04-16 15:47:54,875] warn property topic is not valid (kafka.utils.verifiableproperties)

dsfdfd

zhangsan

lisi

控制台消費topic的資料(steve為topic名;)

./bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic steve --from-beginning

[root@vm_0_7_centos kafka2.10]# ./bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic steve --from-beginning

zdfd

dfadfaf\

dfadf

stevev

stevetao

zzzhngsan

dsfdfd

zhangsan

lisi^c consumed 10 messages

檢視topic某分割槽偏移量最大(小)值(steve為topic名;分割槽從0開始;time為-1時表示最大值,time為-2時表示最小值)

./bin/kafka-run-class.sh kafka.tools.getoffsetshell --topic steve --time -1 --broker-list localhost:9092 --partitions  0

[root@vm_0_7_centos kafka2.10]# ./bin/kafka-run-class.sh kafka.tools.getoffsetshell --topic steve --time -1 --broker-list localhost:9092 --partitions 0

steve:0:7

增加topic分割槽數10

bin/kafka-topics.sh --zookeeper localhost:2181  --alter --topic steve --partitions 10

刪除topic,慎用,只會刪除zookeeper中的元資料,訊息檔案須手動刪除

bin/kafka-run-class.sh kafka.admin.deletetopiccommand --zookeeper localhost:2181 --topic steve

檢視topic消費進度

bin/kafka-run-class.sh kafka.tools.consumeroffsetchecker

kafka相關shell命令

啟動kafkakafka server start.sh daemon opt kafka 2.11 2.0.0 config server.properties停止kafkakafka server stop.sh daemon opt kafka 2.11 2.0.0 config server...

Kafka集群的簡單使用(shell)

kafka本地集群搭建完成,介紹在shell中進行簡單使用,並記錄。cd opt zookeeper bin zkserver.sh startcd opt kafka bin kafka server start sh config server.properties 表示後台執行,這樣就可以啟動...

kafka簡單的啟動命令

我這裡的安裝目錄是 home bigdata kafka 節點名稱為 localhadoop1 進入安裝目錄後輸入 bin kafka server start.sh config server.properties 後台執行 bin kafka server start.sh config ser...