{"id":7682,"date":"2024-07-03T19:35:06","date_gmt":"2024-07-04T02:35:06","guid":{"rendered":"https:\/\/ioflood.com\/blog\/?p=7682"},"modified":"2024-07-03T19:35:06","modified_gmt":"2024-07-04T02:35:06","slug":"install-kafka-linux","status":"publish","type":"post","link":"https:\/\/ioflood.com\/blog\/install-kafka-linux\/","title":{"rendered":"How to Install Kafka | Kafka Quick Start Guide for Linux"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignright size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/ioflood.com\/blog\/wp-content\/uploads\/2024\/07\/Developer-presenting-detailed-install-Kafka-cli-methods-within-functional-kafka-quick-start-class-300x300.jpg\" alt=\"Developer presenting detailed install Kafka cli methods within functional kafka quick start class\" width=\"300\" height=\"300\" title=\"\"><\/figure>\n<\/div>\n<p>Handling real-time data streams are vital for our automated process at at <a href=\"https:\/\/ioflood.com\/\">IOFLOOD<\/a>. While discovering improved tools, kafka CLI stood out as a specialized command-line tool for managing Apache Kafka and real-time data. We have translated our practices into this tutorial for our <a href=\"https:\/\/ioflood.com\/bare-metal-cloud-server.php\">bare metal cloud server<\/a> customers looking for help within the Apache Kafka getting started phases.<\/p>\n<p><strong>In this tutorial, we will guide you through Kafka install steps for Linux systems.<\/strong> We will show you methods for both APT and YUM-based distributions, delve into compiling Kafka cli from source, installing a specific version, and finally, how to use the Kafka command and ensure it&#8217;s installed correctly.<\/p>\n<p>So, let&#8217;s dive in and begin our Linux Kafka quick start process!<\/p>\n<h2>TL;DR: How To Install Kafka CLI on Linux?<\/h2>\n<blockquote><p>\n  You can install Kafka by first downloading the Kafka binaries from the <a href=\"https:\/\/kafka.apache.org\/downloads\" target=\"_blank\" rel=\"noopener\">Apache website<\/a> with <code>wget https:\/\/downloads.apache.org\/kafka\/3.7.1\/kafka_2.13-3.7.1.tgz<\/code>. Then, extract the tar file with <code>tar xzf kafka_2.13-3.7.1.tgz<\/code>, configure, and start the Kafka server.\n<\/p><\/blockquote>\n<p>Here&#8217;s a basic example:<\/p>\n<pre><code class=\"language-bash line-numbers\">wget https:\/\/downloads.apache.org\/kafka\/3.7.1\/kafka_2.13-3.7.1.tgz\n\ntar xzf kafka_2.13-3.7.1.tgz\n\ncd kafka_2.13-3.7.1\n\nbin\/zookeeper-server-start.sh config\/zookeeper.properties &amp;\n\nbin\/kafka-server-start.sh config\/server.properties &amp;\n<\/code><\/pre>\n<p>This is just a basic way to install Kafka on Linux, but there&#8217;s much more to learn about installing and using Kafka. Continue reading for more detailed information and advanced usage scenarios.<\/p>\n<h2>The Basics: Install Kafka on Linux<\/h2>\n<p>Kafka is an open-source distributed streaming platform by Apache. It&#8217;s used to build real-time data pipelines and streaming apps. It&#8217;s horizontally scalable, fault-tolerant, and incredibly fast. This makes Kafka a go-to solution for a large variety of real-time data streaming needs.<\/p>\n<p>Now, let&#8217;s dive into how to install Kafka on your Linux system.<\/p>\n<h3>Kafka Install with APT<\/h3>\n<p>For Debian-based distributions, we use the APT package manager. Here&#8217;s how you can install Kafka using APT:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo apt-get update\nsudo apt-get install kafka\n\n# Output:\n# 'kafka is already the newest version (2.13-2.8.0).'\n<\/code><\/pre>\n<p>This command updates your package lists and then installs Kafka. The output message confirms that Kafka has been installed successfully.<\/p>\n<h3>Kafka Install with YUM<\/h3>\n<p>For Red Hat-based distributions, we use the YUM package manager. Here&#8217;s how you can install Kafka using YUM:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo yum update\nsudo yum install kafka\n\n# Output:\n# 'Package kafka-2.13_2.8.0.noarch already installed and latest version'\n<\/code><\/pre>\n<p>Similar to the APT commands, these commands update your package lists and then install Kafka. The output message confirms that Kafka has been installed successfully.<\/p>\n<p>Remember, these are basic installations. For more advanced scenarios, such as installing from source or installing different versions, continue reading to the Advanced Use section.<\/p>\n<h2>Source Code Kafka Quick Start<\/h2>\n<p>Sometimes, you may need to install Kafka from the source code. This could be due to the need for a specific version or to customize the installation.<\/p>\n<p>Here&#8217;s how you can install Kafka from the source code:<\/p>\n<pre><code class=\"language-bash line-numbers\">git clone https:\/\/github.com\/apache\/kafka.git\n\ncd kafka\n\ngradle\n\n# Output:\n# 'BUILD SUCCESSFUL in 2m 36s'\n<\/code><\/pre>\n<p>This command clones the Kafka repository, changes the directory to the Kafka folder, and then builds Kafka using Gradle. The output message confirms that Kafka has been built successfully.<\/p>\n<h2>Different Versions of Kafka CLI<\/h2>\n<p>Kafka has numerous versions, and you might need a specific one for compatibility or to use a particular feature. Here&#8217;s how you can install a specific version of Kafka.<\/p>\n<h3>Installing from Source<\/h3>\n<p>To install a specific version from source, you need to checkout the specific version before building with Gradle:<\/p>\n<pre><code class=\"language-bash line-numbers\">git clone https:\/\/github.com\/apache\/kafka.git\ncd kafka\ngit checkout 2.3.0\ngradle\n\n# Output:\n# 'BUILD SUCCESSFUL in 2m 36s'\n<\/code><\/pre>\n<h3>Installing with APT<\/h3>\n<p>To install a specific version with APT, you need to specify the version during installation:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo apt-get update\nsudo apt-get install kafka=2.3.0\n\n# Output:\n# 'kafka is already the newest version (2.3.0).'\n<\/code><\/pre>\n<h3>Installing with YUM<\/h3>\n<p>To install a specific version with YUM, you need to specify the version during installation:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo yum update\nsudo yum install kafka-2.3.0\n\n# Output:\n# 'Package kafka-2.3.0.noarch already installed and latest version'\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>Version<\/th>\n<th>Key Changes<\/th>\n<th>Compatibility<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2.3.0<\/td>\n<td>Added support for Java 11<\/td>\n<td>Compatible with all previous versions<\/td>\n<\/tr>\n<tr>\n<td>2.4.0<\/td>\n<td>Introduced Incremental Cooperative Rebalancing<\/td>\n<td>Compatible with all previous versions<\/td>\n<\/tr>\n<tr>\n<td>2.5.0<\/td>\n<td>Added support for non-key joining in KTable<\/td>\n<td>Not backwards compatible with versions below 2.3.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Use and Verify New Kafka Install<\/h2>\n<p>Once Kafka is installed, you can use the <code>kafka-topics<\/code> command to create a topic and then list all topics to verify that Kafka is working correctly.<\/p>\n<p>Here&#8217;s an example:<\/p>\n<pre><code class=\"language-bash line-numbers\">kafka-topics --create --topic test --partitions 1 --replication-factor 1 --bootstrap-server localhost:9092\nkafka-topics --list --bootstrap-server localhost:9092\n\n# Output:\n# 'test'\n<\/code><\/pre>\n<p>This command creates a topic named &#8216;test&#8217; and then lists all topics. The output shows the &#8216;test&#8217; topic, confirming that Kafka is installed and working correctly.<\/p>\n<h2>How to Install Kafka in Docker<\/h2>\n<p>Docker is a popular platform used to develop, ship, and run applications. By installing Kafka using Docker, you can ensure that the software will run the same, regardless of its environment.<\/p>\n<p>Here&#8217;s how to install Kafka using Docker:<\/p>\n<pre><code class=\"language-bash line-numbers\">docker pull confluentinc\/cp-kafka\n\ndocker run -d --name=kafka -p 9092:9092 -e KAFKA_ZOOKEEPER_CONNECT=your.zookeeper.connect:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT:\/\/your.kafka.host.name:9092 -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 confluentinc\/cp-kafka\n\n# Output:\n# 'Successfully tagged confluentinc\/cp-kafka:latest'\n<\/code><\/pre>\n<p>This command pulls the Kafka image and then runs a new Kafka container. The output message confirms that the Kafka Docker image has been successfully created.<\/p>\n<h2>Install Kafka with Kubernetes<\/h2>\n<p>Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers. Here&#8217;s how to install Kafka using Kubernetes:<\/p>\n<pre><code class=\"language-bash line-numbers\">helm repo add confluentinc https:\/\/confluentinc.github.io\/cp-helm-charts\/\nhelm repo update\nhelm install my-kafka confluentinc\/cp-helm-charts\n\n# Output:\n# 'NAME: my-kafka'\n# 'STATUS: deployed'\n<\/code><\/pre>\n<p>This command adds the Confluent Helm chart repository, updates the repo, and then installs Kafka using Helm. The output message confirms that Kafka has been successfully deployed on Kubernetes.<\/p>\n<table>\n<thead>\n<tr>\n<th>Method<\/th>\n<th>Advantages<\/th>\n<th>Disadvantages<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Docker<\/td>\n<td>Simplifies configuration, Isolation from other applications, Easy version control<\/td>\n<td>Requires Docker knowledge, More resources usage<\/td>\n<\/tr>\n<tr>\n<td>Kubernetes<\/td>\n<td>Scalability, High Availability, Automated rollouts and rollbacks<\/td>\n<td>More complex, Requires Kubernetes knowledge<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>While these alternative methods might seem more complex, they offer greater control and scalability, especially in a microservices environment.<\/p>\n<h2>Solving Kafka Install Issues<\/h2>\n<p>While installing Kafka on Linux, you may encounter a few common issues. Let&#8217;s discuss these problems and their solutions to ensure a smooth Kafka installation process.<\/p>\n<h3>Issue: Kafka Service Not Starting<\/h3>\n<p>Sometimes, after installation, the Kafka service might not start. This can be due to various reasons such as incorrect configuration or port conflicts.<\/p>\n<p>To check if Kafka is running, you can use the following command:<\/p>\n<pre><code class=\"language-bash line-numbers\">systemctl status kafka\n\n# Output:\n# 'kafka.service - Apache Kafka\n# Loaded: loaded (\/usr\/lib\/systemd\/system\/kafka.service; disabled; vendor preset: disabled)\n# Active: inactive (dead)'\n<\/code><\/pre>\n<p>If Kafka is not running, you can start it using the following command:<\/p>\n<pre><code class=\"language-bash line-numbers\">systemctl start kafka\n\n# Output:\n# No output on success\n<\/code><\/pre>\n<h3>Issue: Kafka Version Conflict<\/h3>\n<p>If you have installed Kafka from the source and there is a version already installed through the package manager, it can lead to a version conflict. To resolve this, you need to uninstall the existing version before installing a new one.<\/p>\n<p>Here&#8217;s how to uninstall Kafka:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo apt-get remove kafka\n\n# Output:\n# 'The following packages will be REMOVED:\n#   kafka'\n<\/code><\/pre>\n<h3>Issue: Kafka Port Conflict<\/h3>\n<p>Kafka uses port 9092 by default. If another service is using this port, Kafka will not start. You can check the port usage using the following command:<\/p>\n<pre><code class=\"language-bash line-numbers\">sudo lsof -i:9092\n\n# Output:\n# 'COMMAND  PID USER   FD   TYPE DEVICE SIZE\/OFF NODE NAME\n# java    2034 kafka  152u  IPv6  21560      0t0  TCP *:9092 (LISTEN)'\n<\/code><\/pre>\n<p>If the port is in use, you need to stop the service using the port or change the Kafka port.<\/p>\n<p>Remember, troubleshooting is a normal part of any installation process. Don&#8217;t get discouraged if you encounter issues. With these tips, you should be able to resolve common problems and get your Kafka service running on Linux.<\/p>\n<h2>Understanding What is Kafka<\/h2>\n<p>Before delving into the installation process of Kafka on Linux, it&#8217;s essential to understand what Kafka is and its underlying architecture. This will not only make the installation process more meaningful but also enhance your ability to troubleshoot any potential issues.<\/p>\n<h3>What is Kafka?<\/h3>\n<p>Apache Kafka is an open-source distributed event streaming platform used by thousands of companies for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications.<\/p>\n<pre><code class=\"language-bash line-numbers\"># Kafka version check\nkafka-topics --version\n\n# Output:\n# '2.8.0'\n<\/code><\/pre>\n<p>The above command checks the installed Kafka version. The output shows the version of the Kafka installed on your system.<\/p>\n<h3>Kafka Architecture<\/h3>\n<p>The architecture of Kafka is made up of a few key components: Producers, Consumers, Brokers, Topics, Partitions, and Clusters.<\/p>\n<ul>\n<li><strong>Producers<\/strong> are processes that publish data (push messages) into Kafka topics within the broker.<\/li>\n<li><strong>Consumers<\/strong> read data from brokers.<\/li>\n<li><strong>Brokers<\/strong> are a system running the Kafka software, and brokers are containers that hold topic log partitions.<\/li>\n<li><strong>Topics<\/strong> are a particular stream of data. Topics in Kafka are always multi-subscriber.<\/li>\n<li><strong>Partitions<\/strong> allow you to parallelize a topic by splitting the data in a particular topic across multiple brokers.<\/li>\n<li><strong>Clusters<\/strong> are a group of computers. The Kafka cluster stores stream records in categories called topics.<\/li>\n<\/ul>\n<h3>The Role of Kafka in Data Pipelines<\/h3>\n<p>Kafka plays a significant role in real-time data pipelines. It&#8217;s designed to handle real-time data feeds with low latency and high throughput. It also integrates well with Big Data infrastructure and data processing frameworks, making it a popular choice for real-time analytics.<\/p>\n<h3>The Importance of Real-Time Data Processing<\/h3>\n<p>Real-time data processing allows businesses to react without delay. It can help businesses to make crucial decisions promptly, offer better customer service, and stay ahead of the competition.<\/p>\n<p>Understanding these fundamentals will make the Kafka installation process on Linux more comprehensible and manageable.<\/p>\n<h2>Practical Uses of Kafka<\/h2>\n<p>Kafka has become an integral part of big data applications due to its ability to handle real-time data feeds. It&#8217;s often used in data architectures and big data workflows, especially in scenarios where real-time processing is required.<\/p>\n<p>A common use case is log or event data aggregation where Kafka consolidates data from different sources and pushes them into a real-time analytics system or a big data store.<\/p>\n<h3>Kafka in Microservices Architecture<\/h3>\n<p>In a microservices architecture, Kafka serves as a backbone for enabling communication between different services. It provides an asynchronous, decoupled communication mechanism that is ideal for microservices.<\/p>\n<p>With Kafka, microservices can publish events to Kafka topics, and other microservices can consume from these topics. This allows for a loosely coupled architecture where services can evolve independently.<\/p>\n<h2>Exploring Further Topics<\/h2>\n<p>Kafka Streams is a client library for building applications and microservices, where the input and output data are stored in Kafka clusters. It combines the simplicity of writing and deploying standard Java and Scala applications on the client side with the benefits of Kafka&#8217;s server-side cluster technology.<\/p>\n<p>Kafka Connect, on the other hand, is a tool for scalably and reliably streaming data between Apache Kafka and other systems. It makes it simple to quickly define connectors that move large data sets into and out of Kafka.<\/p>\n<h3>Further Resources for Kafka Proficiency<\/h3>\n<p>To further your understanding of Kafka and its applications, here are a few resources that you might find helpful:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tutorialspoint.com\/apache_kafka\/index.htm\" target=\"_blank\" rel=\"noopener\">Apache Kafka CLI: A Streaming System<\/a> &#8211; A comprehensive guide to understanding Kafka and its architecture.<\/p>\n<\/li>\n<li>\n<p><a href=\"http:\/\/kafka.apache.org\/documentation\/#introduction\" target=\"_blank\" rel=\"noopener\">Kafka Quick Start: The Definitive Guide<\/a> &#8211; From the official Apache Kafka website provides a detailed introduction.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.confluent.io\/blog\/how-to-get-started-with-apache-kafka\/\" target=\"_blank\" rel=\"noopener\">Apache Kafka Getting Started Tutorial<\/a> &#8211; A practical guide to getting started with Kafka.<\/p>\n<\/li>\n<\/ol>\n<h2>Recap: Install Kafka CLI in Linux<\/h2>\n<p>In this comprehensive guide, we&#8217;ve ventured into the world of Kafka, a powerful open-source distributed streaming platform. We&#8217;ve explored how to install Kafka on Linux, starting from basic methods and moving on to more advanced techniques.<\/p>\n<p>We started off with the basics, understanding how to install Kafka using package managers like APT and YUM. We then delved into more advanced territory, learning how to install Kafka from the source code, how to install specific versions, and how to use and verify the Kafka installation.<\/p>\n<p>Along the way, we tackled common challenges you might face when installing Kafka on Linux, such as service not starting, version conflicts, and port conflicts, providing you with solutions for each issue.<\/p>\n<p>We also looked at alternative approaches to Kafka installation like Docker and Kubernetes, weighing their advantages and disadvantages. Here&#8217;s a quick comparison of these methods:<\/p>\n<table>\n<thead>\n<tr>\n<th>Method<\/th>\n<th>Advantages<\/th>\n<th>Disadvantages<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Docker<\/td>\n<td>Simplifies configuration, Isolation from other applications, Easy version control<\/td>\n<td>Requires Docker knowledge, More resources usage<\/td>\n<\/tr>\n<tr>\n<td>Kubernetes<\/td>\n<td>Scalability, High Availability, Automated rollouts and rollbacks<\/td>\n<td>More complex, Requires Kubernetes knowledge<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Whether you&#8217;re just starting out with Kafka or you&#8217;re looking to level up your skills, we hope this guide has given you a deeper understanding of Kafka installation on Linux.<\/p>\n<p>With its ability to handle real-time data feeds with low latency and high throughput, Kafka is a powerful tool for data streaming. Now, you&#8217;re well equipped to install and use Kafka on your Linux system. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Handling real-time data streams are vital for our automated process at at IOFLOOD. While discovering improved tools, kafka CLI stood out as a specialized command-line tool for managing Apache Kafka and real-time data. We have translated our practices into this tutorial for our bare metal cloud server customers looking for help within the Apache Kafka [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":21738,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-7682","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","cat-3-id","has_thumb"],"_links":{"self":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/7682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/comments?post=7682"}],"version-history":[{"count":12,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/7682\/revisions"}],"predecessor-version":[{"id":21803,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/posts\/7682\/revisions\/21803"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media\/21738"}],"wp:attachment":[{"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/media?parent=7682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/categories?post=7682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ioflood.com\/blog\/wp-json\/wp\/v2\/tags?post=7682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}