Obtaining Topic Distribution Information
Issue
How do I obtain topic distribution information in a Broker instance?
Preparations
- Prerequisites
The Kafka and ZooKeeper clients have been installed.
- 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:
source bigdata_env
- Run the following command to perform user authentication (skip this step for a cluster in common mode):
kinit Component service user
- Run the following command to switch to the Kafka client installation directory:
cd Kafka/kafka/bin
- 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/kafkaTopic:topic1 PartitionCount:2 ReplicationFactor:2 Configs:Topic: topic1 Partition: 0 Leader: 26 Replicas: 23,25 Isr: 26Topic: topic1 Partition: 1 Leader: 24 Replicas: 24,23 Isr: 24,23In 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.
sh zkCli.sh -server <zk_host:port>
- Run the following command on the ZooKeeper client:
ls /kafka/brokers/ids
get/kafka/brokers/ids/<queried Broker ID>
Example:
[root@node-master1gAMQ kafka]# zkCli.sh -server node-master1gAMQ:2181Connecting to node-master1gAMQ:2181Welcome to ZooKeeper!JLine support is enabledWATCHER::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/kafkaBroker_ID IP_Address--------------------------1 192.168.2.242
Parent topic: Using Kafka
- Preparations
- Solution 1
- Solution 2