Kafka之常用主题操作

x33g5p2x  于2020-09-08 发布在 Kafka  
字(1.8k)|赞(0)|评价(0)|浏览(850)

Kafka常用主题操作包括 create、list、descript、alter、delete

1、create创建主题

使用方法:./kafka-topics.sh --create --zookeeper <host>:<port>[,<host>:<port>,...] --topic <topic-name> 
命令用途:链接zookeeper创建指定的主题

示例:
    ./kafka-topics.sh --create --zookeeper hdp01:2181 --if-not-exists --partitions 5 --replication-factor 1 --topic liumm-topic --config min.insync.replicas=1
描述:
    创建一个不存在的指定分区为5,副本数为1,名称为liumm-topic,最小ISR为1的主题

2、list查看主题

使用方法:./kafka-topics.sh --list --zookeeper <host>:<port>[,<host>:<port>,...]
命令用途:链接zookeeper查看主题

示例:
    ./kafka-topics.sh --list --zookeeper hdp01:2181
描述:
    列出当前所有主题
示例:
    ./kafka-topics.sh --list --zookeeper hdp01:2181 --topic liumm-topic
描述:
    列出指定主题的信息,用于查看某个主题是否存在

3、describe查看主题详情

使用命令:./kafka-topics.sh --describe --zookeeper <host>:<port>[,<host>:<port>,...]
命令用途:链接zookeeper查看主题消息
示例:
    ./kafka-topics.sh --describe --zookeeper hdp01:2181
描述:
    查看所有主题详情
    
示例:
    ./kafka-topics.sh --describe --zookeeper hdp01:2181 --topic liumm-topic
描述:
    查看指定主题详情

4、alter修改主题信息

使用命令:./kafka-topics.sh --alter --zookeeper <host>:<port>[,<host>:<port>,...] --topic <topic-name> 
命令用途:修改主题信息,这个脚本将会被过时,未来将被删除。新版本s使用./kafka-configs.sh进行修改
示例:
    ./kafka-topics.sh --alter --zookeeper hdp01:2181 --topic liumm-topic --partitions 6
描述:
    修改主题分区数目,只能增多,不能减少
    
示例:
    ./kafka-topics.sh --alter --zookeeper hdp01:2181 --topic liumm-topic --config flush.messages=1000
描述:
    新增主题配置
    
示例:
    ./kafka-topics.sh --alter --zookeeper hdp01:2181 --topic liumm-topic --delete-config flush.messages
描述:
    删除指定主题配置

5、delete删除主题配置

使用命令:./kafka-topics.sh --describe --zookeeper <host>:<port>[,<host>:<port>,...] --delete --topic <topic-name> 
命令用途:链接zookeeper删除主题
示例:
    ./kafka-topics.sh --zookeeper hdp01:2181 --delete --topic liumm-topic
描述:
    删除的主题只能被标记,不是立马删除,需要等下一次压缩才能真正删除,但是需要配置delete.topic.enable=true,压缩时才会删除,否则不起作用

相关文章

微信公众号

最新文章

更多