Kafka: Installation (Basic)

(Last Updated On: )

To install Kafka is really straight forward. There is a quick start guide you can follow. The only thing I found was that it didn’t call out Java 8. I will be using Ubuntu 16.04 for this installation.

Install Java 8

  1. sudo apt-get install openjdk-8-jdk

Install Kafka

  1. wget http://apache.forsale.plus/kafka/1.1.0/kafka_2.11-1.1.0.tgz
  2. tar -xzf kafka_2.11-1.1.0.tgz
  3. sudo mv kafka_2.11-1.1.0/ /usr/local/kafka
  4. cd /usr/local/kafka/

Setup .bashrc:

  1. sudo nano ~/.bashrc

Add the following to the end of the file.

#KAFKA VARIABLES START
export KAFKA_HOME=/usr/local/kafka
export KAFKA_CONF_DIR=/usr/local/kafka/conf
export PATH=$PATH:$KAFKA_HOME/bin
#KAFKA VARIABLES STOP

  1. source ~/.bashrc

ZooKeeper

Zookeeper comes pre-installed with kafka but you can run your own. For the purposes of this we just use the built in zookeeper.

  1. bin/zookeeper-server-start.sh config/zookeeper.properties

Kafka Server

Now we can run the kafka server and start receiving messages on topics.

  1. bin/kafka-server-start.sh config/server.properties

List Topics

  1. /usr/local/kafka/bin/kafka-topics.sh --list --zookeeper hadoop:2181

Create Topic

  1. /usr/local/kafka/bin/kafka-topics.sh --create --zookeeper hadoop:2181 --replication-factor 1 --partitions 1 --topic test

Auto Start

So if you want Kafka to run at startup then do the following.

  1. touch kafka_start.sh
  2. sudo chmod +x kafka_start.sh
  3. touch kafka_stop.sh
  4. sudo chmod +x kafka_stop.sh
  5. crontab -e

Add the following and save.

  1. @reboot /home/kafka/kafka_start.sh

kafka_start.sh

  1. #!/bin/bash
  2.  
  3. /usr/local/kafka/bin/zookeeper-server-start.sh -daemon /usr/local/kafka/config/zookeeper.properties
  4. sleep 2
  5. /usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties

kafka_stop.sh

  1. #!/bin/bash
  2.  
  3. /usr/local/kafka/bin/zookeeper-server-stop.sh
  4. sleep 2
  5. /usr/local/kafka/bin/kafka-server-stop.sh

2 thoughts on “Kafka: Installation (Basic)”

Comments are closed.