kafka 修改partition,刪除topic,查詢offset


修改分區個數:

./kafka-topics.sh --zookeeper 127.0.0.1:2181/kafka/<id_of_kafka> --alter --partitions 10 --topic test_topic

上面命令將test_topic對應的分區數目調整為10個,127.0.0.1是zookeeper的地址,2181是zookeeper端口。

刪除topic

./kafka-topics.sh --zookeeper 127.0.0.1:2181/kafka/<id_of_kafka> --delete --topic test_topic

上面命令將主題test_topic標記為刪除,但是如果delete.topic.enable沒有配置為True,上述命令無效。

修改過期時間:

./kafka-topics.sh --zookeeper 127.0.0.1:2181/kafka/<id_of_kafka> --alter --partitions 10 --topic test_topic --config retention.ms=86400000 --config cleanup.policy=delete

 查詢topic offset

./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list <ip:port of kafka instead of zookeeper> --topic topic_to_select --time -1  # 偏移最大值
./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list <ip:port of kafka instead of zookeeper> --topic topic_to_select --time -2 # 偏移最小值

查詢topic詳細信息

./kafka-topics.sh --zookeeper 127.0.0.1:2181/kafka/<id_of_kafka> --describe --topic topic_to_select

 look up consumer group info, include messages lag. there is new_consumer and old_consumer param, default is new_consumer.

./kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --group test_group_id --describe

 check config, entity-type could be brokers, topics, users

./kafka-configs.sh --describe --zookeeper 127.0.0.1:2181/kafka/<id_of_kafka> --entity-type topics

set config

Topics have broker-wide configs that apply by default to any topic that doesn't have a config, but topics can also have topic-specific configs that override or complement broker-wide topic configs. Broker-wide topic configs are set in your service.properties file. Topic specific configs are set using the bin/kafka-topics.sh script.

To set retention.ms on a new topic:

bin/kafka-topics.sh --zookeeper zk_host:port/chroot --create --topic my_topic_name
  --partitions 20 --replication-factor 3 --config retention.ms=-1

modify config of an existing topic:

./kafka-configs.sh --alter --zookeeper 127.0.0.1:2181/kafka/<id_of_kafka> --add-config cleanup.policy=delete --entity-type topic --entity-name <topic_name> 

kafka啟動關閉

bin/zookeeper-server-start.sh -daemon config/zookeeper.properties  # zookeeper 守護進程啟動
bin/zookeeper-server-stop.sh  # 關閉zookeeper
export JMX_PORT=9999   # 設置端口以在kafka mananger顯示統計數據
bin/kafka-server-start.sh -daemon config/server.properties  # 以守護進程啟動kafka
bin/kafka-server-stop.sh  # 關閉kafka

zookeeper查看kafka節點狀態

./zookeeper-shell.sh 172.18.185.123:2181,172.18.185.124:2181  <<< "ls /brokers/ids"

 

 

ref: https://stackoverflow.com/questions/48504123/choosing-the-right-cleanup-policy-in-kafka-configuration

https://stackoverflow.com/questions/40146921/command-to-get-kafka-broker-list-from-zookeeper


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM