How to install and configure Kafka on CentOS 7

Kafka is an open-source stream-processing software platform developed by the Apache Software Foundation and in this tutorial we gonna to show how to install and configure Kafka on CentOS 7.
Imagine that when an event occurs you want to take an action. for example when a user logs in to a system, an email being sent to him/her.
In such situations, your software as PRODUCER sends login event to Kafka and your email sender script as consumer being notified about user login and sends email.

Here is our environment:

OS: CentOS 7 Linux on VMware
Firewall: firewalld
SElinux: permissive
IP Address:

1- Install Java

Kafka has been written in Scala and Java so first we have to install Java:

# yum install java-1.8.0-openjdk

2- Install and configure Kafka

Installing Kafka is pretty simple. just we need to download its package and make service and start it:

# cd /opt/ && wget
# tar -xzf kafka_2.12-2.5.0.tgz
# mv kafka_2.12-2.5.0 kafka

Now we create service files for Kafka. Kafka uses ZooKeeper so we need to first start a ZooKeeper server:

# vim /lib/systemd/system/zookeeper.service

and we paste the following content in it:

Description=Zookeper daemon

ExecStart=/opt/kafka/bin/ -daemon /opt/kafka/config/


then we start and enable service:

# systemctl enable zookeeper.service
# systemctl start zookeeper.service
# systemctl status zookeeper.service

Now we create Kafka service file and start it:

# vim /lib/systemd/system/kafka.service

and put the following content in it:

Description=Kafka daemon

ExecStart=/opt/kafka/bin/ -daemon /opt/kafka/config/


before starting Kafka service we need to put these lines at the end of file:


then we start Kafka service:

# systemctl enable kafka.service
# systemctl start kafka.service
# systemctl status kafka.service

3- Kafka web UI

By default, Kafka has no web UI for better service management. so we install kafka-webview package as a web UI for Kafka management:

# cd /opt/ && wget
# unzip
# mv kafka-webview-ui-2.5.1-bin kafka-webview

then we create service file for it:

# vim /lib/systemd/system/kafka-webview.service

and put these content in it:

Description=Kafka Web UI daemon



finally we start it:

# systemctl enable kafka-webview.service
# systemctl start kafka-webview.service
# systemctl status kafka-webview.service

4- Configure firewall

By default Zookeeper listens on port 2181 and Kafka listens on port 9092. Also web UI listens on port 8080. so we open these ports in firewall:

# firewall-cmd --permanent --add-port=2181/tcp
# firewall-cmd --permanent --add-port=9092/tcp
# firewall-cmd --permanent --add-port=8080/tcp
# firewall-cmd --reload

now we point to this address in browser: