This script is reference for the Coding with Kafka ebook. Here's how you can use it:
For zookeeper:
ssh root@zookeeper-ip "sudo chmod +x /tmp/kafka-bootstrap-script.sh"
ssh root@zookeeper-ip "sudo /tmp/kafka-bootstrap-script.sh zookeeper1"
ssh root@zookeeper-ip "cat /data/zookeeper/myid"
ssh root@zookeeper-ip "ls /opt/kafka/"
For kafka:
ssh root@kafka-ip "sudo chmod +x /tmp/kafka-bootstrap-script.sh"
ssh root@kafka-ip "sudo /tmp/kafka-bootstrap-script.sh kafka1"
ssh root@kafka-ip "ls /opt/kafka/"
Here's what the script is doing:
- Set the hostname based on the keyword passed (e.g.
zookeeper1
orkafka1
in the example above) - Create a user
tars
and add it to thesudo
group, this user will be used for running Kafka and Zookeeper services as background services - Create all necessary directories for Zookeeper and Kafka configuration
- Install Java and other required packages to run Zookeeper and Kafka
- Update the file limits to allow for 100,000 file descriptors; Kafka may open a lot of files so we want to increase the limit.
- Update the memory swap to 1; doing this ensures we leverage RAM as much as possible before using swap space which is stored on the much slower disk. This setting helps us use a Linode 4GB instance but is another indicator as to why 8GB+ is needed.
- Download Kafka from the official Apache Kafka website and extract it to
/opt/kafka/
./opt/kafka/bin/
will hold all the Kafka scripts we'll need to run Zookeeper, run Kafka, use the Zookeeper shell, create topics, produce and consume topics, and more.