Setting Up and Running Apache Kafka on Windows OS

A step-by-step guide to installing and running Apache Zookeeper and Apache Kafka on a Windows OS.

 

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.        

Image title

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:

        Image title(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

Image title

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.

Image title

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.

Image title

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

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

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
 

Image title 

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

Image title
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
 

Image title

 

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:

Image title

 

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.

Image title

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

The Big Data Zone is brought to you in partnership with Exaptive.  Learn how Rapid Application Development powers business. 

 

 

[출처] https://dzone.com/articles/running-apache-kafka-on-windows-os

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 86063
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78588
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95313
31 오라클 컬럼명 찾기 졸리운_곰 2017.04.17 2030
30 [Oracle | 오라클] DB 덤프/임포트 하기 졸리운_곰 2017.03.17 1230
29 Oracle Data pump 실전 사용 졸리운_곰 2017.03.17 857
28 오라클 덤프 export / import file 졸리운_곰 2017.03.17 1348
27 오라클 DB 백업과 복원 졸리운_곰 2017.03.17 1776
26 SQL HINT 를 이용하여 SQL Tunning 을 하는 방법 file 졸리운_곰 2017.03.15 1303
25 <운바-DB> Oracle HINT(기초) file 졸리운_곰 2017.03.15 1532
24 조인 순서 조정을 위한 힌트(ordered, leading) 졸리운_곰 2017.03.15 1476
23 ORACLE Hint 정리 file 졸리운_곰 2017.03.15 1723
22 Oracle Hint 설명 및 사용법 졸리운_곰 2017.03.15 1558
21 ORACLE SQL 서버 및 PLSQL 코딩 표준 가이드 file 졸리운_곰 2017.01.14 1758
20 ORACLE SQL 튜닝 가이드 file 졸리운_곰 2014.06.07 3943
19 Oracle DECODE문을 IF문처럼 사용하기. 졸리운_곰 2014.01.25 2472
18 [ORACLE] NVL함수 & DECODE함수 졸리운_곰 2014.01.25 2468
17 ※ Oracle 오라클 DECODE 함수 file 졸리운_곰 2014.01.25 2769
16 오라클 백업 및 복구(Datapump) 졸리운_곰 2014.01.25 2122
15 (Oracle) delete 복구 졸리운_곰 2014.01.25 2420
14 오라클 쿼리 복구 졸리운_곰 2014.01.25 3450
13 오라클 플래쉬백 사용하기(Flashback Query) 졸리운_곰 2014.01.25 2603
12 체크 제약조건 적용사례 졸리운_곰 2014.01.19 3169
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED