{"id":3714,"date":"2021-01-23T08:58:00","date_gmt":"2021-01-23T08:58:00","guid":{"rendered":"https:\/\/linuxways.net\/?p=3714"},"modified":"2021-01-25T18:36:16","modified_gmt":"2021-01-25T18:36:16","slug":"how-to-install-and-configure-apache-kafka-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-and-configure-apache-kafka-on-ubuntu-20-04\/","title":{"rendered":"How to Install and Configure Apache Kafka on Ubuntu 20.04"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Apache Kafka is a distributed events streaming platform which has the ability to handle the high-performance data pipelines. It was originally developed by Linkedin then to be public as an open-source platform and used by many IT companies in the world.<\/p>\n<p>This article will show you the way to install and configure Kafka on Ubuntu 20.04.<\/p>\n<h2>Installing Apache Kafka<\/h2>\n<h3><span style=\"font-weight: 400;\">Prerequisite<\/span><\/h3>\n<p>Apache Kafka requires Java to be installed on your Ubuntu 20.04 machine. Firstly, let\u2019s update your OS by the following command:<\/p>\n<pre>$ sudo apt update<\/pre>\n<p>After the OS is updated, go ahead to install Java:<\/p>\n<pre>$ sudo apt install openjdk-11-jre-headless<\/pre>\n<p>Verifying that Java was successfully installed by running:<\/p>\n<pre>$ java --version<\/pre>\n<p>The output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"232\" class=\"wp-image-3715\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-364.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-364.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-364-300x45.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-364-1024x155.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-364-768x116.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<h3><span style=\"font-weight: 400;\">Downloading Kafka<\/span><\/h3>\n<p>Next, you have to download the Kafka source to your Ubuntu 20.04. It\u2019s highly recommended to download it from the official website of Apache Kafka: <a href=\"https:\/\/kafka.apache.org\/downloads\">https:\/\/kafka.apache.org\/downloads<\/a><\/p>\n<p>At the time of writing this article, the latest version is 2.7.0. You can download it by the following command:<\/p>\n<pre>$ cd $HOME<\/pre>\n<pre>$ wget <a href=\"https:\/\/downloads.apache.org\/kafka\/2.7.0\/kafka-2.7.0-src.tgz\">https:\/\/downloads.apache.org\/kafka\/2.7.0\/kafka-2.7.0-src.tgz<\/a><\/pre>\n<p>Let\u2019s create a new folder named as kafka-server in \/usr\/local directory:<\/p>\n<pre>$ sudo mkdir \/usr\/local\/kafka-server<\/pre>\n<p>Then extract the downloaded source of Kafka to \/usr\/local\/kafka-server directory:<\/p>\n<pre>$ sudo tar xf $HOME\/kafka-2.7.0-src.tgz -C \/usr\/local\/kafka-server<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"232\" class=\"wp-image-3716\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-365.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-365.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-365-300x45.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-365-1024x155.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-365-768x116.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>You\u2019ve already had the extracted Apache Kafka binary files. Listing these files by running:<\/p>\n<pre>$ ls \/usr\/local\/kafka-server\/kafka-2.7.0-src\/bin\/<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"766\" class=\"wp-image-3717\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-366.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-366.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-366-300x150.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-366-1024x511.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-366-768x383.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>Now, it\u2019s time to make Kafka and Zookeeper run as daemons in Ubuntu 20.04. To do this, you have to create Systemd unit files for both Kafka and Zookeeper.<\/p>\n<h3><span style=\"font-weight: 400;\">Creating Systemd Unit files for Kafka and Zookeeper<\/span><\/h3>\n<p>Using your favorite editor and create two files as follows:<\/p>\n<p>\/etc\/systemd\/system\/zookeeper.service<\/p>\n<pre>[Unit]\n\nDescription=Apache Zookeeper Server\n\nRequires=network.target remote-fs.target\n\nAfter=network.target remote-fs.target\n\n[Service]\n\nType=simple\n\nExecStart=\/usr\/local\/kafka-server\/kafka-2.7.0-src\/bin\/zookeeper-server-start.sh \/usr\/local\/kafka-server\/kafka-2.7.0-src\/config\/zookeeper.properties\n\nExecStop=\/usr\/local\/kafka-server\/kafka-2.7.0-src\/bin\/zookeeper-server-stop.sh\n\nRestart=on-abnormal\n\n[Install]\n\nWantedBy=multi-user.target\n<\/pre>\n<p>\/etc\/systemd\/system\/kafka.service<\/p>\n<pre>[Unit]\n\nDescription=Apache Kafka Server\n\nDocumentation=http:\/\/kafka.apache.org\/documentation.html\n\nRequires=zookeeper.service\n\nAfter=zookeeper.service\n\n[Service]\n\nType=simple\n\nEnvironment=\"JAVA_HOME=\/usr\/lib\/jvm\/java-11-openjdk-amd64\"\n\nExecStart=\/usr\/local\/kafka-server\/kafka-2.7.0-src\/bin\/kafka-server-start.sh \/usr\/local\/kafka-server\/kafka-2.7.0-src\/config\/server.properties\n\nExecStop=\/usr\/local\/kafka-server\/kafka-2.7.0-src\/bin\/kafka-server-stop.sh\n\nRestart=on-abnormal\n\n[Install]\n\nWantedBy=multi-user.target<\/pre>\n<p>In order to apply the changes, the systemd daemons need to be reloaded and you have to enable the services as well.<\/p>\n<pre>$ sudo systemctl daemon-reload\n\n$ sudo systemctl enable --now zookeeper.service\n\n$ sudo systemctl enable --now kafka.service\n\n$ sudo systemctl status kafka zookeeper<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"360\" class=\"wp-image-3718\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-367.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-367.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-367-300x70.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-367-1024x240.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-367-768x180.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"330\" class=\"wp-image-3719\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-368.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-368.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-368-300x64.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-368-1024x220.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-368-768x165.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<h3><span style=\"font-weight: 400;\">Installing Cluster Manager for Apache Kafka (CMAK)<\/span><\/h3>\n<p>The next step is installing the CMAK which stands for Cluster Manager for Apache Kafka. CMAK is an open-source tool for managing and monitoring Kafka services. It was originally developed by Yahoo. In order to install CMAK, run the following commands:<\/p>\n<pre>$ cd $HOME\n\n$ git clone <a href=\"https:\/\/github.com\/yahoo\/CMAK.git\">https:\/\/github.com\/yahoo\/CMAK.git<\/a><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"254\" class=\"wp-image-3720\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-369.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-369.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-369-300x50.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-369-1024x169.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-369-768x127.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<h3><span style=\"font-weight: 400;\">Configuring CMAK<\/span><\/h3>\n<p>Then, using your favorite editor to modify the CMAK configuration.<\/p>\n<pre>$ vim ~\/CMAK\/conf\/application.conf<\/pre>\n<p>In this tutorial, we will configure the Zookeeper is <strong>localhost<\/strong>, let\u2019s change the value of <strong>cmak.zkhosts<\/strong> as <strong>localhost:2181<\/strong><\/p>\n<p>You can find the <strong>cmak.zkhosts<\/strong> at line 28.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"182\" class=\"wp-image-3721\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-370.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-370.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-370-300x36.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-370-1024x121.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-370-768x91.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>Now, you have to create a zip file for the purpose of deploying the application:<\/p>\n<pre>$ cd ~\/CMAK\n\n$ .\/sbt clean dist<\/pre>\n<p>It will take about a minute to complete. The output will be:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"288\" class=\"wp-image-3722\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-371.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-371.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-371-300x56.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-371-1024x192.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-371-768x144.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<h3><span style=\"font-weight: 400;\">Starting the CMAK service<\/span><\/h3>\n<p>Change into ~\/CMAK\/target\/universal directory and extract the zip file:<\/p>\n<pre>$ cd ~\/CMAK\/target\/universal\n\n$ unzip cmak-3.0.0.5.zip<\/pre>\n<p>After unzip the cmak-3.0.0.5.zip file, change to the directory, and execute the cmak binary:<\/p>\n<pre>$ cd cmak-3.0.0.5\n\n$ bin\/cmak<\/pre>\n<p>By default, the cmak service will run on port 9000.<\/p>\n<p>Use the web browser and goto http:\/\/&lt;ip-server&gt;:9000<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"638\" class=\"wp-image-3723\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-372.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-372.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-372-300x125.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-372-1024x425.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-372-768x319.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>Currently, there is no available cluster. We have to add a new one by clicking on <strong>Add Cluster <\/strong>on <strong>Cluster <\/strong>drop-down list.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"434\" class=\"wp-image-3724\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-373.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-373.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-373-300x85.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-373-1024x289.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-373-768x217.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/strong><\/p>\n<p>Then, fill up the below form with the requested information: Cluster name, Cluster Zookeeper Hosts, Kafka Version and so on. For example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1894\" height=\"964\" class=\"wp-image-3725\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-374.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-374.png 1894w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-374-300x153.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-374-1024x521.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-374-768x391.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-374-1536x782.png 1536w\" sizes=\"auto, (max-width: 1894px) 100vw, 1894px\" \/><\/p>\n<p>Leave other options with their default values then click <strong>Save.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1894\" height=\"996\" class=\"wp-image-3726\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-375.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-375.png 1894w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-375-300x158.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-375-1024x538.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-375-768x404.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-375-1536x808.png 1536w\" sizes=\"auto, (max-width: 1894px) 100vw, 1894px\" \/><\/p>\n<p>Done. The cluster was successfully created.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"748\" class=\"wp-image-3727\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-376.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-376.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-376-300x146.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-376-1024x499.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-376-768x374.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/strong><\/p>\n<p>Now, it\u2019s time to create a sample topic. Assume that we\u2019re going to create a topic named \u201cLinuxWaysTopic\u201d. Bearing in mind that the CMAK is still running and launch a new terminal then run the following command:<\/p>\n<pre>$ cd \/usr\/local\/kafka-server\/kafka-2.7.0-src<\/pre>\n<pre>$ bin\/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic LinuxWaysTopic<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1536\" height=\"154\" class=\"wp-image-3728\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-377.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-377.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-377-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-377-1024x103.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-377-768x77.png 768w\" sizes=\"auto, (max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>Go to cluster view then click <strong>Topic &gt; List<\/strong><\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"2086\" height=\"1168\" class=\"wp-image-3729\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-378.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-378.png 2086w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-378-300x168.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-378-1024x573.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-378-768x430.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-378-1536x860.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-378-2048x1147.png 2048w\" sizes=\"auto, (max-width: 2086px) 100vw, 2086px\" \/><\/strong><\/p>\n<h2>Conclusion<\/h2>\n<p>You\u2019ve successfully installed and configured Apache Kafka on your Ubuntu 20.04 LTS machine.<\/p>\n<p>If you have any concerns, feel free to leave your comment and let me know. Thank you!<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction Apache Kafka is a distributed events streaming platform which has the ability to handle the high-performance data pipelines. It was originally developed by Linkedin then to be&hellip;<\/p>","protected":false},"author":23,"featured_media":3731,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[152,100],"class_list":["post-3714","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-apache-kafka","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=3714"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3714\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/3731"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=3714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=3714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=3714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}