创建topic
/opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic zx037
查看topic详细情况
/opt/kafka/bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic ots_to_shenzheng
#返回结果
Topic:ots_to_shenzheng PartitionCount:1 ReplicationFactor:3 Configs:
Topic: ots_to_shenzheng Partition: 0 Leader: 2 Replicas: 2,1,0 Isr: 2,1,0
#isr 代表当前topic 可用isr
#Replicas 代表当前topic 当前Partition 对于Replicas 存在节点
#Leader 代表当前topic 当前Partition 对于leader 所在节点
list 当前集群topic
/opt/kafka/bin/kafka-topics.sh --zookeeper localhost:2181 --list
查看topic是否有其他设置,如单独设置过期时间
bin/kafka-configs.sh --zookeeper localhost:2181 --describe --entity-type topics
导出topic信息
/opt/kafka/bin/kafka-reassign-partitions.sh --zookeeper kafka-01:2181,kafka-02:2181,kafka-03:2181 --topics-to-move-json-file addReplicas.json --broker-list “0,1,2” --generate
#将导出信息重定向到 kanman_barrage-Replicas.json文件
#格式如下:
{“version”:1,“partitions”:[{“topic”:“yinzhengjie-channel”,“partition”:0,“replicas”:[1,0,2]},{“topic”:“yinzhengjie-channel”,“partition”:1,“replicas”:[1,0,3]},{“topic”:“yinzhengjie-channel”,“partition”:2,“replicas”:[1,0,1]}]}
执行更改replicas
/opt/kafka/bin/kafka-reassign-partitions.sh --zookeeper kafka-01:2181,kafka-02:2181,kafka-03:2181 --reassignment-json-file kanman_barrage-Replicas.json --execute
查看分配进度
kafka-reassign-partitions.sh --zookeeper kafka-01:2181,kafka-02:2181,kafka-03:2181 --reassignment-json-file kanman_barrage-Replicas.json --verify
增加partitions
kafka-topics.sh –alter –zookeeper kafka-01:2181 –topic zx037 –partitions 2
/opt/kafka/bin/kafka-topics.sh --zookeeper kafka-binlog-2:2181 --describe --topic zx037
增加partitions
/opt/kafka/bin/kafka-topics.sh –alter –zookeeper kafka-01:2181 –topic zx037 –partitions 2
kafka数据保存时间动态调整
#修改数据保存时间 48小时
/opt/kafka/bin/kafka-topics.sh --zookeeper kafka-binlog-1:2181,kafka-binlog-0:2181,kafka-binlog-2:2181 --topic zx037 --alter --config retention.ms=172800000
#delete retention.ms配置
/opt/kafka/bin/kafka-topics.sh --zookeeper kafka-binlog-1:2181,kafka-binlog-0:2181,kafka-binlog-2:2181 --topic zx037 --alter --delete-config retention.ms