{"id":838,"date":"2020-10-09T12:18:29","date_gmt":"2020-10-09T11:18:29","guid":{"rendered":"http:\/\/www.igfasouza.com\/blog\/?p=838"},"modified":"2021-04-27T11:05:56","modified_gmt":"2021-04-27T10:05:56","slug":"raspberry-pi-kafka-cluster","status":"publish","type":"post","link":"http:\/\/www.igfasouza.com\/blog\/raspberry-pi-kafka-cluster\/","title":{"rendered":"Raspberry Pi Kafka cluster"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2020\/10\/raspberry_kafka.jpg\" alt=\"\" width=\"543\" height=\"345\" class=\"alignnone size-full wp-image-839\" srcset=\"http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2020\/10\/raspberry_kafka.jpg 543w, http:\/\/www.igfasouza.com\/blog\/wp-content\/uploads\/2020\/10\/raspberry_kafka-300x191.jpg 300w\" sizes=\"auto, (max-width: 543px) 100vw, 543px\" \/><\/p>\n<p><b>How heya?<\/b><\/p>\n<p>This is another blog about Raspberry PI, and today I want to show how I did a simple Kafka cluster.<\/p>\n<p>If you&#8217;re not familiar with Kafka, I suggest you have a look at my previous post \u201c<a href=\"http:\/\/www.igfasouza.com\/blog\/what-is-kafka\/\" rel=\"noopener\" target=\"_blank\">What is Kafka?<\/a>\u201d before.<\/p>\n<p>This is a really simple tutorial and you can find similar instructions over the internet.<\/p>\n<h2>Pre-Requisites<\/h2>\n<ul>\n<li>Raspbian installed<\/li>\n<\/ul>\n<h2>Components<\/h2>\n<ul>\n<li>3x Raspberry Pi3 B  with power supply and micro SD card with Raspbian.<\/li>\n<\/ul>\n<p>Despite every time that you look at a cluster tutorial they add a switch, router, and some internet cables I did use just simple wifi.<\/p>\n<p>For the software part, we will download Zookeeper and Kafka, and there&#8217;s no installation. Is just about untar and changing some settings files.<br \/>\nDownload latest Apache Zookeeper &#038; Apache Kafka.<\/p>\n<h2>Steps<\/h2>\n<p>You should do this in all Raspberry PIs.<\/p>\n<p><b>1) Zookeeper<\/b><\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"kw2\">wget<\/span> https:<span class=\"sy0\">\/\/<\/span>downloads.apache.org<span class=\"sy0\">\/<\/span>zookeeper<span class=\"sy0\">\/<\/span>zookeeper-3.6.1<span class=\"sy0\">\/<\/span>apache-zookeeper-3.6.1-bin.tar.gz<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Modify the &#8220;<em>conf\/zoo.cfg<\/em>&#8221; with;<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"re2\">dataDir<\/span>=<span class=\"sy0\">\/<\/span>opt<span class=\"sy0\">\/<\/span>zookeeper_data<br \/>\n<span class=\"re2\">tickTime<\/span>=<span class=\"nu0\">2000<\/span><br \/>\n<span class=\"re2\">initLimit<\/span>=<span class=\"nu0\">10<\/span><br \/>\n<span class=\"re2\">syncLimit<\/span>=<span class=\"nu0\">5<\/span><br \/>\n<span class=\"re2\">dataDir<\/span>=<span class=\"sy0\">\/<\/span>var<span class=\"sy0\">\/<\/span>zookeeper<br \/>\n<span class=\"re2\">clientPort<\/span>=<span class=\"nu0\">2181<\/span><br \/>\nserver.1=192.168.0.18:<span class=\"nu0\">2888<\/span>:<span class=\"nu0\">3888<\/span><br \/>\nserver.2=192.168.0.15:<span class=\"nu0\">2888<\/span>:<span class=\"nu0\">3888<\/span><br \/>\nserver.3=192.168.0.16:<span class=\"nu0\">2888<\/span>:<span class=\"nu0\">3888<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>create a file &#8220;<em>myid<\/em>&#8221; and the file should have only the id of the zookeeper node.<br \/>\nI use 1, 2 and 3<\/p>\n<p>Run this under the zookeeper\u2019s root folder to start the Zookeeper service.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\">.<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>zkServer.sh start <span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">\/<\/span>dev<span class=\"sy0\">\/<\/span>null <span class=\"nu0\">2<\/span><span class=\"sy0\">&gt;&amp;<\/span><span class=\"nu0\">1<\/span> <span class=\"sy0\">&amp;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p><b>2) Kafka<\/b><\/p>\n<p>I downloaded the most recent stable version<br \/>\nModify the &#8220;<em>config\/server.properties<\/em>&#8221; with:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/><\/div><\/td><td><div class=\"bash codecolorer\">broker.id=<span class=\"nu0\">1<\/span><br \/>\n<span class=\"re2\">port<\/span>=<span class=\"nu0\">9092<\/span><br \/>\nhost.name=192.168.0.10 zookeeper.connect=192.168.0.18:<span class=\"nu0\">2181<\/span>,192.168.0.15:<span class=\"nu0\">2181<\/span>,192.168.0.16:<span class=\"nu0\">2181<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Boker.id should be 1,2 and 3 for each PI<br \/>\nHost.name is the machine IP address<br \/>\nzookeeper.connect should be equals in all<\/p>\n<p>(Depends on each Raspberry PI version you are using)<\/p>\n<p>Update the &#8220;<em>bin\/kafka-server-start.sh<\/em>&#8221; with:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"kw3\">export<\/span> <span class=\"re2\">JMX_PORT<\/span>=<span class=\"co1\">${JMX_PORT:-9999}<\/span><br \/>\n<span class=\"kw3\">export<\/span> <span class=\"re2\">KAFKA_HEAP_OPTS<\/span>=<span class=\"st0\">&quot;-Xmx256M -Xms128M&quot;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Otherwise, JVM would complain not able to allocate the specified memory.<\/p>\n<p>Update &#8220;<em>bin\/kafka-run-class.sh<\/em>&#8221; with:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"re2\">KAFKA_JVM_PERFORMANCE_OPTS<\/span>=<span class=\"st0\">&quot;-client -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true&quot;<\/span> <span class=\"co0\"># change -server to -client<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>You can run this to start Kafka<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"sy0\">\/<\/span>opt<span class=\"sy0\">\/<\/span>kafka<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>kafka-server-start.sh <span class=\"re5\">-daemon<\/span> <span class=\"sy0\">\/<\/span>opt<span class=\"sy0\">\/<\/span>kafka<span class=\"sy0\">\/<\/span>config<span class=\"sy0\">\/<\/span>server.properties <span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">\/<\/span>dev<span class=\"sy0\">\/<\/span>null <span class=\"nu0\">2<\/span><span class=\"sy0\">&gt;&amp;<\/span><span class=\"nu0\">1<\/span> <span class=\"sy0\">&amp;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>And that&#8217;s it! Now you can do some basic tests.<\/p>\n<p>Create a topic<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"sy0\">\/<\/span>opt<span class=\"sy0\">\/<\/span>kafka<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>kafka-topics.sh <span class=\"re5\">--create<\/span> <span class=\"re5\">--zookeeper<\/span> 192.168.0.15:<span class=\"nu0\">9092<\/span>,192.168.0.16:<span class=\"nu0\">9092<\/span>,192.168.0.18:<span class=\"nu0\">9092<\/span> &nbsp;<span class=\"re5\">--replication-factor<\/span> <span class=\"nu0\">1<\/span> <span class=\"re5\">--partitions<\/span> <span class=\"nu0\">1<\/span> <span class=\"re5\">--topic<\/span> <span class=\"kw3\">test<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Describe this topic<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"sy0\">\/<\/span>opt<span class=\"sy0\">\/<\/span>kafka<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>kafka-topics.sh <span class=\"re5\">--zookeeper<\/span> localhost:<span class=\"nu0\">2181<\/span> <span class=\"re5\">--describe<\/span> <span class=\"re5\">--topic<\/span> <span class=\"kw3\">test<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Star a terminal producer<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"sy0\">\/<\/span>opt<span class=\"sy0\">\/<\/span>kafka<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>kafka-console-producer.sh <span class=\"re5\">--broker-list<\/span> localhost:<span class=\"nu0\">9092<\/span> <span class=\"re5\">--topic<\/span> <span class=\"kw3\">test<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Start a terminal consumer<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"bash codecolorer\"><span class=\"sy0\">\/<\/span>opt<span class=\"sy0\">\/<\/span>kafka<span class=\"sy0\">\/<\/span>bin<span class=\"sy0\">\/<\/span>kafka-console-consumer.sh &nbsp;<span class=\"re5\">--bootstrap-server<\/span> localhost:<span class=\"nu0\">9092<\/span> <span class=\"re5\">--topic<\/span> <span class=\"kw3\">test<\/span> <span class=\"re5\">--from-beginning<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>I put my Zookeeper and Kafka in the &#8220;<em>\/opt<\/em>&#8221; folder, but you can put it in any path.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/yq4rLLZhmWU\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h2>Final Thoughts<\/h2>\n<p>I did use a Raspberry PI 3 B, but Raspberry PI already released The Raspberry Pi4 with 8g.<br \/>\nI don\u2019t think we are too far from seeing a new Raspberry version, make Pi4 16gb or PI5, who knows.<br \/>\nI did use the Raspbian that is 32bits OS, and Raspberry PI already released Raspberry Pi OS,  (yes they changed the name), that is the new official operating system and there&#8217;s a 64bits version.<\/p>\n<p>With a more powerful computer, memory, and a 64bits OS it\u2019s open to a lot of more ideas and scenarios. Kubernetes, Strimzi, and keda are just some initial things.<\/p>\n<p>Another thing is that Kafka is about to remove the Apache Zookeeper dependency, and this will make a lot of changes.<\/p>\n<p>I found a lot of tutorials about Kubernetes and 64bits OS for Raspberry, but could not find any Kubernetes Kafka example or Strimzi. I think with this new OS and more powerful hardware is just a question of time.<\/p>\n<p><b>MicroK8s<\/b> &#8211; is a powerful, lightweight, reliable production-ready Kubernetes distribution. It is an enterprise-grade Kubernetes distribution that has a small disk and memory footprint while offering carefully selected add-ons out-the-box, such as Istio, Knative, Grafana, Cilium, and more.<\/p>\n<p>Canonical has released Ubuntu 19.10 with a focus on accelerating developer productivity in AI\/ML, new edge capabilities for MicroK8s, and delivering the fastest GNOME desktop performance.<br \/>\nThe Raspberry Pi 4 Model B is supported by Ubuntu 19.10. The latest board from the Raspberry Pi Foundation offers a faster system-on-a-chip with a processor that uses the Cortex-A72 architecture (quad-core 64-bit ARMv8 at 1.5GHz) and offers up to 8GB of RAM. With the Raspberry Pi 4 Model B, developers get access to a low-cost board, powerful enough to orchestrate workloads at the edge with MicroK8s. <\/p>\n<p><a href=\"https:\/\/www.hackster.io\/news\/canonical-walks-through-the-how-and-more-importantly-the-why-of-a-microk8s-raspberry-pi-cluster-0a9b88806c05\" target=\"_blank\" rel=\"noopener\">Canonical and Raspberry<\/a><\/p>\n<p><a href=\"https:\/\/ubuntu.com\/blog\/ubuntu-20-04-lts-is-certified-for-the-raspberry-pi\" target=\"_blank\" rel=\"noopener\">Raspberry with Ubuntu 20.04<\/a><\/p>\n<p><b>K3s<\/b> &#8211; a flavor of Kubernetes that is highly optimized for the edge. Though K3s is a simplified, miniature version of Kubernetes, it doesn\u2019t compromise the API conformance and functionality.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/GhjsEMRU-b4\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h2>Links<\/h2>\n<p><a href=\"https:\/\/kafka.apache.org\/\" target=\"_blank\" rel=\"noopener\">Kafka<\/a><br \/>\n<a href=\"https:\/\/www.confluent.io\/\" rel=\"noopener\" target=\"_blank\">confluent<\/a><br \/>\n<a href=\"https:\/\/www.raspberrypi.org\/\" rel=\"noopener\" target=\"_blank\">Raspberry PI<\/a><br \/>\n<a href=\"https:\/\/www.raspberrypi.org\/blog\/8gb-raspberry-pi-4-on-sale-now-at-75\/\">8gb Raspberry PI4<\/a><br \/>\n<a href=\"https:\/\/www.raspberrypi.org\/downloads\/\" rel=\"noopener\" target=\"_blank\">Raspberry Pi OS<\/a><br \/>\n<a href=\"https:\/\/strimzi.io\/\" rel=\"noopener\" target=\"_blank\">Strimzi<\/a><br \/>\n<a href=\"https:\/\/kubernetes.io\/\" rel=\"noopener\" target=\"_blank\">kubernetes<\/a><br \/>\n<a href=\"https:\/\/keda.sh\/\" rel=\"noopener\" target=\"_blank\">Keda<\/a><br \/>\n<a href=\"https:\/\/k3s.io\/\" rel=\"noopener\" target=\"_blank\">K3s<\/a><br \/>\n<a href=\"https:\/\/microk8s.io\/\" rel=\"noopener\" target=\"_blank\">Microk8s<\/a><\/p>\n<p><b>Some similar tutorial;<\/b><\/p>\n<p><a href=\"https:\/\/towardsdatascience.com\/kafka-and-zookeeper-over-ubuntu-in-a-3-node-cluster-a-data-science-big-data-laboratory-part-4-of-4-47631730d240\" rel=\"noopener\" target=\"_blank\">https:\/\/towardsdatascience.com\/kafka-and-zookeeper-over-ubuntu-in-a-3-node-cluster-a-data-science-big-data-laboratory-part-4-of-4-47631730d240<\/a><\/p>\n<p><a href=\"http:\/\/czcodezone.blogspot.com\/2014\/11\/setup-kafka-in-cluster.html\" rel=\"noopener\" target=\"_blank\">http:\/\/czcodezone.blogspot.com\/2014\/11\/setup-kafka-in-cluster.html<\/a><\/p>\n<p><a href=\"https:\/\/pandariel.com\/posts\/kafka-cluster\/\" rel=\"noopener\" target=\"_blank\">https:\/\/pandariel.com\/posts\/kafka-cluster\/<\/a><\/p>\n<p><a href=\"https:\/\/rdiot.tistory.com\/329\" rel=\"noopener\" target=\"_blank\">https:\/\/rdiot.tistory.com\/329<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How heya? This is another blog about Raspberry PI, and today I want to show how I did a simple Kafka cluster. If you&#8217;re not familiar with Kafka, I suggest you have a look at my previous post \u201cWhat is&hellip; <a href=\"http:\/\/www.igfasouza.com\/blog\/raspberry-pi-kafka-cluster\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":839,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,24],"tags":[7,13],"class_list":["post-838","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kafka","category-raspberry-pi","tag-kafka","tag-raspberry-pi"],"_links":{"self":[{"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/posts\/838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/comments?post=838"}],"version-history":[{"count":9,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/posts\/838\/revisions"}],"predecessor-version":[{"id":1212,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/posts\/838\/revisions\/1212"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/media\/839"}],"wp:attachment":[{"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/media?parent=838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/categories?post=838"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.igfasouza.com\/blog\/wp-json\/wp\/v2\/tags?post=838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}