# 2. Setup Kafka

FAQ for Setup Problems

**Please refer to this lecture first if you have setup problems.**

\=====================

**> Zookeeper - java.net.BindException: Address already in use**

Something is already occupying your port 2181. Figure out which application it is and stop it

**> Kafka - org.apache.kafka.common.KafkaException: Socket server failed to bind to 0.0.0.0:9092: Address already in use.**

Something is already occupying your port 9092. Figure out what it is and stop it.\
Otherwise, if you really insist, you can change the Kafka port by adding the following line to `server.properties`

```
# example for port 9093listeners=PLAINTEXT://:9093
```

**> My topics are losing their data after a while**

This is how Kafka works. Data is only retained for 7 days.

**> The topics list is disappearing**

Make sure you have changed the Zookeeper `dataDir=/path/to/data/zookeeper` , and Kafka `log.dirs=/path/to/data/kafka`

**> I have launched Kafka in a VM or in the Cloud, and I can't produce to Kafka**

If you can't produce to Kafka, it's possible you are using a VM and this can break the Kafka behaviour. Please look at the annex lectures for solutions of how to deal with that. I strongly recommend doing this tutorial using the Kafka binaries and localhost

If we set the path in bash file then we can access kafka anywhere from the terminal:

![](/files/-MDLskFGpDjaiF9U09QB)

Start Kafka & zookeeper on windows :

Edit zookeeper.properties which is inside kafka >> config folder .

![](/files/-MDLto1GjrF8Yr_w8V_3)

![](/files/-MDLu17dd5K-U9qskFNq)

+++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++

To start on windows :

1\) First place kafka on C drive:

a) create a data folder inside kafka&#x20;

b) inside data folder create two folders named kafka & zookeeper .

![](/files/-MDM-TaBwlFKOM4G9NRz)

2\) After doing chnages in server.properties file run the below command :

![](/files/-MDLyPUOLSKMOOjQPmB2)

![](/files/-MDLyEtlUlB5-yuFpufF)

3\) Now we can check that there is a new windows folder created & it contains all the bat file:

![](/files/-MDLyyl3dtsPjc6Uefjt)

4\) Add this path in environment variable :

![](/files/-MDLzUAkIsq5wD5GCf_h)

5\) Now from any dir we can start kafka :

![](/files/-MDLzpyrSnOqcy6isOnn)

6\) Edit zookeeper.properties file inside kafka >> config directory:

![](/files/-MDM-npsprXuYwbRHsVZ)

7\) Start zookeeper now with below command:

Make sure we are inside kafka folder then only we start zookeeper so that it can pick config file

**zookeeper-server-start.bat config\zookeeper.properties**

![](/files/-MDM-g9i8NjDvdLn88S0)

![](/files/-MDM0-XH8Z6D09QtPN-g)

8\) Start kafka thereafter :

go inside kafka folder :

**kafka-server-start.bat config\server.properties**

**WINDOWS SUMMARY :**

Windows - Summary

**In summary, for Windows**

1. Download and Setup **Java 8 JDK**
2. Download the Kafka binaries from <https://kafka.apache.org/downloads>
3. Extract Kafka at the root of `C:\`
4. Setup Kafka bins in the **Environment variables** section by editing **Path**
5. Try Kafka commands using `kafka-topics.bat` (for example)
6. Edit Zookeeper & Kafka configs using NotePad++ <https://notepad-plus-plus.org/download/>
   1. zookeeper.properties: `dataDir=C:/kafka_2.12-2.0.0/data/zookeeper` (yes the slashes are inversed)
   2. server.properties: `log.dirs=C:/kafka_2.12-2.0.0/data/kafka` (yes the slashes are inversed)
7. Start Zookeeper in one command line: `zookeeper-server-start.bat config\zookeeper.properties`
8. Start Kafka in **another** command line: `kafka-server-start.bat config\server.properties`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://architectures.gitbook.io/project/apahce-kafka/learn-apache-kafka-for-beginners-v2/starting-kafka/2.-setup-kafka.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
