Updated on 2023-05-29 GMT+08:00

Using Kafka from Scratch

Scenario

You can create, query, and delete topics on a cluster client. For details, see Managing Kafka User Permissions.

Prerequisites

The client has been installed in a directory, for example, /opt/client. The client directory in the following operations is only an example. Change it based on site requirements.

Using the Kafka Client

  1. Install the client. For details, see Installing a Client.
  2. Access the ZooKeeper instance page.

    Log in to FusionInsight Manager. For details, see Accessing FusionInsight Manager. Choose Cluster > Services > ZooKeeper > Instance.

  3. View the IP addresses of the ZooKeeper role instance.

    Record any IP address of the ZooKeeper instance.

  4. Log in to the node where the client is installed.
  5. Run the following command to switch to the client installation directory, for example, /opt/client/Kafka/kafka/bin.

    cd /opt/client/Kafka/kafka/bin

  6. Run the following command to configure environment variables:

    source /opt/client/bigdata_env

  7. If Kerberos authentication is enabled for the current cluster, run the following command to authenticate the current user. If Kerberos authentication is disabled for the current cluster, skip this step.

    kinit Kafka user

  8. Log in to FusionInsight Manager, choose Cluster > Services > ZooKeeper, and click the Configurations tab and then All Configurations. On the displayed page, search for the clientPort parameter and record its value.
  9. Create a topic.

    sh kafka-topics.sh --create --topic Topic name --partitions Number of partitions occupied by the topic --replication-factor Number of replicas of the topic --zookeeper IP address of the node where the ZooKeeper instance resides:clientPort/kafka

    Example: sh kafka-topics.sh --create --topic TopicTest --partitions 3 --replication-factor 3 --zookeeper 10.10.10.100:2181/kafka

    You can search for clientPort in all ZooKeeper configuration parameters to obtain the value of clientPort. The default ports are as follows:
    • The default open-source port number is 2181.
    • The default customized port number is 24002.

    Port customization/open source: When creating an LTS version cluster, you can set Component Port to Open source or Custom. If Open source is selected, the open source port is used. If Custom is selected, the customized port is used.

  10. Run the following command to view the topic information in the cluster:

    sh kafka-topics.sh --list --zookeeper IP address of the node where the ZooKeeper instance resides:clientPort/kafka

    Example: sh kafka-topics.sh --list --zookeeper 10.10.10.100:2181/kafka

  11. Delete the topic created in 9.

    sh kafka-topics.sh --delete --topic Topic name --zookeeper IP address of the node where the ZooKeeper instance resides:clientPort/kafka

    Example: sh kafka-topics.sh --delete --topic TopicTest --zookeeper 10.10.10.100:2181/kafka