kafka(三)kafka命令操作
kafak 命令操作
在kafak 的 bin目录下 放着所有的启动和管理命令相关的脚本。
topic 管理
脚本: kafka-topics.sh
- 创建
1 | kafka-topics.sh --bootstrap-server 192.168.1.103:9092 --create --partitions 1 --replication-factor=1 --if-not-exists --topic test_01 |
create 表示创建topic
partitions 分片数量
replication-factor 副本数量
if-not-exists 不存在的时候创建
topic topic名称
- 查看列表
1 | kafka-topics.sh --bootstrap-server 192.168.1.103:9092 --list |

- 查看指定topic详细信息
1 | kafka-topics.sh --bootstrap-server 192.168.1.103:9092 --describe --topic test_01 |

- 修改topic的副本和分片信息,修改成3个
1 | kafka-topics.sh --bootstrap-server 192.168.1.103:9092 --alter --topic test_01 --partitions 3 |
- 对topic进行删除
1 | kafka-topics.sh --bootstrap-server hadoop1:9092 --delete --topic test_01 |
- 消费指定topic消息
1 | kafka-console-consumer.sh h --bootstrap-server 192.168.1.103:9092 --topic test_01 |
使用命令发送和消费消息
kafka-console-producer.sh 用来生产消息
kafka-console-consumer.sh 用来监听消费消息
当然这2个命令一般只在测试的时候使用,实际还是通过代码发送和监听。
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment


