Kafka window 环境搭建

首先如图:


我搭建的时候先搭建的Zookeeper,然后再搭建Kafka;
1:下载zookeeper和kafka的安装包;
解压
2;解压后文件是 zookeeper-3.5.3;复制两份;
3:修改conf目录下面zoo.cfg文件;
zookeeper-3.5.3.1配置文件:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#dataDir=/tmp/zookeeper
#修改数据文件路径
dataDir=D:\\zookeeper\\zookeeper-3.5.3.1\\zkdata
#修改日记文件路径
dataLogDir=D:\\zookeeper\\zookeeper-3.5.3.1\\zkdatalog
# the port at which the clients will connect
#一共3个zookeeper所以对应的端口号是不一样的 我这边是 2181,2182,2183
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
#集群环境中有多个zookeeper
server.1=127.0.0.1:12888:1381
server.2=127.0.0.1:12889:1382
server.3=127.0.0.1:12887:1383
zookeeper-3.5.3.2配置文件:
zookeeper-3.5.3.3配置文件:
注意此处的dataDir路径和dataLogDir路径,如果项目中没有,建议自己创建好该目录;我是建在zookeeper里面的;
同时; 在配置的dataDir目录下面新建一个 myid 文件,文件内容就是对应的id号,
例如
zookeeper-3.5.3.1 程序 myid 文件的内容 为 1
zookeeper-3.5.3.2 程序 myid 文件的内容 为 2
zookeeper-3.5.3.3 程序 myid 文件的内容 为 3
如图:

忽略此处的version-2,这是服务启动之后生成的文件;

4:启动zookeeper
在对应的bin目录下启动
zkServer.cmd

5:安装kafka;
解压后到config文件夹下 打开server.properties配置文件进行配置
我的目录
kafka_2.11-1.1.0.1的配置文件 server.properties;
#唯一标识
broker.id=1
#监听端口 如果没有直接加 port 和 host.name
port=9091
host.name=127.0.0.1
#消息最大大小
message.max.bytes=50485760
#配置副本数量
default.replication.factor=2
#获取的最大大小
replica.fetch.max.bytes=50485760
#队列中消息持久化存放的位置,可以多个目录,用逗号分开, 如果你是一台机器搭建的,建议修改这个目录,我这边: log.dirs=../tmp/kafka-logs
log.dirs=/tmp/kafka-logs
#默认的分区数
num.partitions=2
#对应着刚刚配置的zookeeper的三个ip与端口地址; 主要此处的2181对应的是:zookeeper配置文件中的: clientPort 端口号
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183

6:在 对应 的server.properties中修改
#唯一标识
broker.id=1
broker.id=2
broker.id=3
#监听端口  
port=9091
port=9092
port=9093

7:启动对应的kafka
进入到bin/windows目录下 启动kafka并指定配置文件如下:
kafka-server-start.bat ../../config/server.properties

(1):如果报错:[Kafka][错误: 找不到或无法加载主类 Files\Java\jdk1.8.0_101\lib\dt.jar;C:\Program]
请参考: https://blog.csdn.net/cx2932350/article/details/78870135 中,先看解决办法2,不行看1;

(2):如果报错:Kafka:Configured broker.id 2 doesn't match stored broker.id 0 in meta.properties. 这个就是由于kafka中 log.dirs=/tmp/kafka-logs的问题,上面我提到了,
建议 log.dirs=../tmp/kafka-logs,如果不在同一个环境上面倒无所谓;

8:测试集群
(1)创建一个 topic
kafka-topics.bat --create --zookeeper 127.0.0.1:2181 --replication-factor 1 --partitions 1 --topic test
 
(2)查看是否创建成功
kafka-topics.bat --list --zookeeper localhost:2181
 
(3)发送消息
kafka-console-producer.bat --broker-list localhost:9092 --topic testThis is a message
 
(4)接收消息
kafka-console-consumer.bat --zookeeper localhost:2181 --topic test --from-beginning
 
不同客户端能接收到消息,说明配置成功;


参考的学习资料地址: https://www.cnblogs.com/lentoo/p/7785004.html
在此基础上稍作详解;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值