文章目录
- Kafka常用命令
- kafka的基本操作(命令行操作)
- 1.启动集群:
- 2.查看当前服务器中的所有topic(在kafka目录下)
- 3.创建主题topic(在kafka目录下)
- 4.删除topic(在kafka目录下)
- 5.启动控制台生产者(在kafka目录下)
- 6.启动控制台消费者(在kafka目录下)(需要另外打开一个终端)
- 7.查看某个topic的详情(在kafka目录下)
- 8.修改分区数(在kafka目录下)
Kafka常用命令
kafka的基本操作(命令行操作)
1.启动集群:
$ bin/kafka-server-start.sh -daemon config/server.properties
$ bin/kafka-server-stop.sh stop
2.查看当前服务器中的所有topic(在kafka目录下)
$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --list
3.创建主题topic(在kafka目录下)
$ bin/kafka-topics.sh --create --zookeeper hadoop102:2181 --replication-factor 1 --partitions 1 --topic test
4.删除topic(在kafka目录下)
如:test
$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --delete --topic test
#需要server.properties中设置delete.topic.enable=true否则只是标记删除。
5.启动控制台生产者(在kafka目录下)
如:test
$ bin/kafka-console-producer.sh --bootstrap-server hadoop102:9092 --topic clicks
6.启动控制台消费者(在kafka目录下)(需要另外打开一个终端)
如:test
$ bin/kafka-console-consumer.sh --bootstrap-server hadoop102:9092 --topic test --from-beginning
我们一般先运行消费者,再去运行生产者
7.查看某个topic的详情(在kafka目录下)
$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --describe --topic test
8.修改分区数(在kafka目录下)
$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --alter --topic test --partitions 6
–topic 定义topic名
–replication-factor 定义副本数
–partitions 定义分区数
–from-beginning:会把主题中以往所有的数据都读取出来