*** 保证kafka和zookeeper已经在linux上进行了安装,目录需要改为自己的目录
*** kafka2.8之后引入了kraft机制,不用zookeeper也能启动
参数介绍
--create 创建一个topic
--topic [your_topic_name] 创建的topic的信息
--describe 描述信息
--bootstrap-server [host_url] 指定的服务器地址
--from-beginning 表示从什么地方开始获取信息
开启zookeeper
/mydata/zookeeper/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start
开启kafka
/mydata/kafka/kafka_2.12-3.5.0/bin/kafka-server-start.sh /mydata/kafka/kafka_2.12-3.5.0/config/server.properties
创建一个topic
$ bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092
显示使用信息和分区计数信息
$ bin/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092
Topic: quickstart-events TopicId: NPmZHyhbR9y00wMglMH2sg PartitionCount: 1 ReplicationFactor: 1 Configs:
Topic: quickstart-events Partition: 0 Leader: 0 Replicas: 0 Isr: 0
开启生产者,向其中写入消息
& bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
>This is my first event
>This is my second event
开启消费者,读取消息
$ bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092
This is my first event
This is my second event
标签:bin,quickstart,简单,--,kafka3,kafka,topic,使用,server From: https://www.cnblogs.com/huoziqi/p/17693638.html