Kafka命令

1、开启zookeeper、Kafka、kafka-manager服务(nohup …… &表示后台执行)

nohup bin/zkServer.sh start conf/zoo.cfg &

nohup bin/kafka-server-start.sh config/server.properties &

nohup ./kafka-manager-Dconfig.file=../conf/application.conf &

2. 创建topic(任意IP或localhost均可)

bin/kafka-topics.sh --create --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --replication-factor 2 --partitions 3 --topic test

bin/kafka-topics.sh --create --zookeeper 192.168.43.209:2181 --replication-factor 2 --partitions 1 --topic test2

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

3. 查看topic列表(任意IP或localhost均可)

bin/kafka-topics.sh --list --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181

bin/kafka-topics.sh --list --zookeeper 192.168.43.209:2181

bin/kafka-topics.sh --list --zookeeper localhost:2181

4. 查看topic详情(任意IP或localhost均可)

bin/kafka-topics.sh --describe --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --topic test1

bin/kafka-topics.sh --describe --zookeeper 192.168.43.209:2181 --topic test1

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

5. 发布者发布消息(任意IP均可,localhost不行)

bin/kafka-console-producer.sh --broker-list 192.168.43.209:9092,192.168.43.210:9092,192.168.43.211:9092 --topic test1

bin/kafka-console-producer.sh --broker-list 192.168.209:9092 --topic test1

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test1(不行)

6. 消费者消费消息(任意IP或localhost均可)

bin/kafka-console-consumer.sh --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --topic test1 --from-beginning

bin/kafka-console-consumer.sh --zookeeper 192.168.43.209:2181 --topic test1 --from-beginning

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

7. 删除topic(delete.topic.enable=true)

bin/kafka-topics.sh --delete --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --topic test

8. Kafka集群管理(网页)

firefox命令打开浏览器,输入如下网址:

192.168.43.209:9000

加权限控制之后:

9. 添加生产者权限

bin/kafka-acls.sh --add --authorizer-properties zookeeper.connect=192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --allow-principal User:sce --producer --topic=test

10. 添加消费者权限

bin/kafka-acls.sh --add --authorizer-properties zookeeper.connect=192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181  --allow-principal User:sce --consumer --group sce --topic=test15

11. 查看topic权限

bin/kafka-acls.sh --authorizer-properties zookeeper.connect=192.168.43.209:2181 --list --topic test2

12. 删除权限

bin/kafka-acls.sh --authorizer-properties zookeeper.connect=192.168.43.209:2181 --operation Write --operation Read --operation Describe --allow-principal User:admin --allow-host * --remove --topic test2

13. 发布消息

bin/kafka-console-producer.sh --broker-list 192.168.43.209:9092,192.168.43.210:9092,192.168.43.211:9092 --producer-property security.protocol=SASL_PLAINTEXT --producer-property sasl.mechanism=PLAIN --topic test15

14. 订阅消息

bin/kafka-console-consumer.sh --bootstrap-server 192.168.43.209:9092,192.168.43.210:9092,192.168.43.211:9092 --consumer-property security.protocol=SASL_PLAINTEXT --consumer-property sasl.mechanism=PLAIN --topic test3

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容