How to install Kafka on Windows?
Ok, it's finally not complicated :)
The only steps are:
Edit (2021/10) Latest versions of Kafka end up with an AccessDeniedException
upon startup, and even when successfully started, throw the same error during log rotation. Kafka utilizes Java methods designed for Unix filesystem libraries, so installing Kafka in WSL2 is recommended (link to Confluent blog, but steps also applicable to Apache Kafka direct installation).
Old answer
- Download Kafka and uncompress it somewhere nice (let's say
C:/Kafka
) - Install Cygwin
If using Cygwin, edit \bin\kafka-run-class.sh
and at the end of the file, change
`exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"`
to
``exec java $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp `cygpath -wp $CLASSPATH` $KAFKA_OPTS "$@"``
- In Environment Variables, Add java to your Path System Variable:
That's it.. you can now run ZooKeeper and Kafka servers and start playing with topics and stuff..
You will probably find that Kafka comes with Windows .bat files under the bin folder to help you run Kafka under windows. However, those bat files are not updated since version 0.8.0 and some of Kafka's logic has changed (regarding topics, etc.).
I have tried two ways to solve this problem. One is to use Cygwin or MinGW to simulate Linux environment and run the Linux shell script, but there would be tons of other problems related to path names. The other solution, which is simpler and come with less trouble, is to use the corrected version of Windows bat files.
Please refer to this blog post.
Download any binary version(I've downloaded kafka_2.11-0.10.2.0) of Kafka from https://kafka.apache.org/downloads
Extract it to any folder(I've extracted to "C:\Kafka")
Open Command Prompt
Go to the folder that you extract Kafka(C:\Kafka\kafka_2.11-0.10.2.0)
Run this command to start Zookeeper
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
Run this command to start Kafka
.\bin\windows\kafka-server-start.bat .\config\server.properties
Now it works!
These are the steps I followed to run kafka on Windows
- Install Zookeeper first (I downloaded v3.3.6)
zookeeper-3.3.6.tar.gz
- Extract Zookeeper and run this command in powershell/cmd
\zookeeper-3.3.6\bin> .\zkServer.cmd
Now this should up a Zookeeper instance onlocalhost:2181
- Download Kafka binary version (I downloaded v0.10.0.1)
kafka_2.10-0.10.0.1.tgz
- Extract Kafka, time to modify some configs
- Inside Kafka extraction you can find
.\config\server.properties
- In
.\config\server.properties
replacelog.dirs=c:/kafka/kafka-logs
- Note: Make sure to create those folders in relevant paths
- Happy news: Now Kafka ships with windows .bat scripts, You can find these files inside
./bin/windows
folder - Start powershell/cmd and run this command to start Kafka broker
.\bin\windows\kafka-server-start.bat .\config\server.properties
- DONE!, Now you have a running Zookeeper instance and a Kafka broker.