{"id":6967,"date":"2018-10-02T18:25:45","date_gmt":"2018-10-02T15:25:45","guid":{"rendered":"https:\/\/www.howtoforge.com\/tutorial\/ubuntu-apache-kafka-installation\/"},"modified":"2018-10-02T18:25:45","modified_gmt":"2018-10-02T15:25:45","slug":"how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu\/","title":{"rendered":"How to Install Apache Kafka Distributed Streaming Platform on Ubuntu"},"content":{"rendered":"<p>Apache Kafka is a distributed streaming platform developed by Apache Software Foundation and written in Java and Scala. Apache Kafka was originally developed by LinkedIn, and was open sourced in 2011.<\/p>\n<p>Apache Kafka is used for building real-time streaming data pipeline that reliably gets data between system and applications. It provides a unified, high-throughput, and low-latency data processing in real-time.<\/p>\n<p>In this tutorial, we will show you how to step-by-step install and configure Apache Kafka on Ubuntu 18.04. This guide will cover the Apache Kafka and Apache Zookeeper installation and configuration.<\/p>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<ul>\n<li>Ubuntu 18.04<\/li>\n<li>Root privileges<\/li>\n<\/ul>\n<h2 id=\"what-we-will-do\">What we will do?<\/h2>\n<ol>\n<li>Install Java OpenJDK 8<\/li>\n<li>Install Apache Zookeeper<\/li>\n<li>Download and Configure Apache Kafka<\/li>\n<li>Configure Apache Kafka and Zookeeper as s Service<\/li>\n<li>Testing<\/li>\n<\/ol>\n<h2 id=\"step-install-java-openjdk-\">Step 1 &#8211; Install Java OpenJDK 8<\/h2>\n<p>Apache Kafka has been written in Java and Scala, so we need to install java on the server.<\/p>\n<p>Before installing any packages, update the repository and upgrade all packages.<\/p>\n<p class=\"command\">sudo apt update<br \/>sudo apt upgrade<\/p>\n<p>Now install the Java OpenJDK 8 from the Ubuntu repository using the apt command below.<\/p>\n<p class=\"command\">sudo apt install openjdk-8-jdk -y<\/p>\n<p>After the installation is complete, check the java installed version.<\/p>\n<p class=\"command\">java -version<\/p>\n<p>Now you will see the java OpenJDK 8 installed on Ubuntu 18.04.<\/p>\n<p><a class=\"fancybox\" id=\"img-1\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_kafka_on_ubuntu_1804\/big\/1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu.png\" alt=\"Install Java\" width=\"500\" height=\"323\" title=\"\"><\/a><\/p>\n<h2 id=\"step-install-apache-zookeeper\">Step 2 &#8211; Install Apache Zookeeper<\/h2>\n<p>Apache Kafka uses zookeeper for the electing controller, cluster membership, and topics configuration. Zookeeper s a distributed configuration and synchronization service.<\/p>\n<p>In this step, we will install Zookeeper from the Ubuntu repository.<\/p>\n<p>Run the apt command below.<\/p>\n<p class=\"command\">sudo apt install zookeeperd -y<\/p>\n<p>Wait until the installation is complete.<\/p>\n<p><a class=\"fancybox\" id=\"img-3\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_kafka_on_ubuntu_1804\/big\/3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu-1.png\" alt=\"Install Apache Zookeeper\" width=\"500\" height=\"170\" title=\"\"><\/a><\/p>\n<h2 id=\"step-download-and-configure-apache-kafka\">Step 3 &#8211; Download and Configure Apache Kafka<\/h2>\n<p>In this step, we will install the Apache Kafka using the binary files that can be downloaded from the Kafka website. We will install and configure apache Kafka and run it as a non-root user.<\/p>\n<p>Add a new user named &#8216;kafka&#8217;.<\/p>\n<p class=\"command\">useradd -d \/opt\/kafka -s \/bin\/bash kafka<br \/>passwd kafka<\/p>\n<p>Now go to the &#8216;\/opt&#8217; directory and download the Apache Kafka binary files using wget.<\/p>\n<p class=\"command\">cd \/opt<br \/>wget http:\/\/www-eu.apache.org\/dist\/kafka\/2.0.0\/kafka_2.11-2.0.0.tgz<\/p>\n<p>Now create a new kafka directory.<\/p>\n<p class=\"command\">mkdir -p \/opt\/kafka<\/p>\n<p>Extract the kafka_*.tar.gz file to the &#8216;kafka&#8217; directory and change the owner of directory to the &#8216;kafka&#8217; user and group.<\/p>\n<p class=\"command\">tar -xf kafka_2.11-2.0.0.tgz -C \/opt\/kafka &#8211;strip-components=1<br \/>sudo chown -R kafka:kafka \/opt\/kafka<\/p>\n<p>Now login to the &#8216;kafka&#8217; user and edit the server.properties configuration.<\/p>\n<p class=\"command\">su &#8211; kafka<br \/>vim config\/server.properties<\/p>\n<p>Paste the following configuration to the end of the line.<\/p>\n<pre>delete.topic.enable = true<\/pre>\n<p>Save and exit.<\/p>\n<p><a class=\"fancybox\" id=\"img-5\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_kafka_on_ubuntu_1804\/big\/5.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu-2.png\" alt=\"Start Apache Kafka\" width=\"500\" height=\"160\" title=\"\"><\/a><\/p>\n<p>The Apache Kafka configuration has been completed.<\/p>\n<h2 id=\"step-configure-apache-kafka-and-zookeeper-as-services\">Step 4 &#8211; Configure Apache Kafka and Zookeeper as Services<\/h2>\n<p>In this step, we will configure the Apache Kafka as a service and configure the customs service configuration for the zookeeper.<\/p>\n<p>Go to the &#8216;\/lib\/systemd\/system&#8217; directory and create a new service file &#8216;zookeeper.service&#8217;.<\/p>\n<p class=\"command\">cd \/lib\/systemd\/system\/<br \/>vim zookeeper.service<\/p>\n<p>Paste the configuration below.<\/p>\n<pre>[Unit]&#13;\nRequires=network.target remote-fs.target&#13;\nAfter=network.target remote-fs.target&#13;\n&#13;\n[Service]&#13;\nType=simple&#13;\nUser=kafka&#13;\nExecStart=\/opt\/kafka\/bin\/zookeeper-server-start.sh \/opt\/kafka\/config\/zookeeper.properties&#13;\nExecStop=\/opt\/kafka\/bin\/zookeeper-server-stop.sh&#13;\nRestart=on-abnormal&#13;\n&#13;\n[Install]&#13;\nWantedBy=multi-user.target<\/pre>\n<p>Save and exit.<\/p>\n<p>Now create the Apache Kafka service file &#8216;kafka.service&#8217;.<\/p>\n<p class=\"command\">vim kafka.service<\/p>\n<p>Paste the configuration below.<\/p>\n<pre>[Unit]&#13;\nRequires=zookeeper.service&#13;\nAfter=zookeeper.service&#13;\n&#13;\n[Service]&#13;\nType=simple&#13;\nUser=kafka&#13;\nExecStart=\/bin\/sh -c '\/opt\/kafka\/bin\/kafka-server-start.sh \/opt\/kafka\/config\/server.properties'&#13;\nExecStop=\/opt\/kafka\/bin\/kafka-server-stop.sh&#13;\nRestart=on-abnormal&#13;\n&#13;\n[Install]&#13;\nWantedBy=multi-user.target<\/pre>\n<p>Save and exit.<\/p>\n<p>Reload the systemd manager configuration.<\/p>\n<p class=\"command\">systemctl daemon-reload<\/p>\n<p>Now start Apache Zookeeper and Apache Kafka services.<\/p>\n<p class=\"command\">systemctl start zookeeper<br \/>systemctl enable zookeeper<\/p>\n<p>systemctl start kafka<br \/>systemctl enable kafka<\/p>\n<p><a class=\"fancybox\" id=\"img-6\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_kafka_on_ubuntu_1804\/big\/6.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu-3.png\" alt=\"Start Zookeeper and Kafka\" width=\"500\" height=\"192\" title=\"\"><\/a><\/p>\n<p>The apache zookeeper and Kafka are up and running.<\/p>\n<p>Zookeeper running under port &#8216;2181&#8217;, and Kafka on port &#8216;9092&#8217;, check it using the\u00a0<a href=\"https:\/\/www.howtoforge.com\/linux-netstat-command\/\" target=\"_blank\" rel=\"noopener noreferrer\">netstat<\/a> command below.<\/p>\n<p class=\"command\">netstat -plntu<\/p>\n<p><a class=\"fancybox\" id=\"img-7\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_kafka_on_ubuntu_1804\/big\/7.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu-4.png\" alt=\"Software is listening to its default ports\" width=\"500\" height=\"175\" title=\"\"><\/a><\/p>\n<h2 id=\"step-testing-apache-kafka\">Step 5 &#8211; Testing Apache Kafka<\/h2>\n<p>Login to the &#8216;kafka&#8217; user and go to the &#8216;bin\/&#8217; directory.<\/p>\n<p class=\"command\">su &#8211; kafka<br \/>cd bin\/<\/p>\n<p>Now create a new topic named &#8216;HakaseTesting&#8217; using the &#8216;kafka-topics.sh&#8217; executable file.<\/p>\n<p class=\"command\">.\/kafka-topics.sh &#8211;create &#8211;zookeeper localhost:2181 \\<br \/>&#8211;replication-factor 1 &#8211;partitions 1 \\<br \/>&#8211;topic HakaseTesting<\/p>\n<p>And run the &#8216;kafka-console-producer.sh&#8217; with the &#8216;HakaseTesting&#8217; topic.<\/p>\n<p class=\"command\">.\/kafka-console-producer.sh &#8211;broker-list localhost:9092 \\<br \/>&#8211;topic HakaseTesting<\/p>\n<p>Now open a new terminal and log in to the server, then login to the &#8216;kafka&#8217; user.<\/p>\n<p>Run &#8216;kafka-console-consumer.sh&#8217; for the &#8216;HakaseTesting&#8217; topic.<\/p>\n<p class=\"command\">.\/kafka-console-consumer.sh &#8211;bootstrap-server localhost:9092 \\<br \/>&#8211;topic HakaseTesting &#8211;from-beginning<\/p>\n<p>And when you type any input from the &#8216;kafka-console-producer.sh&#8217; shell, you will get the same result on the &#8216;kafka-console-consumer.sh&#8217; shell.<\/p>\n<p><a class=\"fancybox\" id=\"img-8\" href=\"https:\/\/www.howtoforge.com\/images\/how_to_install_apache_kafka_on_ubuntu_1804\/big\/8.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu-5.png\" alt=\"Testing Apache Kafka\" width=\"500\" height=\"376\" title=\"\"><\/a><\/p>\n<p>The installation and configuration for Apache Kafka on Ubuntu 18.04 has been completed successfully.<\/p>\n<h2 id=\"reference\">Reference<\/h2>\n<div class=\"authorbox\" readability=\"15\">\n<p><strong>About Muhammad Arul<\/strong><\/p>\n<p>Muhammad Arul is a freelance system administrator and technical writer. He is working with Linux Environments for more than 5 years, an Open Source enthusiast and highly motivated on Linux installation and troubleshooting. Mostly working with RedHat\/CentOS Linux and Ubuntu\/Debian, Nginx and Apache web server, Proxmox, Zimbra Administration, and Website Optimization. Currently learning about OpenStack and Container Technology.<\/p>\n<\/div>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Ftutorial%2Fubuntu-apache-kafka-installation%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Ftutorial%2Fubuntu-apache-kafka-installation%2F&amp;text=How+to+Install+Apache+Kafka+Distributed+Streaming+Platform+on+Ubuntu&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu-7.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu-8.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Ftutorial%2Fubuntu-apache-kafka-installation%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/10\/how-to-install-apache-kafka-distributed-streaming-platform-on-ubuntu-9.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Apache Kafka is a distributed streaming platform developed by Apache Software Foundation and written in Java and Scala. Apache Kafka was originally developed by LinkedIn, and was open sourced in 2011. Apache Kafka is used for building real-time streaming data pipeline that reliably gets data between system and applications. It provides a unified, high-throughput, and &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-6967","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=6967"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6967\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=6967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=6967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=6967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}