Setting Up and Running Apache Kafka on Windows

Stella981
• 阅读 613

Introduction

This article is all about configuring and starting an Apache Kafka server on a Windows OS. This guide will also provide instructions to set up Java and Apache Zookeeper.

Apache Kafka is a fast and scalable messaging queue, capable of handeling heavy loads in context of read and write, i.e. IO-related stuff. You can find more about Kafka on http://kafka.apache.org/. Apache Kafka requires a running Zookeeper instance, which is used for reliable distributed cordination. Please find more about Zookeeper on https://zookeeper.apache.org/.

You can find help from this video for setting up Kafka on Windows.

Downloading the Required Files

For this tutorial we are assuming that Zookeeper and Kafka are unzipped in C: drive, but you can unzip them in any location.

Here we are using full-fledged zookeeper and not the one packaged with Kafka because it will be single-node Zookeeper instance. If you want you can run Kafka with packaged zookeeper located in Kafka package inside \kafka\bin\windows directory.

Installation

A. JDK Setup

1. Start JRE installation and hit the check box “Change destination folder”, then click install.        

Setting Up and Running Apache Kafka on Windows

2. Change the installation directory to any path without spaces in folder name. E.g. C:\Java\jre1.8.0_xx\. (By default it will be C:\Program Files\Java\jre1.8.0_xx) then click Next.

3. Now open the system environment variables dialogue by opening Control Panel -> System -> Advanced system settings -> Environment Variables.

4. Hit the New User Variable button in User variables section then type JAVA_HOME in_Variable name_ and give your jre path in Variable value. It should look like:

        Setting Up and Running Apache Kafka on Windows (Java path and version may change according to the version of Kafka you are using)

5. Now click OK.

6. Search for a Path variable in the “System Variable” section in “Environment Variables” dialogue box you just opened.

7. Edit the path and type “;%JAVA_HOME%\bin” at the end of the text already written there just like image below

Setting Up and Running Apache Kafka on Windows

8. To confirm the Java installation just open cmd and type “java –version”, you should be able to see version of the java you just installed.

Setting Up and Running Apache Kafka on Windows

If your command prompt somewhat looks like the image above, you are good to go. Otherwise you need to recheck whether your setup version is matching with the correct OS architecture (x86, x64), or if the environment variables path is correct.

B. Zookeeper Installation

1. Goto your Zookeeper config directory. For me its C:\zookeeper-3.4.7\conf

2. Rename file “zoo_sample.cfg” to “zoo.cfg”

3. Open zoo.cfg in any text editor like notepad but I prefer notepad++.

4. Find & edit dataDir=/tmp/zookeeper to :\zookeeper-3.4.7\data

5. Add entry in System Environment Variables as we did for Java

    a. Add in System Variables ZOOKEEPER_HOME = C:\zookeeper-3.4.7

    b. Edit System Variable named “Path” add ;%ZOOKEEPER_HOME%\bin;

6. You can change the default Zookeeper port in zoo.cfg file (Default port 2181).

7. Run Zookeeper by opening a new cmd and type zkserver.

8. You will see the command prompt with some details like the image below.

Setting Up and Running Apache Kafka on Windows

Congratulations, your Zookeeper is up and running on port 2181!

C. Setting Up Kafka

1. Go to your Kafka config directory. For me its C:\kafka_2.11-0.9.0.0\config

2. Edit file “server.properties”

3. Find & edit line “log.dirs=/tmp/kafka-logs” to “log.dir= C:\kafka_2.11-0.9.0.0\kafka-logs”.

4. If your Zookeeper is running on some other machine or cluster you can edit_“zookeeper.connect:2181”_ to your custom IP and port. For this demo we are using same machine so no need to change. Also Kafka port & broker.id are configurable in this file. Leave other settings as it is.

5. Your Kafka will run on default port 9092 & connect to zookeeper’s default port which is 2181.

D. Running Kafka Server

Important: Please ensure that your Zookeeper instance is up and running before starting a Kafka server.

1. Go to your Kafka installation directory _C:\kafka_2.11-0.9.0.0\_

2. Open a command prompt here by pressing Shift + right click and choose“Open command window here” option)

3. Now type .\bin\windows\kafka-server-start.bat .\config\server.properties and press Enter.

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

Setting Up and Running Apache Kafka on Windows  

4. If everything went fine, your command prompt will look like this one:

Setting Up and Running Apache Kafka on Windows
5. Now your Kafka is up and running, you can create topics to store messages. Also we can produce or consume data from Java or Scala code or directly from the command prompt.

E. Creating topics

1. Now create a topic with name “test” and replication factor 1, as we have only one Kafka server running. If you have a cluster with more than 1 Kafka server running, you can increase the replication-factor accordingly which will increase the data availability and act like a fault-tolerant system.

2. Open a new command prompt in the location C:\kafka_2.11-0.9.0.0\bin\windows

3. Type following command and hit Enter:

kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

Setting Up and Running Apache Kafka on Windows

F. Creating a Producer and Consumer to Test Server

1. Open a new command prompt in the location C:\kafka_2.11-0.9.0.0\bin\windows

2. To start a producer type the following command:

kafka-console-producer.bat --broker-list localhost:9092 --topic test

3. Again open a new command prompt in the same location as C:\kafka_2.11-0.9.0.0\bin\windows

4. Now start a consumer by typing the following command:

kafka-console-consumer.bat --zookeeper localhost:2181 --topic test

5. Now you will have two command prompts like the image below:

Setting Up and Running Apache Kafka on Windows

6. Now type anything in the producer command prompt and press Enter, and you should be able to see the message in the other consumer command prompt.

Setting Up and Running Apache Kafka on Windows

7. If you are able to push & see your messages in the consumer side, you are done with Kafka setup.

Some Other Useful Commands

  1. List Topics: kafka-topics.bat --list --zookeeper localhost:2181
  2. Describe Topic: kafka-topics.bat --describe --zookeeper localhost:2181 --topic [Topic Name]
  3. Read messages from beginning: kafka-console-consumer.bat --zookeeper localhost:2181 --topic [Topic Name] --from-beginning
  4. Delete Topic: kafka-run-class.bat kafka.admin.TopicCommand --delete --topic [topic_to_delete] --zookeeper localhost:2181
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
4个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Stella981 Stella981
3年前
Spring Boot日志集成
!(https://oscimg.oschina.net/oscnet/1bde8e8d00e848be8b84e9d1d44c9e5c.jpg)SpringBoot日志框架SpringBoot支持JavaUtilLogging,Log4j2,Lockback作为日志框架,如果你使用star
Stella981 Stella981
3年前
Redis 6.0 正式版终于发布了!除了多线程还有什么新功能?
!(https://oscimg.oschina.net/oscnet/b8c8b22b9f44bd806c26b486e1893a263a4.jpg)这是我的第56篇原创文章!(https://oscimg.oschina.net/oscnet/8bf00bc92f6a1cd46596ee44bac64a801ae.pn
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
10个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这