Kafka配置入门

Posted 读书使人进步

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kafka配置入门相关的知识,希望对你有一定的参考价值。

  在上一篇kafka简介的基础之上,本篇主要介绍如何快速的运行kafka。  

  在进行如下配置前,首先要启动Zookeeper。

配置单机kafka

1.进入kafka解压目录
2.启动kafka

bin\\windows\\kafka-server-start config\\server.properties

 3.创建Topic和查看机器上topic

bin\\windows\\kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic topic1
bin\\windows\\kafka-topics --list --zookeeper localhost:2181

 
4.发送数据

bin\\windows\\kafka-console-producer --broker-list localhost:9092 --topic topic1

5.开始消费数据

bin\\windows\\kafka-console-consumer --bootstrap-server localhost:9092 --topic topic1 --from-beginning

 

配置kafka集群

1.复制server.properties文件,并修改文件配置

broker.id=2
listeners=PLAINTEXT://:9094
log.dirs=E:\\kafka_2.11-0.10.2-2\\log

 2.启动kafka

bin\\windows\\kafka-server-start config\\server-1.properties
bin\\windows\\kafka-server-start config\\server-2.properties

 3.创建topic,然后查看集群详细信息

bin\\windows\\kafka-topics --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic topic-cluster
bin\\windows\\kafka-topics --describe --zookeeper localhost:2181 --topic topic-cluster

 

  第一行详细描述topic-cluster这个topic的集群信息。主要包括topic名称、分区数目、复制因子。后面的每一行描述一个分区信息,Partition:0表示该分区编号为0;Leader:0,表示该分区的Leader的broker.id为0;replicas为所在的broker.id;该分区的ISR为0、1、2.

4.向kafka集群发送数据

bin\\windows\\kafka-console-producer --broker-list localhost:9092 --topic topic-cluster

 

5.开始消费数据

bin\\windows\\kafka-console-consumer --bootstrap-server localhost:9092 --topic topic-cluster --from-beginning

 6.测试kafka集群失败恢复 杀死leader进程
7.查看集群信息

bin\\windows\\kafka-topics --describe --zookeeper localhost:2181 --topic topic-cluster

 

  此时可以发现,该分区的Leader和ISR都发生了改变.

8.重新消费数据

bin\\windows\\kafka-console-consumer --bootstrap-server localhost:9092 --topic topic-cluster --from-beginning

下一篇:Kafka学习-生产者和消费者

以上是关于Kafka配置入门的主要内容,如果未能解决你的问题,请参考以下文章

Kafka 入门--安装配置和 kafka-python 调用

[菜鸟SpringCloud实战入门]第八章:通过消息总线Bus实现配置文件统一刷新(使用Kafka)

kafka入门使用

kafka入门:简介使用场景主要配置

kafka入门:简介使用场景设计原理主要配置及集群搭建

kafka入门:简介使用场景设计原理主要配置及集群搭建(转)