How to start Zookeeper and then Kafka?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If you are running classic Kafka mode, ZooKeeper must be up before Kafka brokers can register and become healthy. Most local startup issues come from wrong paths, port conflicts, or stale data directories. A clean startup sequence plus quick validation commands will save a lot of time.
Confirm Your Kafka Mode Before Starting
Kafka now supports KRaft mode, which does not require ZooKeeper. This article covers the classic flow where ZooKeeper is still required, which you may see in older clusters, tutorials, or compatibility environments.
Before starting anything, confirm:
- Java is installed.
KAFKA_HOMEpoints to your extracted Kafka directory.- ports
2181for ZooKeeper and9092for Kafka are free.
If ports are busy, either stop conflicting services or update config files to different ports.
Start ZooKeeper First
In classic Kafka distributions, ZooKeeper scripts are under Kafka bin directory.
Start ZooKeeper:
This command runs in foreground. Keep the terminal open while testing. For background mode:
Important settings in config/zookeeper.properties:
dataDir, where ZooKeeper snapshots are stored.clientPort, usually2181.maxClientCnxns, useful for local stress tests.
If startup fails with file permission errors, create and own dataDir properly.
Start Kafka Broker After ZooKeeper Is Healthy
In a second terminal, start Kafka broker:
Or as daemon:
Critical broker settings to verify in config/server.properties:
broker.id, unique per broker.listeners, where broker binds.advertised.listeners, what clients should use.log.dirs, where partition data is stored.zookeeper.connect, which should match your ZooKeeper endpoint.
Local single-node example:
If advertised.listeners is wrong, clients may connect to broker but fail metadata fetches.
Validate End to End With Topic and Messages
Once both processes are running, create a test topic:
List topics:
Produce messages:
Type a few lines and press enter after each line.
Consume messages in another terminal:
If producer and consumer both work, startup sequence is correct.
Stop Services Cleanly
For foreground processes, use keyboard interrupt. For daemon mode, use stop scripts:
Clean shutdown helps avoid log corruption and confusing restart behavior.
Common Local Failure Patterns and Fixes
- ZooKeeper starts, Kafka fails with connection error.
- Check
zookeeper.connecthost and port. - Confirm ZooKeeper process is still alive.
- Kafka starts but clients cannot connect.
- Verify
advertised.listenersvalue. - Check whether firewall or container networking rewrites hostnames.
- Startup fails after previous crash.
- Remove stale lock files or clean local log directories in development environment.
- Avoid deleting production data paths accidentally.
- Broker starts then exits quickly.
- Read first error line in broker logs, not last cascading stack trace.
Useful checks:
Notes for Multi-Broker Development
If you run multiple local brokers, each needs distinct values for:
broker.idlistenersportlog.dirs
You can duplicate server.properties into separate files such as server-1.properties, server-2.properties, then start each broker with its own file.
Common Pitfalls
- Starting Kafka before ZooKeeper in classic mode.
- Misconfigured
advertised.listenerscausing client metadata failures. - Reusing the same
log.dirsacross multiple brokers. - Ignoring port conflicts on
2181or9092. - Assuming old ZooKeeper flow is required when running a KRaft-only setup.
Summary
- In classic mode, start ZooKeeper first, then Kafka broker.
- Validate with topic creation plus producer and consumer commands.
- Check
zookeeper.connect, listener settings, and data directories first when debugging. - Use daemon mode carefully and always stop services cleanly.
- For new deployments, verify whether KRaft can replace ZooKeeper requirements.

