Home > Java > javaTutorial > body text

In-depth analysis of Kafka startup commands to quickly master Kafka

WBOY
Release: 2024-02-01 09:44:14
Original
790 people have browsed it

In-depth analysis of Kafka startup commands to quickly master Kafka

Detailed explanation of Kafka startup command

1. Start a single Broker

kafka-server-start.sh config/server.properties
Copy after login

This command will start a Kafka Broker and use config/server .properties as configuration file.

2. Start multiple Brokers

kafka-server-start.sh config/server-1.properties
kafka-server-start.sh config/server-2.properties
kafka-server-start.sh config/server-3.properties
Copy after login

This command will start three Kafka Brokers and use config/server-1.properties, config/server -2.properties and config/server-3.properties as configuration files.

3. Start ZooKeeper

zookeeper-server-start.sh config/zookeeper.properties
Copy after login

This command will start a ZooKeeper server and use config/zookeeper.properties as the configuration file.

4. Create Topic

kafka-topics.sh --create --topic test --partitions 3 --replication-factor 2
Copy after login

This command will create a Topic named test, which has 3 partitions and 2 replication factors.

5. Produce data

kafka-console-producer.sh --topic test
Copy after login

This command will start a console producer that sends data to the test Topic.

6. Consume data

kafka-console-consumer.sh --topic test --from-beginning
Copy after login

This command will start a console consumer, which will consume data from the beginning of the test Topic.

7. Stop Kafka

kafka-server-stop.sh
Copy after login

This command will stop all running Kafka Broker.

8. Stop ZooKeeper

zookeeper-server-stop.sh
Copy after login

This command will stop the ZooKeeper server.

Specific code examples

The following is a complete example that demonstrates how to start a Kafka cluster, create a Topic, produce data, consume data, and then stop the Kafka cluster.

# 启动ZooKeeper
zookeeper-server-start.sh config/zookeeper.properties

# 启动Kafka Broker
kafka-server-start.sh config/server-1.properties
kafka-server-start.sh config/server-2.properties
kafka-server-start.sh config/server-3.properties

# 创建Topic
kafka-topics.sh --create --topic test --partitions 3 --replication-factor 2

# 生产数据
kafka-console-producer.sh --topic test

# 消费数据
kafka-console-consumer.sh --topic test --from-beginning

# 停止Kafka
kafka-server-stop.sh

# 停止ZooKeeper
zookeeper-server-stop.sh
Copy after login

Notes

  • Before starting Kafka Broker, you must first start the ZooKeeper server.
  • Before creating a Topic, Kafka Broker must be started.
  • Before producing data, a Topic must be created first.
  • Before consuming data, data must be produced first.
  • Before stopping the Kafka cluster, you must first stop all running Kafka Brokers.
  • Before stopping the ZooKeeper server, you must first stop all running Kafka Brokers.

The above is the detailed content of In-depth analysis of Kafka startup commands to quickly master Kafka. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!