Thursday, February 18, 2016

Setup 2 node Apache Kafka cluster on Mac-OSX

This is a quick start guide to setup 2 node (broker) cluster on the Mac-OSX.
Steps to install:
1. Download apache kafka from the http://kafka.apache.org/downloads.html
2. extract to some folder in my example i have created in /tmp folder
3. Create kafka logs directory
mkdir /tmp/kafka-logs-1
mkdir /tmp/kafka-logs-2
4. copy config/server.properties to config/server2.properties as I will be running the two broker on the same machine so the following property needs to be updated in server.properties
broker.id=0
port=9092
log.dirs=/tmp/kafka-logs-1
edit the server2.properties accordingly
broker.id=1
port=9091
log.dirs=/tmp/kafka-logs-2
5. now start the zookeeper with
bin/zookeeper-server-start.sh config/zookeeper.properties
6. Start kafka broker
bin/kafka-server-start.sh config/server.properties &

7. Start second kafka broker
bin/kafka-server-start.sh config/server2.properties &

8. create kafka topic
bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic general_topic --partitions 2 --replication-factor 2

9. list topic
bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic general_topic

10. now its time to test kafka setup, for that setup producer and consumers
bin/kafka-console-producer.sh --broker-list  localhost:9092 --topic general_topic

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic general_topic
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic general_topic --from-beginning

No comments: