Learning Kafka - Installing Kafka, starting a Kafka Cluster & creating a Topic
Contents
Steps
Install Kafka
-
Download Kafka from Kafka Apache Downloads
-
Extract Kafka in a directory
tar -xvf <filename-downloaded>
(eg./home/demouser/kafka/
) -
Check if Kafka is working - Go to folder where you have extracted the downloaded Tar file and run
bin/kafka-topics.sh
-
Add Kafka to Path
-
Update
.bashrc
export PATH="/home/demouser/kafka/kafka_2.12-2.2.0/bin:$PATH"
-
Update
.zshrc
export PATH="/home/demouser/kafka/kafka_2.12-2.2.0/bin:$PATH"
-
-
Check if Kafka is added to Path - Open a new terminal and run
kafka-topics.sh --version
Create a Kafka Cluster
Start Zookeeper
-
Go to Directory where you extracted the downloaded Tar file
/home/demouser/kafka/kafka_2.12-2.2.0/
-
Create directory
data
- Create directory
data/zookeeper
- Create directory
-
Modify properties for Zookeeper
-
nano config/zookeeper.properties
-
Modify
dataDir=/home/demouser/kafka/kafka_2.12-2.2.0/data/zookeeper
tozookeeper.properties
-
Save and Exit
-
-
Start Zookeeper
-
Go to directory
/home/demouser/kafka/kafka_2.12-2.2.0
-
zookeeper-server-start.sh config/zookeeper.properties
-
If Zookeeper starts successfully it’ll bind to port 2181
-
Start Kafka
-
Go to Directory
/home/demouser/kafka/kafka_2.12-2.2.0/
-
Create directory
data/kafka
-
Modify properties for Kafka
-
nano config/server.properties
-
Modify
log.dirs=/home/divyanshu/kafka/kafka_2.12-2.2.0/data/kafka
toserver.properties
-
Save and Exit
-
-
Start Kafka
-
Go to Directory
/home/demouser/kafka/kafka_2.12-2.2.0/
-
kafka-server-start.sh config/server.properties
(Remember to keep Zookeeper running from the earlier step) -
If Kafka starts successfully we get a Kafka Started message
-
Create a Kafka Topic with 3 partitions and a replication factor of 1
-
Go to Directory
/home/demouser/kafka/kafka_2.12-2.2.0/
-
Create Kafka Topic -
kafka-topics.sh --zookeeper 127.0.0.1:2181 --topic first_topic --create --partitions 3 --replication-factor 1
-
List info about a Kafka Topic -
kafka-topics.sh --zookeeper 127.0.0.1:2181 --topic first_topic --describe