Using a Kafka Client
Scenario
You can create, query, and delete topics on a cluster client.
Prerequisites
The client has been installed. For example, the client is installed in the /opt/hadoopclient directory. The client directory in the following operations is only an example. Change it to the actual installation directory.
Using the Kafka Client (Versions Earlier Than MRS 3.x)
- View the IP addresses of the ZooKeeper role instance.
Record any IP address of the ZooKeeper instance.
- Log in to the node where the client is installed.
- Run the following command to switch to the client directory, for example, /opt/hadoopclient/Kafka/kafka/bin.
cd /opt/hadoopclient/Kafka/kafka/bin
- Run the following command to configure environment variables:
source /opt/hadoopclient/bigdata_env
- If Kerberos authentication is enabled for the current cluster, run the following command to authenticate the user. If Kerberos authentication is disabled, skip this step.
kinit Kafka user
- 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
- 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
- Delete the topic created in 6.
sh kafka-topics.sh --delete --topic Topic name --zookeeper IP address of the node where the ZooKeeper instance resides:clientPort/kafka
Type y and press Enter.
Using the Kafka Client (MRS 3.x or Later)
- View the IP addresses of the ZooKeeper role instance.
Record any IP address of the ZooKeeper instance.
- Log in to the node where the client is installed.
- Run the following command to switch to the client directory, for example, /opt/hadoopclient/Kafka/kafka/bin.
cd /opt/hadoopclient/Kafka/kafka/bin
- Run the following command to configure environment variables:
source /opt/hadoopclient/bigdata_env
- If Kerberos authentication is enabled for the current cluster, run the following command to authenticate the user. If Kerberos authentication is disabled, skip this step.
kinit Kafka user
- 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
- 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
- Delete the topic created in 6.
sh kafka-topics.sh --delete --topic Topic name --zookeeper IP address of the node where the ZooKeeper instance resides:clientPort/kafka
Type y and press Enter.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot