If you are playing around with Kafka you, probably, would prefer to use containers. But, for some reason, you may want to use VMs instead. With this Vagrant script you can get a cluster installed and configured locally with a few steps.
Note that this script doesn't use the most recent version of Kafka. But you can change the version by changing the lines 12
and 13
of the script. Check the Confluent Platform and Apache Kafka Compatibilty table for details.
-
Install Virtual Box https://www.virtualbox.org/
-
Install Vagrant >= 1.6.4 http://www.vagrantup.com/
-
Copy the Vagrantfile to a folder and run:
$ vagrant up
It will take a couple of minutes.
- Start Zookeeper
$ vagrant ssh zk
$ sudo zookeeper-server-start /etc/kafka/zookeeper.properties
- Start the Kafka brokers
$ vagrant ssh kafka101
$ sudo kafka-server-start /etc/kafka/server.properties
Repeat this procedure for kafka102
and kafka103
- Create a topic
The following commands can be executed inside any VM. Use $ vagrant ssh kafka101
to log in.
$ kafka-topics --zookeeper zk:2181 --create --topic my-topic --partitions 6 --replication-factor 2
$ kafka-topics --zookeeper zk:2181 --describe --topic my-topic
- Send some messages to the topic using the command line util:
$ kafka-console-producer --broker-list kafka101:9092,kafka102:9092 --topic my-topic
- Consume the messages
kafka-console-consumer --consumer-property group.id=test-consumer-group --from-beginning --topic my-topic --bootstrap-server kafka101:9092,kafka102:9092