# Start & Stop Kafka & Zookeeper

In 
Published 2022-12-03

This tutorial explains to you how to start and stop Apache Kafka and Zookeeper.

If you are not understanding the Kafka Server architecture you can take a look at Apache Kafka Architecture before.

In order to have Kafka server up and running you must configure first Zookeeper server and Kafka Server.

By default, Kafka and Zookeeper use some temporary data directories. These directories must be replaced by permanent ones. Now I will show you how to do a basic Kafka and Zookeeper configuration.

If you want just to see how to start/stop Apache Kafka and Zookeeper you can go to the step #4.

  1. Create the data directories for Kafka and Zookeeper
# mkdir -p /kafka/kafka_2.13-2.8.0/data/kafka
# mkdir -p /kafka/kafka_2.13-2.8.0/data/zookeeper
# chown -R kafka:kafka /kafka/kafka_2.13-2.8.0/data

  1. Configure Zookeeper to use this new data directory
vi /kafka/kafka_2.13-2.8.0/config/zookeeper.properties

Put the new dataDir like in picture below.

  1. Configure Kafka server
vi /kafka/kafka_2.13-2.8.0/config/server.properties

Put the new log.dirs like in picture below.

  1. Start Zookeeper
cd /kafka/kafka_2.13-2.8.0
zookeeper-server-start.sh ./config/zookeeper.properties

If Zookeeper is started correctly, the Zookeeper logs must look like above.

  1. Start Kafka Server
cd /kafka/kafka_2.13-2.8.0
kafka-server-start.sh ./config/server.properties

If Apache Kafka server is started correctly, the Kafka logs must look like above.

If you want Kafka and Zookeeper run in background you must start them using nohup command:

nohup zookeeper-server-start.sh ./config/zookeeper.properties &
nohup kafka-server-start.sh ./config/server.properties &
  1. Stop Kafka Server
kafka-server-stop.sh

If Apache Kafka server is stopped correctly, the Kafka logs must look like above.

  1. Stop Zookeeper
zookeeper-server-stop.sh