2.1.1 Installing Kafka Without Zookeeper (KRaft Mode)
Complete guide to installing Kafka 3.8.0 in KRaft mode without Zookeeper. Covers installation steps for Linux, Mac, Windows, and Docker with detailed configuration examples.
Installing Kafka Without Zookeeper (KRaft Mode)
Overview
Kafka offers two installation methods:
- With Zookeeper: Traditional setup where Zookeeper handles metadata and leader elections
- Without Zookeeper (KRaft Mode): Introduced in Kafka 2.8, stable in 3.x versions
- Kafka manages its own metadata
- Simplifies architecture
- The future of Kafka
This guide covers Kafka 3.8.0 installation in KRaft mode for Linux, Mac, Windows, and Docker.
Prerequisites
Before installation, ensure you have:
- Java Development Kit (JDK) version 8 or higher (verify with
java -version) - Platform-specific tools:
- Windows: Git Bash or PowerShell
- Mac: Homebrew
- Linux: Package manager (apt or yum)
- Docker & Docker Compose (for containerized setup)
KRaft Mode on Linux
1. Download and Extract Kafka
1mkdir -p /opt/kafka
2wget https://downloads.apache.org/kafka/3.8.0/kafka_2.13-3.8.0.tgz
3tar -xvzf kafka_2.13-3.8.0.tgz -C /opt/kafka --strip-components=12. Create Log Directory
1mkdir /tmp/kraft-combined-logs3. Configure server.properties
1cat <<EOL > /opt/kafka/config/kraft/server.properties
2process.roles=broker,controller
3node.id=1
4controller.quorum.voters=1@localhost:9093
5listeners=PLAINTEXT://localhost:9092,CONTROLLER://localhost:9093
6log.dirs=/tmp/kraft-combined-logs
7EOLConfiguration explained:
process.roles=broker,controller: Node serves as both broker (handles client requests) and controller (manages metadata)node.id=1: Unique identifier for the Kafka nodecontroller.quorum.voters=1@localhost:9093: Defines quorum voters for controllerlisteners=PLAINTEXT://localhost:9092,CONTROLLER://localhost:9093:
- Broker listens for clients at port 9092
- Controller listens at port 9093
log.dirs=/tmp/kraft-combined-logs: Directory for storing Kafka logs
4. Format Storage
1/opt/kafka/bin/kafka-storage.sh format -t $(uuidgen) -c /opt/kafka/config/kraft/server.properties5. Start Kafka
1/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/kraft/server.propertiesKRaft Mode on Mac
1. Install Kafka via Homebrew
1brew install kafka2. Create Log Directory
1mkdir /tmp/kraft-combined-logs3. Configure server.properties
1cat <<EOL > /usr/local/etc/kafka/server.properties
2process.roles=broker,controller
3node.id=1
4controller.quorum.voters=1@localhost:9093
5listeners=PLAINTEXT://localhost:9092,CONTROLLER://localhost:9093
6log.dirs=/tmp/kraft-combined-logs
7EOL4. Format KRaft Metadata Storage
1/usr/local/bin/kafka-storage format -t $(uuidgen) -c /usr/local/etc/kafka/server.properties5. Start Kafka
1kafka-server-start /usr/local/etc/kafka/server.propertiesKRaft Mode on Windows
1. Create Directory and Extract
1mkdir C:\kafka
2tar -xvzf kafka_2.13-3.8.0.tgz -C C:\kafka2. Create Log Directory
1mkdir C:\tmp\kraft-combined-logs3. Configure server.properties
1cat <<EOL > C:\kafka\config\kraft\server.properties
2process.roles=broker,controller
3node.id=1
4controller.quorum.voters=1@localhost:9093
5listeners=PLAINTEXT://localhost:9092,CONTROLLER://localhost:9093
6log.dirs=C:\tmp\kraft-combined-logs
7EOL4. Format KRaft Metadata Storage
1C:\kafka\bin\windows\kafka-storage.bat format -t $([guid]::NewGuid()) -c C:\kafka\config\kraft\server.properties5. Start Kafka
1C:\kafka\bin\windows\kafka-server-start.bat C:\kafka\config\kraft\server.propertiesKafka in KRaft Mode - Docker
Step 1: Prepare Docker File
- Create a
kafkadirectory in your workspace - Create a
docker-compose.yamlfile in this directory
Step 2: Set Up Services
The docker-compose.yaml defines two services:
kafka-init service:
- Formats storage directory for KRaft mode
- Initializes metadata for Kafka
- Runs
kafka-storage.sh formatcommand - Stores metadata in
./kafka-logs
kafka service:
- Configured as both broker and controller
Key environment variables:
KAFKA_PROCESS_ROLES: Defines roles as broker and controllerKAFKA_CONTROLLER_QUORUM_VOTERS: Identifies controller quorum nodeKAFKA_LISTENERS: Sets up client and controller listenersKAFKA_LOG_DIRS: Points to log storage directory
Step 3: Run Docker Compose
1docker-compose up -dThe -d flag runs services in detached mode, allowing them to run in the background while you execute other commands.