kafka經常使用的命令

一、啓動zookeeper

# ./zkServer.sh start

二、查看zookeeper是否啓動

# ps -ef |grep java

三、關閉zookeeper

# ./zkServer.sh stop

四、查看zookeeper的狀態

# ./zkServer.sh status

五、啓動kafka

# ./kafka-server-start.sh -daemon ../config/server.properties &

六、查看kafka是否啓動

# ps -ef |grep kafka

七、關閉kafka

# ./kafka-server-stop.sh

八、建立topic

# ./kafka-topics.sh --create --zookeeper 172.16.218.201:2181,172.16.218.202:2181,172.16.218.203:2181 --replication-factor 3 --partitions 1 --topic szy

九、查看全部topic

# ./kafka-topics.sh --list --zookeeper 172.16.218.201:2181,172.16.218.202:2181,172.16.218.203:2181

十、查看某個topic具體信息

# ./kafka-topics.sh --describe --zookeeper 172.16.218.201:2181,172.16.218.202:2181,172.16.218.203:2181 --topic szy

十一、刪除topic (可直接刪除的前提:delete.topic.enable=true)

# ./kafka-topics.sh --delete --zookeeper 172.16.218.201:2181,172.16.218.202:2181,172.16.218.203:2181 --topic test 
命令沒法刪除,topic被標記爲刪除時候,用下面命令刪除
# cd /usr/local/zookeeper-node3/bin/
# ./zkCli.sh
ls /brokers/topics
rmr /brokers/topics/【topic name】
quit

十二、生產消息

# ./kafka-console-producer.sh --broker-list 172.16.218.201:19092,172.16.218.202:19092,172.16.218.203:19092 --topic szy

1三、消費消息

# ./kafka-console-consumer.sh --zookeeper 172.16.218.201:2181,172.16.218.202:2181,172.16.218.203:2181  --topic szy --from-beginning
相關文章
相關標籤/搜索