0
0
KafkaHow-ToBeginner · 3 min read

How to Start Kafka Server: Simple Steps to Run Apache Kafka

To start the Kafka server, first start the Zookeeper service using bin/zookeeper-server-start.sh config/zookeeper.properties, then start Kafka with bin/kafka-server-start.sh config/server.properties. These commands launch the necessary services to run Kafka locally.
📐

Syntax

Starting Kafka requires two main commands:

  • Start Zookeeper: bin/zookeeper-server-start.sh config/zookeeper.properties - Zookeeper manages Kafka's cluster metadata.
  • Start Kafka server: bin/kafka-server-start.sh config/server.properties - This runs the Kafka broker that handles messaging.

Both commands use configuration files to set up the services.

bash
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
💻

Example

This example shows how to start Zookeeper and Kafka server on a Unix-like system. Run these commands in separate terminal windows to keep both services running.

bash
# Start Zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties

# In a new terminal, start Kafka server
bin/kafka-server-start.sh config/server.properties
Output
[2024-06-01 10:00:00,000] INFO Starting zookeeper server ... [2024-06-01 10:00:05,000] INFO Kafka server started (kafka.server.KafkaServer)
⚠️

Common Pitfalls

Common mistakes when starting Kafka server include:

  • Not starting Zookeeper first, which causes Kafka to fail.
  • Running both commands in the same terminal without backgrounding one, causing the second command not to run.
  • Using incorrect paths or missing configuration files.
  • Port conflicts if other services use the same ports.

Always verify Zookeeper is running before starting Kafka.

bash
# Wrong: Starting Kafka without Zookeeper
bin/kafka-server-start.sh config/server.properties

# Right: Start Zookeeper first
bin/zookeeper-server-start.sh config/zookeeper.properties &
bin/kafka-server-start.sh config/server.properties
📊

Quick Reference

Summary tips for starting Kafka server:

  • Start Zookeeper first using bin/zookeeper-server-start.sh config/zookeeper.properties.
  • Start Kafka server next with bin/kafka-server-start.sh config/server.properties.
  • Use separate terminals or background processes to keep both running.
  • Check logs for errors if startup fails.

Key Takeaways

Always start Zookeeper before starting the Kafka server.
Use separate terminal windows or background processes to run both services simultaneously.
Ensure configuration files are correct and accessible.
Check logs to troubleshoot startup issues.
Avoid port conflicts by verifying no other services use Kafka or Zookeeper ports.