Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
kafka installation on ubuntu 16.04
Install and configure Apache Kafka on Ubuntu 16.04
1. Install Java (JDK8)::
Add the repository
$ sudo add-apt-repository -y ppa:webupd8team/java
Update the metadata of the new repository and install JDK
$ sudo apt update && apt install oracle-java8-installer -y
Verify that JDK 8 is installed properly
$ java -version
You should see the output something like this
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
2. Install zookeeper::
$ sudo apt install zookeeperd
After the installation completes, ZooKeeper will be started as a daemon automatically. By default, it will listen on port 2181.
Confirm zookeeper is running on expected port::
$ netstat -ant | grep :2181
If everything's fine, you should see the following output:
tcp6 0 0 :::2181 :::* LISTEN
if after typing 'ruok' once connected to 'localhost', zookeeper will respond with 'imok' and close the session.
$ telnet localhost 2181
Trying ::1...
Connected to localhost.
Escape character is '^]'.
ruok <-- Type at empty prompt!
imokConnection closed by foreign host.
3. Download kafka from
$ curl -O
Untar and move binaries to /opt/kafka/:
$ sudo mkdir -p /opt/kafka && sudo tar -xvf kafka_2.11- -C /opt/kafka/
4. Configure and run Kafka Server::
Turn on topic delete
$ sudo sed -i 's/#delete.topic.enable=true/delete.topic.enable=true/' /opt/kafka/kafka_2.11-
Add some niceties to simplify life:
- add a symlink to "latest" kafka installation:
cd /opt/kafka
ln -s kafka_2.11- latest
- add to `PATH`
cat >> ~/.zshrc
export KAFKA_HOME=/opt/kafka/latest
Start Kafka by running script
$ source ~/.zshrc
$ sudo $KAFKA_HOME/config/
Now, we can check listening ports:
- ZooKeeper : 2181
- Kafka
$ netstat -ant | grep -E ':2181|:9092'
If everything's fine, you should see the following output:
tcp6 0 0 :::9092 :::* LISTEN 1367/java
tcp6 0 0 :::2181 :::* LISTEN -
5. Test Server::
Open another session, and create a topic:
$ --create --topic topic-test --zookeeper localhost:2181 --partitions 1 --replication-factor 1
List available topics:
$ --list --zookeeper localhost:2181
Send message to topic as a producer via the ''::
echo "hello world" | --broker-list localhost:9092 --topic topic-test
*Consume* the sent message::
$ --bootstrap-server localhost:9092 --topic topic-test --from-beginning
# reference:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.