Win10配置安装Kafka
Win10配置安装Kafka前提jdkzookeeper下载安装单机配置运行集群配置运行附录官方文档前提jdkzookeeperzookeeper的安装配置见另一篇博文:https://blog.csdn.net/sndayYU/article/details/90718238下载网址:http://kafka.apache.org/downloads下载:kafka_2.12-2....
前提
jdk
zookeeper
zookeeper的安装配置见另一篇博文:https://blog.csdn.net/sndayYU/article/details/90718238
下载
网址:http://kafka.apache.org/downloads
下载:kafka_2.12-2.2.0.tgz
安装
1.解压到“D:\programGreen\kafka_2.12-2.2.0”
单机
配置
2.修改配置文件"config/server.properties"下面两个参数值;并在D盘建立目录“D:/programData/kafka/logs”
log.dirs=/programData/kafka/logs
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
运行
1.启动zookeeper的三台服务器,运行“D:\programGreen\zookeeper-3.4.9\bin”下的zkServer1.cmd、zkServer2.cmd、zkServer3.cmd。
2.启动kafka
C:\Windows\system32>d:
D:\>cd D:\programGreen\kafka_2.12-2.2.0
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-server-start.bat .\config\server.properties
3.创建一个主题,并用客户端发送消息
C:\Windows\system32>d:
D:\>cd D:\programGreen\kafka_2.12-2.2.0
D:\programGreen\kafka_2.12-2.2.0>bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test
>This is a message
>This is another message
>
4.启动消费者,可以看到客户端传来的消息。此时,在客户端输入的消息都将传到消费者端。
C:\Windows\system32>d:
D:\>cd D:\programGreen\kafka_2.12-2.2.0
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message
集群
配置
1.先参照单机配置
2.将“D:\programGreen\kafka_2.12-2.2.0\config”下的server.properties复制3份:server-0.properties、server-1.properties、server-2.properties,并修改其内部分内容,如下
# server-0.properties
broker.id=0
listeners=PLAINTEXT://:9092
log.dirs=/programData/kafka/logs-0
# server-1.properties
broker.id=1
listeners=PLAINTEXT://:9093
log.dirs=/programData/kafka/logs-1
# server-2.properties
broker.id=2
listeners=PLAINTEXT://:9094
log.dirs=/programData/kafka/logs-2
运行
1.启动3个节点
C:\Windows\system32>d:
D:\>cd D:\programGreen\kafka_2.12-2.2.0
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-server-start.bat .\config\server-0.properties &
C:\Windows\system32>d:
D:\>cd D:\programGreen\kafka_2.12-2.2.0
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-server-start.bat .\config\server-1.properties &
C:\Windows\system32>d:
D:\>cd D:\programGreen\kafka_2.12-2.2.0
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-server-start.bat .\config\server-2.properties &
2.创建一个复制因子为3的新主题,并运行“describe topics”命令查看哪个经纪人正在做什么
C:\Windows\system32>d:
D:\>cd D:\programGreen\kafka_2.12-2.2.0
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 3 --partitions 1 --topic my-replicated-topic
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-topics.bat --describe --bootstrap-server localhost:9092 --topic my-replicated-topic
Topic:my-replicated-topic PartitionCount:1 ReplicationFactor:3 Configs:segment.bytes=1073741824
Topic: my-replicated-topic Partition: 0 Leader: 0 Replicas: 0,1,2 Isr: 0,1,2
D:\programGreen\kafka_2.12-2.2.0>
3.发布消息
C:\Windows\system32>d:
D:\>cd D:\programGreen\kafka_2.12-2.2.0
D:\programGreen\kafka_2.12-2.2.0>.\bin\kafka-console-producer.bat --broker-list localhost:9092 --topic my-replicated-topic
'.\bin\kafka-console-producer.bat' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic my-replicated-topic
>Hello mytest!
>
4.启动消费端,接收消息,可以看到消费端能接收到“Hello mytest!”
D:\programGreen\kafka_2.12-2.2.0>.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --from-beginning --topic my-replicated-topic
5.测试兼容性
安装官方文档干掉主kafka后,消费者还能接收到消息,但本人测试已不能了—?????
C:\Windows\system32>wmic process where "caption = 'java.exe' and commandline like '%server-1.properties%'" get processid
ProcessId
20948
C:\Windows\system32>taskkill /pid 20948 /f
成功: 已终止 PID 为 20948 的进程。
C:\Windows\system32>
附录
官方文档
更多推荐
所有评论(0)