Download and install Apache Kafka binaries on bare metal
Here’s a procedure to download and install Apache Kafka binaries on bare metal, and then verify that they’re working with a simple message produce and consume using Kafka scripts. This procedure should work on RHEL, macOS, and Windows.
-
Download Kafka binaries
Go to the Apache Kafka website. Download the latest Kafka binaries (not the source code) by clicking on the link under “Binary downloads”. Extract the downloaded archive to a directory of your choice.
-
Set up environment variables.
In a command prompt or terminal, navigate to the directory where you extracted the Kafka binaries.
Set the
KAFKA_HOME
environment variable to this directory. For example, on Windows: setKAFKA_HOME=C:\path\to\kafka\directory
.Add the bin directory within
KAFKA_HOME
to your system’s PATH environment variable. For example, on Windows: setPATH=%PATH%;%KAFKA_HOME%\bin
. -
Start Kafka.
Open a new command prompt or terminal window and navigate to the directory where you extracted the Kafka binaries.
Start the ZooKeeper service:
bin\zookeeper-server-start.sh config\zookeeper.properties
(on Windows, usebin\windows\zookeeper-server-start.bat
instead).In a separate command prompt or terminal window, start the Kafka broker:
bin\kafka-server-start.sh config\server.properties
(on Windows, usebin\windows\kafka-server-start.bat
instead) -
Create a topic.
Open a new command prompt or terminal window and navigate to the directory where you extracted the Kafka binaries.
Create a new topic named “test” with a single partition and a replication factor of 1:
bin\kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
-
Produce a message.
Open a new command prompt or terminal window and navigate to the directory where you extracted the Kafka binaries.
Send a message to the “test” topic:
bin\kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test
.Type a message and press Enter to send it.
-
Consume a message.
Open a new command prompt or terminal window and navigate to the directory where you extracted the Kafka binaries.
Start a consumer that reads messages from the beginning of the “test” topic:
bin\kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
.You should see the message you produced in step 5 appear in the consumer window.
That’s it! If you followed these steps, you should have a working installation of Apache Kafka that can produce and consume messages.