Sunday, July 22, 2018

Deploying Kafka into ubuntu

Apache Kafka is a distributed message broker designed to handle large volumes of real-time data efficiently. Unlike traditional brokers like ActiveMQ and RabbitMQ, Kafka runs as a cluster of one or more servers which makes it highly scalable and due to this distributed nature it has inbuilt fault-tolerance while delivering higher throughput when compared to its counterparts

 Implementation Steps Single Node

3.1. Installing a Single Node Kafka

3.1.1. Installing Java

sudo apt-get update
sudo apt-get install default-jre

3.1.2. Installing zookeeper

sudo apt-get install zookeeperd

3.1.3. Create a service User for Kafka

sudo adduser --system --no-create-home --disabled-password --disabled-login kafka

3.1.4. Installing Kafka

3.1.5. Download Kafka

cd ~

curl | gpg --import
gpg --verify kafka_2.12-1.0.1.tgz.asc kafka_2.12-1.0.1.tgz

3.1.6. Create a directory for extracting Kafka

sudo mkdir /opt/kafka
sudo tar -xvzf kafka_2.12-1.0.1.tgz --directory /opt/kafka --strip-components 1

3.1.7. Delete Kafka tarball and .asc file

rm -rf kafka_2.12-1.0.1.tgz kafka_2.12-1.0.1.tgz.asc

3.1.8. Configuring Kafka Server

Setup Kafka to start automatically on bootup

Copy the following init script to /etc/init.d/kafka:
# Check that networking is up.
#[ ${NETWORKING} = "no" ] && exit 0


# See how we were called.
case "$1" in
       # Start daemon.
       echo "Starting $DAEMON_NAME";
       nohup $DAEMON_PATH/ -daemon /opt/kafka/config/
       # Stop daemons.
       echo "Shutting down $DAEMON_NAME";
       pid=`ps ax | grep -i 'kafka.Kafka' | grep -v grep | awk '{print $1}'`
       if [ -n "$pid" ]
         kill -9 $pid
         echo "Kafka was not Running"
       $0 stop
       sleep 2
       $0 start
       pid=`ps ax | grep -i 'kafka.Kafka' | grep -v grep | awk '{print $1}'`
       if [ -n "$pid" ]
         echo "Kafka is Running as PID: $pid"
         echo "Kafka is not Running"
       echo "Usage: $0 {start|stop|restart|status}"
       exit 1

exit 0
======*** Make the kafka service

sudo chmod 755 /etc/init.d/kafka
sudo update-rc.d kafka defaults Start Stop the Kafka Services

sudo service kafka start
sudo service kafka status
sudo service kafka stop

3.1.9. Testing kafka topics Starting Kafka

sudo service kafka start
sudo service kafka status Topic creation

/opt/kafka/bin/ --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test Publish Msg to test topic

/opt/kafka/bin/ --broker-list localhost:9092 --topic test

This will prompt for Msgs,  we can enter a test Msg Consume Msg from topic

/opt/kafka/bin/ --zookeeper localhost:2181 --topic test --from-beginning

3.2. Making Kafka Scalable

Clustering the Zookeeper in all the Servers
Clustering the kafka in All the servers

Install Zookeeper in all the server and configure the servers in

to mention all the nodes of zookeeper


Once kafka is installed in all the servers

We will change the following settings. should be unique for each node in the cluster.

for node-2
for node-3
change zookeeper.connect value to have such that it lists all zookeeper hosts with port


No comments:

Post a Comment