Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common commands in Kafka

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the common commands in Kafka". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the common commands of Kafka"?

1. Open zookeeper (use the command in the installation directory)

Linux:bin/zkServer.sh start

Windows:bin\ zkServer.cmd

2. Start kafka (use the command in the installation directory)

Linux:bin/kafka-server-start.sh start config/server.properties

Windows:bin\ windows\ kafka-server-start.bat config\ server.properties

3. View the list of topic names

Linux:bin/kafka-topics.sh-list-- zookeeper 172.16.0.99 purl 2181172.16.0.218 purl 2181

Windows:bin\ windows\ kafka-topics.bat-list-- zookeeper 172.16.0.99 purl 2181172.16.0.218 purl 2181

4. View the details of topic

Linux:bin/kafka-topics.sh-zookeeper localhost:2181-topic test-describe

Windows:bin\ windows\ kafka-topics.bat-zookeeper localhost:2181-topic test-describe

5. Delete topic

Linux:bin/kafka-topics.sh-zookeeper localhost:2181-delete-topic "test"

Windows:bin\ windows\ kafka-topics.bat-zookeeper localhost:2181-delete-topic "test"

Note: one machine in the cluster deletes topic, while other machines delete the same topic synchronously.

6. Create topic

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

Windows:bin\ windows\ kafka-topics.bat-create-zookeeper localhost:2181-replication-factor 1-partitions 1-topic test

Note:

Replication-factor: the number of copies, generally less than or equal to the number of Broker.

Partitions: number of partitions. If the number of replicas is 1 and the partition is 4, the 4 partitions will be evenly distributed over each Broker. If the Broker is 2, the replica is 2, and the partition is 4, there are 4 partitions above each Broker.

7. Create Consumer

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

Windows:bin\ windows\ kafka-console-consumer.bat-zookeeper localhost:2181-topic test-form-beginning

Note: form beginning means to pull from scratch.

8. Create a Producer

Linux:bin/kafka-console-producer.sh-- broker-list 172.16.0.99 topic test 9020172.16.0.218

Windows:bin\ windows\ kafka-console-producer.bat-- broker-list 172.16.0.99 broker-list 9092172.16.0.218 topic test

Note: here is the port of kafka, and if you enter localhost here in the cluster, a connection error will be reported. It is assumed that the message did not reach the cluster, so enter all the ip of the cluster here.

9. Query the offset values of all topic partitions

Linux:bin/kafka-run-class.sh kafka.tools.GetOffsetShell-- broker-list 10.162.160.115 topic s1mmetest-- time-1

10. Query the number of messages in all current topic partitions of the kafka cluster

Linux:bin/kafka-run-class.sh kafka.tools.GetOffsetShell-- broker-list 132.232.78.175-- topic s1mmetest-- time-2

Reference: https://www.2cto.com/kf/201804/739331.html

At this point, I believe you have a deeper understanding of "what are the common commands in Kafka?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report