Obtaining Topic Distribution Information
Issue
How do I obtain topic distribution information in a Broker instance?
Preparations
- Prerequisites
- Procedure
- Log in to the node where the Kafka client is installed as the client installation user.
- Switch to the Kafka client installation directory, for example, /opt/client.
cd /opt/client
- Run the following command to configure environment variables:
- Run the following command to perform user authentication (skip this step for a cluster in common mode):
- Run the following command to switch to the Kafka client installation directory:
- Run the Kafka commands to obtain the topic assignment information and copy synchronization information, and check the return result.
kafka-topics.sh --describe --zookeeper <zk_host:port/chroot>
Example:
[root@mgtdat-sh-3-01-3 client]#kafka-topics.sh --describe --zookeeper 10.149.0.90:2181/kafka Topic:topic1 PartitionCount:2 ReplicationFactor:2 Configs: Topic: topic1 Partition: 0 Leader: 26 Replicas: 23,25 Isr: 26 Topic: topic1 Partition: 1 Leader: 24 Replicas: 24,23 Isr: 24,23
In the preceding information, Replicas indicates the replica assignment information and Isr indicates the replica synchronization information.
Solution 1
- Query the Broker ID mapping in ZooKeeper.
- Run the following command on the ZooKeeper client:
get/kafka/brokers/ids/<queried Broker ID>
Example:
[root@node-master1gAMQ kafka]# zkCli.sh -server node-master1gAMQ:2181 Connecting to node-master1gAMQ:2181 Welcome to ZooKeeper! JLine support is enabled WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: node-master1gAMQ:2181(CONNECTED) 0] ls /kafka/brokers/ ids seqid topics [zk: node-master1gAMQ:2181(CONNECTED) 0] ls /kafka/brokers/ids [1] [zk: node-master1gAMQ:2181(CONNECTED) 1] get /kafka/brokers/ids/1 {"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT","SSL":"SSL"},"endpoints":["PLAINTEXT://192.168.2.242:9092","SSL://192.168.2.242:9093"],"rack":"/default/rack0","jmx_port":21006,"host":"192.168.2.242","timestamp":"1580886124398","port":9092,"version":4} [zk: node-master1gAMQ:2181(CONNECTED) 2]
Solution 2
Obtain the mapping between nodes and Broker IDs.
kafka-broker-info.sh --zookeeper <zk_host:port/chroot>
Example:
[root@node-master1gAMQ kafka]# bin/kafka-broker-info.sh --zookeeper 192.168.2.70:2181/kafka Broker_ID IP_Address -------------------------- 1 192.168.2.242
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