kafka windows环境搭建

此博客中的kafka前提

在此文中使用的kafka版本为2.2.0,下载地址:二进制文件地址为:https://www.apache.org/dyn/closer.cgi?path=/kafka/2.2.0/kafka_2.12-2.2.0.tgz,
kafka在使用时需要zookeeper的支持,而在kafka2.2.0中已经集成了zookeeper 3.4.13版本,所以我将不再额外的进行zookeeper的下载与配置。
在这里插入图片描述

jdk配置

此版本的kafka对jdk的支持最低为1.8,若不想更改java_home配置可更改**kafka路径/bin/windows/kafka-server-start.bat**,在设置获取java_home的地方手动设置一个java_home,如图:

在这里插入图片描述

配置文件修改

配置文件位于 config目录下

zookeeper配置文件(zookeeper.properties)

默认的配置文件如下:
# the directory where the snapshot is stored.
dataDir=F:\\third\\kafka_2.12-2.2.0\\tmp\\zookeeper // 数据文件目录 默认是/tmp/zookeeper 需修改问windows上的 注意转义
# the port at which the clients will connect
clientPort=2181 //这里是配置zookeeper的端口 一般是不修改  其他软件配zookeeper地址就是IP:端口
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0 //这个配置是用来限制连接数的,如果设置为零 将忽略连接数的限制 如果大于0将限制

kafka配置文件(server.properties)

此配置中需要修改两个地方,第一个是zookeeper的连接地址,另一个就是kafka的ip和port了,我这边修改如下:

zookeeper的配置

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181  //其实这个地方不用改(除非你用虚拟机或改了zookeeper的配置) 

kafka的ip端口配置

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://localhost:9092  //这里我也是用的默认的 

启动

启动文件全部在bin下面,打开cmd跳转到"kafka安装目录/bin/windows"目录下

一,zookeeper启动

启动方式是:

zookeeper-server-start.bat <configfile> 
如下:
zookeeper-server-start.bat ../../config/zookeeper.properties

启动日志:
在这里插入图片描述

kafka启动

启动方式:

和zookeeper启动类似:
kafka-server-start.bat <configfile>
如下:
kafka-server-start.bat ../../config/server.properties

测试

kafka是消息队列 需要消息的生产则与消费者以及创建队列:

队列创建

创建命令:

这些命令都是kafka自带的测试脚本
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test1
--replication-factor 为副本数量 不能超过最大的服务器(brorker)的数量
--partitions 分区数量 合理的分区能够提高kafka的性能,以下为测试结果

在这里插入图片描述

队列消费者建立

命令:

kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test1
--bootstrap-server kafka服务地址 
--topic 队列名

在这里插入图片描述

队列生产者建立

命令:

kafka-console-producer.bat --broker-list localhost:9092 --topic test1
--borker-list 指定kafka队列地址

在这里插入图片描述

至此kafka的demo搭建已经初步完成,但是生产以及实际使用单节点肯定还是不足的 。在生产环境中像我们公司的测试环境都三个zookeeper+三个activeMQ来支撑大量数据
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值