Updated on 2024-10-09 GMT+08:00

Creating a Kafka Topic

Scenario

You can use the cluster client or KafkaUI to create Kafka topics based on service requirements. Management permission is required for clusters with Kerberos authentication enabled.

Prerequisites

You have installed the Kafka client.

Creating a Kafka Topic Using the Kafka Client

  1. Access the ZooKeeper instance page.

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

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

    Record any IP address of the ZooKeeper instance.

  3. Prepare the client based on service requirements. Log in to the node where the client is installed.For details, see Using an MRS Client.
  4. Run the following command to switch to the client installation directory, for example, /opt/client/Kafka/kafka/bin.

    cd /opt/client/Kafka/kafka/bin

  5. Run the following command to configure environment variables:

    source /opt/client/bigdata_env

  6. Run the following command to perform user authentication (skip this step in normal mode):

    kinit Component service user

  7. Use kafka-topics.sh to create Kafka topics.

    ./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 any ZooKeeper node:clientPort/kafka

    ./kafka-topics.sh --create --topic topic name --partitions number of partitions occupied by the topic--replication-factor number of replicas of the topic --bootstrap-server IP address of the Kafkacluster:21007 --command-config ../config/client.properties

Creating a Kafka Topic Using KafkaUI

  1. Access the Kafka UI.

    1. Log in to FusionInsight Manager as a user who has the permission to access the Kafka UI and choose Cluster > Services > Kafka.

      If you need to perform related operations on the page, for example, creating a topic, you need to grant related permissions to the user. For details, see Kafka User Permissions.

    2. On the right of KafkaManager WebUI, click the URL to access Kafka UI.

  2. Click Create Topic. On the page that is displayed, set parameters based on Table 1 and click Create.

    Table 1 Topic information

    Parameter

    Description

    Remarks

    Topic

    Topic name, which can contain a maximum of 249 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

    Example: kafka_ui

    Partitions

    Number of topic partitions. The value must be greater than or equal to 1. The default value is 3.

    -

    Replication Factor

    Replication factor of a topic. The value ranges from 1 to N. N indicates the number of brokers in the current cluster. The default value is 2.

    -

    • You can click Advanced Options to set advanced topic parameters based on service requirements. Generally, retain the default values.
    • In a cluster in security mode, the user who creates a topic must belong to the kafkaadmin user group. Otherwise, the topic cannot be created due to authentication failure.
    • In a cluster in non-security mode, no authentication is required for creating a topic. That is, any user can create a topic.