Kafka – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Thu, 15 Dec 2022 05:57:03 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Install Apache Kafka on Ubuntu 22.04 https://tecadmin.net/how-to-install-apache-kafka-on-ubuntu-22-04/ https://tecadmin.net/how-to-install-apache-kafka-on-ubuntu-22-04/#respond Sun, 05 Jun 2022 07:53:28 +0000 https://tecadmin.net/?p=29849 Apache Kafka is an open-source, distributed event streaming platform developed by the Apache Software Foundation. This is written in Scala and Java programming languages. You can install Kafka on any platform that supports Java programming language. This tutorial provides you with step-by-step instructions to install Apache Kafka on Ubuntu 22.04 LTS Linux system. You will [...]

The post How to Install Apache Kafka on Ubuntu 22.04 appeared first on TecAdmin.

]]>
Apache Kafka is an open-source, distributed event streaming platform developed by the Apache Software Foundation. This is written in Scala and Java programming languages. You can install Kafka on any platform that supports Java programming language.

This tutorial provides you with step-by-step instructions to install Apache Kafka on Ubuntu 22.04 LTS Linux system. You will also learn to create topics in Kafka and run producer and consumer nodes.

Prerequisites

You must have sudo privileged account access to the Ubuntu 22.04 Linux system.

Step 1 – Installing Java

We can run the Apache Kafka server on systems that support Java. So make sure, you have Java installed on your Ubuntu system.

Use the following commands to install OpenJDK on your Ubuntu system from the official repositories.

sudo apt update  
sudo apt install default-jdk 

Verify the current active Java version.

java --version 
Output:
openjdk version "11.0.15" 2022-04-19 OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1) OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1, mixed mode, sharing)

Step 2 – Download Latest Apache Kafka

You can download the latest Apache Kafka binary files from its official download page. Alternativaly you can download Kafka 3.2.0 with the below command.

wget https://dlcdn.apache.org/kafka/3.2.0/kafka_2.13-3.2.0.tgz 

Then extract the downloaded archive file and place them under /usr/local/kafka directory.

tar xzf kafka_2.13-3.2.0.tgz 
sudo mv kafka_2.13-3.2.0 /usr/local/kafka 

Step 3 – Create Systemd Startup Scripts

Now, create systemd unit files for the Zookeeper and Kafka services. That will help you to start/stop the Kafka service in an easy way.

First, create a systemd unit file for Zookeeper:

sudo nano /etc/systemd/system/zookeeper.service 

And add the following content:

[Unit]
Description=Apache Zookeeper server
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

Save the file and close it.

Next, create a systemd unit file for the Kafka service:

sudo nano /etc/systemd/system/kafka.service 

Add the below content. Make sure to set the correct JAVA_HOME path as per the Java installed on your system.

[Unit]
Description=Apache Kafka Server
Documentation=http://kafka.apache.org/documentation.html
Requires=zookeeper.service

[Service]
Type=simple
Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64"
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

Save the file and close.

Reload the systemd daemon to apply new changes.

sudo systemctl daemon-reload 

This will reload all the systemd files in the system environment.

Step 4 – Start Zookeeper and Kafka Services

Let’s start both services one by one. First, you need to start the ZooKeeper service and then start Kafka. Use the systemctl command to start a single-node ZooKeeper instance.

sudo systemctl start zookeeper 
sudo systemctl start kafka 

Verify both of the services status:

sudo systemctl status zookeeper 
sudo systemctl status kafka 

That’s it. You have successfully installed the Apache Kafka server on Ubuntu 22.04 system. Next, we will create topics in the Kafka server.

Step 5 – Create a Topic in Kafka

Kafka provides multiple pre-built shell script to work on it. First, create a topic named “testTopic” with a single partition with single replica:

cd /usr/local/kafka 
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic testTopic 
Output
Created topic testTopic.

Here:

  • Use --create option to create a new topic
  • The --replication-factor describes how many copies of data will be created. As we are running with a single instance keep this value 1.
  • Set the --partitions options as the number of brokers you want your data to be split between. As we are running with a single broker keep this value 1.
  • The --topic define the name of the topic

You can create multiple topics by running the same command as above. After that, you can see the created topics on Kafka by the running below command:

bin/kafka-topics.sh --list --bootstrap-server localhost:9092 

The output looks like the below screenshot:

How to Install Apache Kafka on Ubuntu 22.04
Listing Kafka Topics

Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

Step 6 – Send and Receive Messages in Kafka

The “producer” is the process responsible for put data into our Kafka. The Kafka comes with a command-line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. The default Kafka sends each line as a separate message.

Let’s run the producer and then type a few messages into the console to send to the server.

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic 

>Welcome to kafka
>This is my first topic
>

You can exit this command or keep this terminal running for further testing. Now open a new terminal to the Kafka consumer process on the next step.

Kafka also has a command-line consumer to read data from the Kafka cluster and display messages to standard output.

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testTopic --from-beginning 

Welcome to kafka
This is my first topic

Now, If you have still running Kafka producer in another terminal. Just type some text on that producer terminal. it will immediately be visible on the consumer terminal. See the below screenshot of Kafka producer and consumer in working:

How to Setup Apache Kafka on Ubuntu 22.04
Running Apache Kafka Producer and Consumer Node

Conclusion

This tutorial helped you to install and configure the Apache Kafka server on an Ubuntu 22.04 Linux system. Additionally, you learned to create a new topic in the Kafka server and run a sample production and consumer process with Apache Kafka.

The post How to Install Apache Kafka on Ubuntu 22.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-install-apache-kafka-on-ubuntu-22-04/feed/ 0
(Resolved) zookeeper is not a recognized option – Kafka https://tecadmin.net/resolved-zookeeper-is-not-a-recognized-option-kafka/ https://tecadmin.net/resolved-zookeeper-is-not-a-recognized-option-kafka/#comments Fri, 06 May 2022 07:28:53 +0000 https://tecadmin.net/?p=29877 Problem Recently, I installed Apache Kafka on the Ubuntu system. When tried to run the consumer console script, I found the error message that “zookeeper is not a recognized option”. ./bin/kafka-console-consumer.sh --topic testTopic --zookeeper localhost:9092 zookeeper is not a recognized option Option Description ------ ----------- --bootstrap-server --consumer-property properties in the form key=value to ... ... [...]

The post (Resolved) zookeeper is not a recognized option – Kafka appeared first on TecAdmin.

]]>
Problem

Recently, I installed Apache Kafka on the Ubuntu system. When tried to run the consumer console script, I found the error message that “zookeeper is not a recognized option”.

./bin/kafka-console-consumer.sh --topic testTopic --zookeeper localhost:9092 
zookeeper is not a recognized option
Option                                   Description
------                                   -----------
--bootstrap-server 
--consumer-property                            properties in the form key=value to
...
...

Solution

After searching a bit time, I visited to Apache Kafa QUICKSTART guide. Here I found the solution that Kafka has removed --zookeeper option and replaced it with a new option --bootstrap-server .

So the new command would be like:

./bin/kafka-console-consumer.sh --topic testTopic --bootstrap-server  localhost:9092 

Hope this will help you to resolve the Kafka issue.

The post (Resolved) zookeeper is not a recognized option – Kafka appeared first on TecAdmin.

]]>
https://tecadmin.net/resolved-zookeeper-is-not-a-recognized-option-kafka/feed/ 1
How to Install Apache Kafka on Ubuntu 20.04 https://tecadmin.net/how-to-install-apache-kafka-on-ubuntu-20-04/ https://tecadmin.net/how-to-install-apache-kafka-on-ubuntu-20-04/#comments Sun, 14 Feb 2021 16:40:56 +0000 https://tecadmin.net/?p=23427 Apache Kafka is an open-source, distributed event streaming platform developed by the Apache Software Foundation. This is written in Scala and Java programming languages. You can install Kafka on any platform supporting Java. This tutorial described you step-by-step tutorial to install Apache Kafka on Ubuntu 20.04 LTS Linux system. You will also learn to create [...]

The post How to Install Apache Kafka on Ubuntu 20.04 appeared first on TecAdmin.

]]>
Apache Kafka is an open-source, distributed event streaming platform developed by the Apache Software Foundation. This is written in Scala and Java programming languages. You can install Kafka on any platform supporting Java.

This tutorial described you step-by-step tutorial to install Apache Kafka on Ubuntu 20.04 LTS Linux system. You will also learn to create topics in Kafka and run producer and consumer nodes.

Prerequisites

You must have sudo privileged account access to the Ubuntu 20.04 Linux system.

Step 1 – Installing Java

Apache Kafka can be run on all platforms supported by Java. In order to set up Kafka on the Ubuntu system, you need to install java first. As we know, Oracle java is now commercially available, So we are using its open-source version OpenJDK.

Execute the below command to install OpenJDK on your system from the official PPA’s.

sudo apt update 
sudo apt install default-jdk

Verify the current active Java version.

java --version 

openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

Step 2 – Download Latest Apache Kafka

Download the Apache Kafka binary files from its official download website. You can also select any nearby mirror to download.

wget https://dlcdn.apache.org/kafka/3.2.0/kafka_2.13-3.2.0.tgz 

Then extract the archive file

tar xzf kafka_2.13-3.2.0.tgz 
sudo mv kafka_2.13-3.2.0 /usr/local/kafka 

Step 3 – Creating Systemd Unit Files

Now, you need to create systemd unit files for the Zookeeper and Kafka services. Which will help you to start/stop the Kafka service in an easy way.

First, create a systemd unit file for Zookeeper:

vim /etc/systemd/system/zookeeper.service

And add the following content:

[Unit]
Description=Apache Zookeeper server
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

Save the file and close it.

Next, to create a systemd unit file for the Kafka service:

vim /etc/systemd/system/kafka.service

Add the below content. Make sure to set the correct JAVA_HOME path as per the Java installed on your system.

[Unit]
Description=Apache Kafka Server
Documentation=http://kafka.apache.org/documentation.html
Requires=zookeeper.service

[Service]
Type=simple
Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

Save the file and close.

Reload the systemd daemon to apply new changes.

systemctl daemon-reload

Step 4 – Start Kafka and Zookeeper Service

First, you need to start the ZooKeeper service and then start Kafka. Use the systemctl command to start a single-node ZooKeeper instance.

sudo systemctl start zookeeper

Now start the Kafka server and view the running status:

sudo systemctl start kafka
sudo systemctl status kafka

Kafka service on ubuntu

All done. The Kafka installation has been successfully completed. The part of this tutorial will help you to work with the Kafka server.

Step 5 – Create a Topic in Kafka

Kafka provides multiple pre-built shell scripts to work on it. First, create a topic named “testTopic” with a single partition with a single replica:

cd /usr/local/kafka
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic testTopic

Created topic testTopic.

The replication factor describes how many copies of data will be created. As we are running with a single instance keep this value 1.

Set the partition options as the number of brokers you want your data to be split between. As we are running with a single broker keep this value 1.

You can create multiple topics by running the same command as above. After that, you can see the created topics on Kafka by the running below command:

bin/kafka-topics.sh --list --bootstrap-server localhost:9092

[output]
testTopic

Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

Step 6 – Send and Receive Messages in Kafka

The “producer” is the process responsible for put data into our Kafka. The Kafka comes with a command-line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. The default Kafka sends each line as a separate message.

Let’s run the producer and then type a few messages into the console to send to the server.

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic

>Welcome to kafka
>This is my first topic
>

You can exit this command or keep this terminal running for further testing. Now open a new terminal to the Kafka consumer process on the next step.

Step 7 – Using Kafka Consumer

Kafka also has a command-line consumer to read data from the Kafka cluster and display messages to standard output.

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testTopic --from-beginning

Welcome to kafka
This is my first topic

Now, If you have still running Kafka producer (Step #6) in another terminal. Just type some text on that producer terminal. it will immediately be visible on the consumer terminal. See the below screenshot of the Kafka producer and consumer in working:

Conclusion

This tutorial helped you to install and configure the Apache Kafka service on an Ubuntu system. Additionally, you learned to create a new topic in the Kafka server and run a sample production and consumer process with Apache Kafka.

The post How to Install Apache Kafka on Ubuntu 20.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-install-apache-kafka-on-ubuntu-20-04/feed/ 6
How to Install Apache Kafka on Debian 11/10 https://tecadmin.net/install-apache-kafka-debian/ https://tecadmin.net/install-apache-kafka-debian/#comments Sun, 05 Apr 2020 06:06:02 +0000 https://tecadmin.net/?p=20498 Apache Kafka is a distributed streaming platform. It is useful for building real-time streaming data pipelines to get data between the systems or applications. Another useful feature is real-time streaming applications that can transform streams of data or react on a stream of data. This tutorial will help you to install Apache Kafka on Debian [...]

The post How to Install Apache Kafka on Debian 11/10 appeared first on TecAdmin.

]]>
Apache Kafka is a distributed streaming platform. It is useful for building real-time streaming data pipelines to get data between the systems or applications. Another useful feature is real-time streaming applications that can transform streams of data or react on a stream of data.

This tutorial will help you to install Apache Kafka on Debian 11, Debian 10, and Debian 9 Linux systems.

Step 1 – Install Java

Apache Kafka required Java to run. You must have java installed on your system. Execute below command to install default OpenJDK on your system from the official PPA’s.

sudo apt update
sudo apt install default-jdk

Step 2 – Download Apache Kafka

Download the Apache Kafka binary files from its official download website. You can also select any nearby mirror to download.

wget https://dlcdn.apache.org/kafka/3.2.0/kafka_2.13-3.2.0.tgz 

Then extract the archive file

tar xzf kafka_2.13-3.2.0.tgz 
sudo mv kafka_2.13-3.2.0 /usr/local/kafka 

Step 3 – Create Systemd Unit Files

Next, create systemd unit files for the Zookeeper and Kafka service. This will help to manage Kafka services to start/stop using the systemctl command.

First, create systemd unit file for Zookeeper with below command:

vim /etc/systemd/system/zookeeper.service

Add below content:

[Unit]
Description=Apache Zookeeper server
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

Save the file and close it.

Next, to create a Kafka systemd unit file using the following command:

vim /etc/systemd/system/kafka.service

Add the below content. Make sure to set the correct JAVA_HOME path as per the Java installed on your system.

[Unit]
Description=Apache Kafka Server
Documentation=http://kafka.apache.org/documentation.html
Requires=zookeeper.service

[Service]
Type=simple
Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

Save file and close.

Reload the systemd daemon to apply new changes.

systemctl daemon-reload

Step 4 – Start Kafka Server

Kafka required ZooKeeper so first, start a ZooKeeper server on your system. You can use the script available with Kafka to get start a single-node ZooKeeper instance.

sudo systemctl start zookeeper

Now start the Kafka server and view the running status:

sudo systemctl start kafka
sudo systemctl status kafka

Intalling Apache Kafka on Debian

All done. The Kafka installation has been successfully completed. The part of this tutorial will help you to work with the Kafka server.

Step 5 – Create a Topic in Kafka

Kafka provides multiple pre-built shell script to work on it. First, create a topic named “testTopic” with a single partition with single replica:

cd /usr/local/kafka
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic testTopic

Created topic testTopic.

The replication-factor describes how many copies of data will be created. As we are running with a single instance keep this value 1.

Set the partitions options as the number of brokers you want your data to be split between. As we are running with a single broker keep this value 1.

You can create multiple topics by running the same command as above. After that, you can see the created topics on Kafka by the running below command:

bin/kafka-topics.sh --list --zookeeper localhost:9092

testTopic
TecAdminTutorial1
TecAdminTutorial2

Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

Step 6 – Send Messages to Kafka

The “producer” is the process responsible for put data into our Kafka. The Kafka comes with a command-line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. The default Kafka sends each line as a separate message.

Let’s run the producer and then type a few messages into the console to send to the server.

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic

>Welcome to kafka
>This is my first topic
>

You can exit this command or keep this terminal running for further testing. Now open a new terminal to the Kafka consumer process on the next step.

Step 7 – Using Kafka Consumer

Kafka also has a command-line consumer to read data from the Kafka cluster and display messages to standard output.

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testTopic --from-beginning

Welcome to kafka
This is my first topic

Now, If you have still running Kafka producer (Step #6) in another terminal. Just type some text on that producer terminal. it will immediately visible on consumer terminal. See the below screenshot of Kafka producer and consumer in working:

Install Kafka on Debian

Conclusion

You have successfully installed and configured the Kafka service on a Debian Linux system.

The post How to Install Apache Kafka on Debian 11/10 appeared first on TecAdmin.

]]>
https://tecadmin.net/install-apache-kafka-debian/feed/ 2
How to Install Apache Kafka on CentOS 8 https://tecadmin.net/install-apache-kafka-centos-8/ https://tecadmin.net/install-apache-kafka-centos-8/#comments Mon, 02 Mar 2020 14:41:15 +0000 https://tecadmin.net/?p=20502 Apache Kafka is a distributed streaming platform. It is useful for building real-time streaming data pipelines to get data between the systems or applications. Another useful feature is real-time streaming applications that can transform streams of data or react on a stream of data. This tutorial will help you to install Apache Kafka CentOS 8 [...]

The post How to Install Apache Kafka on CentOS 8 appeared first on TecAdmin.

]]>
Apache Kafka is a distributed streaming platform. It is useful for building real-time streaming data pipelines to get data between the systems or applications. Another useful feature is real-time streaming applications that can transform streams of data or react on a stream of data.

This tutorial will help you to install Apache Kafka CentOS 8 or RHEL 8 Linux systems.

Prerequisites

Step 1 – Install Java

You must have Java installed on your system to run Apache Kafka. You can install OpenJDK on your machine by executing the following command. Also, install some other required tools.

sudo dnf install java-11-openjdk wget vim 

Step 2 – Download Apache Kafka

Download the Apache Kafka binary files from its official download website. You can also select any nearby mirror to download.

wget https://dlcdn.apache.org/kafka/3.2.0/kafka_2.13-3.2.0.tgz 

Then extract the archive file

tar xzf kafka_2.13-3.2.0.tgz 
sudo mv kafka_2.13-3.2.0 /usr/local/kafka 

Step 3 – Setup Kafka Systemd Unit Files

CentOS 8 uses systemd to manage its services state. So we need to create systemd unit files for the Zookeeper and Kafka service. Which helps us to manage Kafka services to start/stop.

First, create systemd unit file for Zookeeper with below command:

vim /etc/systemd/system/zookeeper.service

Add below contnet:

[Unit]
Description=Apache Zookeeper server
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
ExecStart=/usr/bin/bash /usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
ExecStop=/usr/bin/bash /usr/local/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

Save the file and close it.

Next, to create a Kafka systemd unit file using the following command:

vim /etc/systemd/system/kafka.service

Add the below content. Make sure to set the correct JAVA_HOME path as per the Java installed on your system.

[Unit]
Description=Apache Kafka Server
Documentation=http://kafka.apache.org/documentation.html
Requires=zookeeper.service

[Service]
Type=simple
Environment="JAVA_HOME=/usr/lib/jvm/jre-11-openjdk"
ExecStart=/usr/bin/bash /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/bin/bash /usr/local/kafka/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

Save the file and close it.

Reload the systemd daemon to apply changes.

systemctl daemon-reload

Step 4 – Start Kafka Server

Kafka required ZooKeeper so first, start a ZooKeeper server on your system. You can use the script available with Kafka to get start a single-node ZooKeeper instance.

sudo systemctl start zookeeper

Now start the Kafka server and view the running status:

sudo systemctl start kafka
sudo systemctl status kafka

How to Install Apache Kafka CentOS 8

All done. You have successfully installed Kafka on your CentOS 8. The next part of this tutorial will help you to create topics in the Kafka cluster and work with the Kafka producer and consumer service.

Step 5 – Creating Topics in Apache Kafka

Apache Kafka provides multiple shell script to work on it. First, create a topic named “testTopic” with a single partition with single replica:

cd /usr/local/kafka
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic testTopic

Created topic testTopic.

The replication-factor describes how many copies of data will be created. As we are running with a single instance keep this value 1.

Set the partitions options as the number of brokers you want your data to be split between. As we are running with a single broker keep this value 1.

You can create multiple topics by running the same command as above. After that, you can see the created topics on Kafka by the running below command:

bin/kafka-topics.sh --list --zookeeper localhost:9092

testTopic
KafkaonCentOS8
TutorialKafkaInstallCentOS8

Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

Step 6 – Apache Kafka Producer and Consumer

The “producer” is the process responsible for put data into our Kafka. The Kafka comes with a command-line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. The default Kafka sends each line as a separate message.

Let’s run the producer and then type a few messages into the console to send to the server.

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic

>Welcome to kafka
>This is my first topic
>

Now open a new terminal to run the Apache Kafka consumer process. Kafka also provides and command-line consumer to read data from the Kafka cluster and display messages to the standard output.

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testTopic --from-beginning

Welcome to kafka
This is my first topic

The –from-beginning option is used to read messages from the beginning of the selected topic. You can skip this option to read the latest messages only.

For example, Run the Kafka producer and consumer in the separate terminals. Just type some text on that producer terminal. it will immediately visible on the consumer terminal. See the below screenshot of Kafka producer and consumer in working:

Kafka consumer and producer in action

Conclusion

You have successfully installed and configured the Kafka service on the CentOS 8 Linux machine.

The post How to Install Apache Kafka on CentOS 8 appeared first on TecAdmin.

]]>
https://tecadmin.net/install-apache-kafka-centos-8/feed/ 6
How to Install Apache Kafka on Ubuntu 18.04 https://tecadmin.net/install-apache-kafka-ubuntu/ https://tecadmin.net/install-apache-kafka-ubuntu/#comments Sat, 10 Mar 2018 14:49:03 +0000 https://tecadmin.net/?p=15426 Apache Kafka is a distributed streaming platform. It is useful for building real-time streaming data pipelines to get data between the systems or applications. Another useful feature is real-time streaming applications that can transform streams of data or react to a stream of data. This tutorial will help you to install Apache Kafka on Ubuntu [...]

The post How to Install Apache Kafka on Ubuntu 18.04 appeared first on TecAdmin.

]]>
Apache Kafka is a distributed streaming platform. It is useful for building real-time streaming data pipelines to get data between the systems or applications. Another useful feature is real-time streaming applications that can transform streams of data or react to a stream of data.

This tutorial will help you to install Apache Kafka on Ubuntu 18.04, and Ubuntu 16.04 Linux systems.

Step 1 – Install Java

Apache Kafka required Java to run. You must have java installed on your system. Execute the below command to install default OpenJDK on your system from the official PPA’s. You can also install the specific version of from here.

sudo apt update 
sudo apt install default-jdk 

Step 2 – Download Apache Kafka

Download the Apache Kafka binary files from its official download website. You can also select any nearby mirror to download.

wget https://dlcdn.apache.org/kafka/3.2.0/kafka_2.13-3.2.0.tgz 

Then extract the archive file

tar xzf kafka_2.13-3.2.0.tgz 
sudo mv kafka_2.13-3.2.0 /usr/local/kafka 

Step 3 – Setup Kafka Systemd Unit Files

Next, create systemd unit files for the Zookeeper and Kafka service. This will help to manage Kafka services to start/stop using the systemctl command.

First, create systemd unit file for Zookeeper with below command:

sudo vim /etc/systemd/system/zookeeper.service 

Add below content:

[Unit]
Description=Apache Zookeeper server
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

Save the file and close it.

Next, to create a Kafka systemd unit file using the following command:

sudo vim /etc/systemd/system/kafka.service 

Add the below content. Make sure to set the correct JAVA_HOME path as per the Java installed on your system.

[Unit]
Description=Apache Kafka Server
Documentation=http://kafka.apache.org/documentation.html
Requires=zookeeper.service

[Service]
Type=simple
Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh

[Install]
WantedBy=multi-user.target

Save the file and close.

Reload the systemd daemon to apply new changes.

systemctl daemon-reload 

Step 4 – Start Kafka Server

Kafka required ZooKeeper so first, start a ZooKeeper server on your system. You can use the script available with Kafka to get start a single-node ZooKeeper instance.

sudo systemctl start zookeeper 

Now start the Kafka server and view the running status:

sudo systemctl start kafka 
sudo systemctl status kafka 

Kafka service on ubuntu

All done. The Kafka installation has been successfully completed. This part of this tutorial will help you to work with the Kafka server.

Step 5 – Create a Topic in Kafka

Kafka provides multiple pre-built shell script to work on it. First, create a topic named “testTopic” with a single partition with single replica:

cd /usr/local/kafka 
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic testTopic 

Created topic testTopic.

The replication factor describes how many copies of data will be created. As we are running with a single instance keep this value 1.

Set the partition options as the number of brokers you want your data to be split between. As we are running with a single broker keep this value 1.

You can create multiple topics by running the same command as above. After that, you can see the created topics on Kafka by the running below command:

bin/kafka-topics.sh --list --zookeeper localhost:9092 

testTopic
TecAdminTutorial1
TecAdminTutorial2

Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

Step 6 – Send Messages to Kafka

The “producer” is the process responsible for put data into our Kafka. The Kafka comes with a command-line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. The default Kafka sends each line as a separate message.

Let’s run the producer and then type a few messages into the console to send to the server.

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic testTopic

>Welcome to kafka
>This is my first topic
>

You can exit this command or keep this terminal running for further testing. Now open a new terminal to the Kafka consumer process on the next step.

Step 7 – Using Kafka Consumer

Kafka also has a command-line consumer to read data from the Kafka cluster and display messages to standard output.

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testTopic --from-beginning 

Welcome to kafka
This is my first topic

Now, If you have still running Kafka producer (Step #6) in another terminal. Just type some text on that producer terminal. it will immediately visible on consumer terminal. See the below screenshot of Kafka producer and consumer in working:

Conclusion

You have successfully installed and configured the Kafka service on your Ubuntu Linux machine.

The post How to Install Apache Kafka on Ubuntu 18.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/install-apache-kafka-ubuntu/feed/ 24