• Home
  • Docker
  • Kubernetes
  • LLMs
  • Java
  • Ubuntu
  • Maven
  • Big Data
  • Archived
Big Data | Install and configure Apache Kafka (3.4.0)
  1. Prerequisites
  2. Install Kafka
  3. How to configure Kafka?
  4. How to start/stop Kafka?
  5. How to install and configure a Kafka cluster on the same host?
  6. Common Kafka startup errors
  7. Cleanup Kafka
  8. How to create topics?
  9. How to monitor topics?
  10. How to delete topics?
  11. How to send (produce) a message to Kafka?
  12. How to send a very large file to Kafka?
  13. How to receive (consume) a message from kafka?
  14. How to monitor consumer groups?
  15. How to get an entity configuration?
  16. How to add/delete an entity configuration?
  17. Kafka Tool

  1. Prerequisites
    Zookeeper is a prerequisite and should be up and running before starting Kafka.
    See this page for more details on how to install Zookeeper: Apache ZooKeeper
  2. Install Kafka
    Download Apache Kafka: https://kafka.apache.org/downloads

    Extract the file "kafka_2.13-3.4.0.tgz" in the folder you want to install Kafka: /opt/kafka_2.13-3.4.0

    Note: In the following sections, the environment variable ${KAFKA_HOME} will refer to this location "/opt/kafka_2.13-3.4.0"

  3. How to configure Kafka?
    Create the folder "kafka-logs": "${KAFKA_HOME}/kafka-logs"
    Create the log folder "logs": "${KAFKA_HOME}/logs"


    Configure the kafka server properties file server.properties, by adjusting the following properties:

    Notes:
    • Leave listener hostname empty to bind to default interface:
    • Specify listener hostname as 0.0.0.0 to bind to all interfaces:
    • Specify multiple listeners:
  4. How to start/stop Kafka?
    • Start Kafka server:
      • Validate that Kafka is up/running and listening on port "9092":

      • Validate that Kafka was registered properly to ZooKeeeper:
    • Stop Kafka server:
  5. How to install and configure a Kafka cluster on the same host?
    The following examples show how to configure a cluster of Kafka instances on the same host.

    Extract the file "kafka_2.13-3.4.0.tgz" in the folders you want to install Kafka:


    Create the folders "kafka-logs" and "logs" for each instance:



    Configure the kafka server properties file server.properties, by adjusting the following properties for each instance (the broker.id, listeners, log.dirs are specific to each instance):



    Start Kafka servers:
    Stop Kafka servers:
  6. Common Kafka startup errors
    The following error indicates that the configured broker.id is already in use, or Kafka server was shutdown and restarted but ZooKeeper didn't timeout yet so it appears that Kafka is re-registering.
    The following error indicates that a process is already running using the same port:
  7. Cleanup Kafka


  8. How to create topics?
    Create a topic with one partition:
    Describe topic1:
    Create a topic with two partitions:
    Describe topic2:
    Add new partitions to a topic (if partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected):
    Describe topic2:
  9. How to monitor topics?
    List topics:
    Describe a topic (name, partitions count, replication factor, partitions list/configurations):
  10. How to delete topics?
  11. How to send (produce) a message to Kafka?
    Using the console to produce a message to Kafka:
    The output when your read the messages with a consumer should looks as following:
    Using a file to produce a message to Kafka (each line in the file is sent as a seprate message):
    The output when your read the messages with a consumer should looks as following (the order of messages might be different):
    Using a file with "key:value" lines (one entry per line) to produce a message to Kafka (each line in the file is sent as a separate message):
    The output when your read the messages with a consumer should looks as following (the order of messages might be different):
    Using "key:value" command line to produce a message to Kafka:
    The output when your read the messages with a consumer should looks as following (the order of messages might be different):
  12. How to send a very large file to Kafka?
    You need to configure the property max.request.size of the file ${KAFKA_HOME}/config/producer.properties
    You need to configure the property message.max.bytes of the file ${KAFKA_HOME}/config/zookeeper.properties
  13. How to receive (consume) a message from kafka?
    Consume new messages from a specific topic using a custom "consumer.properties" file:

    Consume all messages from a specific topic using the option "from-beginning":

    Consume messages from a specific topic using custom properties:

    A list of various command lines to consume messages from a specific topic using partitions properties:
  14. How to monitor consumer groups?
    List all consumers groups (this will only show information about consumers that use ZooKeeper, not those using the Java Consumer API):
    Describe a consumer group (this will only show information about consumers that use ZooKeeper, not those using the Java Consumer API):
  15. How to get an entity configuration?
    Get a topic configuration:
    Get a broker configuration:
  16. How to add/update/delete an entity configuration?
    Add/update new/existing configuration of a specific topic:
    Get the topic configuration:
    Delete a configuration from a specific topic:
  17. Kafka Tool
    Download Kafka Tool: http://www.kafkatool.com/download.html

    Copy Kafka Tool in the folder you want to install it: /opt/kafkatool

    Run Kafka Tool:
    Broker (Properties):
    Topic (Properties):
    Topic (Data):
    Topic (Partitions):
    Consumers (Partitions):
    Consumers (Offsets):
© 2025  mtitek