1) This document provides instructions for setting up a single node Kafka cluster on Linux. It describes downloading required software, installing Java, Zookeeper and Kafka, and configuring the basic functionality of the Kafka cluster including creating topics, producing and consuming messages.
2) The key steps are downloading Java, Zookeeper, Kafka, installing Java, extracting and configuring Zookeeper to run on port 5181, extracting and configuring Kafka to connect to Zookeeper on port 5181 and run with one broker and 5 partitions.
3) Functionality is verified by starting Zookeeper and Kafka, creating and describing topics, producing messages to and consuming messages from topics.
2. Basics of Kafka &
Zookeeper
This slide covers the Kafka setup on a
VM running on Windows.
Apart from Kafka, we will install various other
software such as JDK, Zookeeper, VM etc.. That we
need to run Kafka.
We expect you have basic understanding of JDK,
and understand what is kafka and what is zookeepr
and their usage.
As, this slide does not cover the basics of these,
and we will straight forward discuss about setting
them up, we recommend you go through our other
slides to have some basic knowledge of them.
3. Download The
Required Software
What do we need to download?
[As on 30-Sep-2022]
1. Latest version of Apache Kafka
https://dlcdn.apache.org/kafka/3.2.3/kafka_2.12-3.2.3.tgz
2. Latest version of Apache Zookeeper
https://dlcdn.apache.org/zookeeper/zookeeper-
3.8.0/apache-zookeeper-3.8.0-bin.tar.gz
3. jdk-11.0.16.1_linux-x64_bin.tar.gz
https://www.oracle.com/java/technologies/downloads/
Additionally, If your machine is running on Windows Operating
System, download the following also:
1. VMware Workstation player 16 from
https://www.vmware.com/go/getplayer-win
2. Ubuntu 14.04.2 LTS from http://old-
releases.ubuntu.com/releases/14.04.2/ubuntu-14.04.5-
desktop-i386.iso
(Not mandatory to use Ubuntu-14.02 LTS, if your system is
having high configuration (RAM > 8 GB and Disk >1 TB),
you can go for latest version of Ubuntu)
4. Install the Software
on Windows
Systems
In order to persist the entire Kafka cluster environment on a
separate external Hard Disk, lets install the software in the
following order:
1. Install the VM Workstation
2. On top of it, install Linux OS, which is Ubuntu
Windows 10 will be the host OS and Ubuntu the guest OS where
single CPU of the system will be shared according to configured
value in VM Workstation
1. Install JDK
2. Install Kafka
3. Install Zookeeper
We will discuss the installation process of each of these
software one by one, in the coming slides
5. Installing VM
Workstation on
Windows Systems
Lets start with Installing the VM Workstation:
● Right click VMware-player-full-16.2.4-20089737.exe and select
Run as Administrator and follow the installation instruction.
● Installation Dialog Box will open.. Accept the End-user Licence
Agreement and click Next
6. Installing
VM Workstation
on Windows
● Keep clicking Next and finally click on Install, this will
start the installation process of Vmware Player. It may
take some time.
● Click on finish to complete the setup. Once installtion
is completed, VM player will start and you can see VM
Player Window with various options.
7. Installing Ubuntu
on Windows
Once VM Workstation is installed, we can setup Ubuntu on it.
● Click Create New Virtual Machine
● Locate the Ubantu iso file when asked
8. Installing
Ubuntu
on Windows
● Enter the Linux name of your choice, Username in
small letters and passwords and clcik next
● Enter Kafka Cluster name (without space), select the
location and click next.
9. Installing
Ubuntu
on Windows
● Increase the Disk Capacity to 50 GB and click Next
● On the next screen click on Customize Hardware and select 4
gb as minimum memory.
11. Installing
Ubuntu
on Windows
● This will take 10-15 minutes to complete the setup
● Once setup is completed, you will be able to see the below screen
● Enter the password, in this case : demo, and click on arrow.
13. Install JDK
Starting Ubuntu
Now since we have already VM Ware player and Ubuntu
installed, let start with installing JDK.
● Start VM Ware Player
● Start Ubuntu, it will ask for password, enter the password
(in this case “demo”)
● Double click on folder icon from left menu, once you are
inside Ubuntu, It will open the directory structure.
14. Install JDK
Extract JDK
● Create a folder (in this case Kafka-Softwares), where
we can keep installable files which we need to install
throughout this exercise.
● Now copy the installable from windows and paste it
inside Ubuntu under the newly created folder.
15. Install JDK
Extract JDK
● Once all the installable are copied under new folder, we will
first extract the JDK.
● Open a command terminal by typing CTRL+ALT+T
16. Install JDK
Extract JDK
Go to the directory location of JDK by using following
commands
● pwd (to check the current directory location)
● ls (to list the files and folders under current directory)
● cd Kafka-Softwares (use your folder name)
17. Install JDK
Extract JDK
● Once you reach the directory location of JDK, type
sudo tar -xvf JDK filename and then press enter
● This will extract the JDK tar ball
● Double click on the jdk folder and ensure java, javac
and javaws are there under bin folder
18. Install JDK
Setup Java Home
● Open the terminal by CNTRL+ALT+T
● Type command sudo vi /etc/profile
● Enter the password for root user, if asked
● Press enter to continue
● Bring the cursor to the bottom end of the file on last character
● Type I two times and press enter
● Now profile file will open in editor mode
● Add comments #Setting up Java Home Environment Variable
● Insert the following in the end
JAVA_HOME=/home/demo/Kafka-Softwares/jdk-11.0.16.1
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
● Type :wq and press enter to save the eateries.
● Type vi /etc/profile - To verify the changes made
● Type :q! - if you want to come out of vi editor
19. Install JDK
Install Java
Type the following commands to install Java:
● sudo update-alternatives --install ”/usr/bin/java” “java”
“/home/demo/Kafka-Softwares/jdk1.8.0_101/bin/java” 1
● sudo update-alternatives --install ”/usr/bin/javac” “javac”
“/home/demo/Kafka-Softwares/jdk1.8.0_101/bin/javac” 1
● sudo update-alternatives --install ”/usr/bin/javaws” “javaws”
“//home/demo/Kafka-Softwares/jdk1.8.0_101/bin/javaws” 1
20. Install JDK
Set Java Variable
Type the following commands to set the Java variables
● sudo update-alternatives –-set java /home/demo/Kafka-
Softwares/jdk1.8.0_101/bin/java
● sudo update-alternatives –-set javac /home/demo/Kafka-
Softwares/jdk1.8.0_101/bin/javac
● sudo update-alternatives –-set javaws /home/demo/Kafka-
Softwares/jdk1.8.0_101/bin/javaws
This completes the java installation
21. Install JDK
Verify
As we installed java, lets verify the same by using below
commands once by one.
● Type java -version to check if java installed properly and its
version
● type java
● type javac
If there is no error, you
have installed and setup
java successfully ☺
22. Install Zookeeper
Extract Zookeeper
Go to the location of Zookeeper and extract the tar ball
● Open the terminal by CNTRL+ALT+T
● Go to the folder where zookeeper tar ball is copied by using
the following commands:
● pwd (to check the current directory location)
● ls (to list the files and folders under current directory)
● cd Kafka-Softwares (use your folder name)
● Once you reach the directory location of Zookeeper, type
sudo tar -xvzf Zookeeper Filename and then press enter
● This will extract the Zookeeper tar ball and create a new
folder with the same name.
● Double click on the newly created zookeeper folder and
verify that it is extracted properly
23. Install Zookeeper
Move zookeeper folder
Move zookeeper folder to /usr/local/zookeeper folder
● Type command sudo mv apache-zookeeper-3.8.0-bin
/usr/local/zookeeper and press enter
● This will create a zookeeper folder under /usr/local/, you
may verify this by clicking on Computer under Devices
from left side menu and then visiting the location
usr>local
24. Install Zookeeper
Creating data directory and
logs directory
● Create data directory by using command mkdir
/usr/local/zookeeper/data
● Create logs directory by using command mkdir
/usr/local/zookeeper/logs
25. Install Zookeeper
Creating myid file under data
directory
● Type cd /usr/local/zookeeper/data to go to
/usr/local/zookeeper/data directory
● Now type echo “1” > /usr/local/zookeeper/data/myid
● This will create myid file under
/usr/local/zookeeper/data
● Verify the creation of myid file by going to data folder by
using command cd /usr/local/zookeeper/data/myid and
then use ls , this will display myid file
26. Install Zookeeper
Rename zoo_sample.cnf
● Type cd /usr/local/zookeeper/conf to go to conf folder
● Type mv zoo_sample.cnf zoo.cnf to change the name of
zoo_sample.cnf to zoo.cnf
27. Install Zookeeper
Modify zoo.cnf
● Type vi zoo.config , it will open the zoo.config file in vi
editor mode.
● Now scroll down using arrow keys to dataDir= and change
its value to /usr/local/zookeeper/data
● Make a new entry in the next line
dataLogDir=/usr/local/zookeeper/logs
● Go to the line where clientPort=2181 is mentioned and
change it to clientPort=5181
● Now, go to end of the file and add
server.1=localhost:2888:3888
● Type :wq and press enter to save the changes
● Type vi zoo.config to verify the changes
28. Install Zookeeper
Starting the Zookeeper
● Type cd /usr/local/zookeeper/bin
● Type ls to see the list of files under bin directory
● Type -/zkServer.sh start to start the zookeeper, and you should see STARTED
message upon successful start of zookeeper
This completes Zookeeper
setup
29. Install Kafka
Extract Kafka
Go to the location of Kafka and extract the tar ball
● Open the terminal by CNTRL+ALT+T
● Go to the folder where kafka tar ball is copied by using
the following commands:
● pwd (to check the current directory location)
● ls (to list the files and folders under current directory)
● cd Kafka-Softwares (use your folder name)
● Once you reach the directory location of Kafka, type
sudo tar -xvzf Kafka Filename and then press enter
● This will extract the Kafka tar ball and create a new
folder with the same name.
● Double click on the newly created kafka folder and verify
that it is extracted properly
30. Install Kafka
Move kafka folder
Move kafka folder to /usr/local/kafka folder
● Type command sudo mv kafka_2.12-3.2.3
/usr/local/kafka and press enter
● This will create a kafka folder under /usr/local/, you may
verify this by clicking on Computer under Devices from
left side menu and then visiting the location usr>local
31. Install Kafka
Modify server.properties
● Type vi /usr/local/kafka/config/server.properties to open the
server.properties file in vi editor
● Now scroll down using arrow keys to broker_id=0 and change it to
broker_id=1
● Scroll down further to see log.dirs.=/tmp/kafka-log
● Scroll down further to change num.partitions=1 to num.partitions=5
● Scroll down further to change zookeeper.connect=localhost:2181
to zookeeper.connect=localhost:5181
● Scroll down further to end of the file and add
delete.topic.enable=true
● Type :wq and press enter to save the changes
● Type Type vi /usr/local/kafka/config/server.properties to verify the
changes made
● Type :q! to come out of vi editor
32. Install Kafka
Start zookeeper and kafka
● Now type cd /user/local/zookeeper/bin
● Type ./zkServer.sh start to start zookeeper
● Now type cd /user/local/kafka/bin
● Type ./kafka-server-start.sh ../config/server.properties to
start kafka server using server.properties file.
33. Install Kafka
Creating Kafka Topic
● Now type cd /user/local/kafka/bin
● Type ./kafka-server-start.sh ./kafka-topics.sh –bootstrap-
server localhost:9002 –create –replication-factor 1 –
partitions 2 –topic firstTopic
● This will create a Topic named firstTopic
● Verify this by typing Type ./kafka-server-start.sh ./kafka-
topics.sh –bootstrap-server localhost:9002 –list
34. Install Kafka
Looking into details of Kafka
Topic
● Type ./kafka-server-start.sh ./kafka-topics.sh –bootstrap-
server localhost:9002 –topic firstTopic –describe to see the
details of the topic firstTopic
35. Install Kafka
Kafka Producer & Consumer
● We can see two files Kafka-console-producer.sh and kafka-
console-consumer.sh under /usr/local/kafka/bin
36. Install Kafka
Publishing Messages on Kafka
Topic
● Go to /usr/local/kafka/bin and type ./kafka-console-
producer.sh --bootstrap-server localhost:9092 --topic
firstTopic and press enter
● Type any random message (e.g. Hi) and press enter
● This will publish the message on the topic firstTopic.
37. Install Kafka
Consuming message from
Kafka Topic
● Now open another terminal by typing CLTR+ALT+T
● Type /usr/local/kafka/bin and press enter
● Type ./kafka-console-consumer.sh –bootstrap-server
localhost:9092 --topic firstTopic --from beginning and press
enter
● You can see messages sent by publisher are getting consumed
and published here.
● Keep publishing new messages on publisher and same will be
consumed by consumer at run time.
38. Install Kafka
Stopping the publisher and
consumer scripts
● Type CLTR+C one by one in each terminal of publisher and
consumer.
● This will stop the publisher and consumer scripts
● Type exit to close the terminals
39. Install Kafka
Stopping zookeeper & kafka
servers
● Go to /usr/local/zookeeper/bin and press enter
● Type ./zkServer.sh stop
● This will stop zookeeper server
● Go to /usr/local/kafka/bin and press enter
● Type ./kafka-server-stop.sh stop
● This will stop kafka server
40. Install Kafka
Looking into Kafka Logs
● Open a new terminal by typing CTRL+ALT+T and type sudo
mkdir /usr/local/kafka-logs and press enter
● Enter the password (in this case “demo”) if asked
● Now go to the kafka bin directory by typing /usr/local/kafka/bin
● Open server.properties file in vi editor in another terminal by
typing vi /usr/local/kafka/config/server.properties
● Scroll down to logs.dirs. And change its value to
/home/demo/kafka.logs
● Type :wq to save
● Go to cd /usr/local/zookeeper/bin
● Type ./zkServer.sh start
● Now type cd /user/local/kafka/bin
● Type ./kafka-server-start.sh ../config/server.properties to start
kafka server
41. Install Kafka
Looking into Kafka Logs
● Now switch to the terminal of /kafka-logs
● Now browse through the directory by clicking on home/kafka-
logs
● Check for meta.properties file
42. Install Kafka
Looking into Kafka Logs
● Right click on meta.properties file and open it in office
application to view its content
● You can brose through different logs same way.
This Complete Kafka
setup