jxp2002 发表于 2017-5-23 15:18:11

kafka topic命令

 
 kafka topic可以定制执行brokerid和partition的topic,还有增加partition
kafka topic
Create, delete, describe, or change a topic.
Option                                  Description                            
------                                  -----------                            
--alter                                 Alter the configuration for the topic. 
--config <name=value>                   A topic configuration override for the 
                                          topic being created or altered.The   
                                          following is a list of valid         
                                          configurations:                      
                                                unclean.leader.election.enable        
                                                delete.retention.ms                   
                                                segment.jitter.ms                     
                                                retention.ms                          
                                                flush.ms                              
                                                segment.bytes                         
                                                flush.messages                        
                                                segment.ms                            
                                                retention.bytes                       
                                                cleanup.policy                        
                                                segment.index.bytes                   
                                                min.cleanable.dirty.ratio             
                                                max.message.bytes                     
                                                file.delete.delay.ms                  
                                                min.insync.replicas                   
                                                index.interval.bytes                  
                                        See the Kafka documentation for full   
                                          details on the topic configs.        
--create                                Create a new topic.                    
--delete                                Delete a topic                         
--delete-config <name>                  A topic configuration override to be   
                                          removed for an existing topic (see   
                                          the list of configurations under the 
                                          --config option).                    
--describe                              List details for the given topics.     
--help                                  Print usage information.               
--list                                  List all available topics.             
--partitions <Integer: # of partitions> The number of partitions for the topic 
                                          being created or altered (WARNING:   
                                          If partitions are increased for a    
                                          topic that has a key, the partition  
                                          logic or ordering of the messages    
                                          will be affected                     
--replica-assignment                    A list of manual partition-to-broker   
  <broker_id_for_part1_replica1 :         assignments for the topic being      
  broker_id_for_part1_replica2 ,          created or altered.                  
  broker_id_for_part2_replica1 :                                               
  broker_id_for_part2_replica2 , ...>                                          
--replication-factor <Integer:          The replication factor for each        
  replication factor>                     partition in the topic being created.
--topic <topic>                         The topic to be create, alter or       
                                          describe. Can also accept a regular  
                                          expression except for --create option
--topics-with-overrides                 if set when describing topics, only    
                                          show topics that have overridden     
                                          configs                              
--unavailable-partitions                if set when describing topics, only    
                                          show partitions whose leader is not  
                                          available                            
--under-replicated-partitions           if set when describing topics, only    
                                          show under replicated partitions     
--zookeeper <urls>                      REQUIRED: The connection string for    
                                          the zookeeper connection in the form 
                                          host:port. Multiple URLS can be      
                                          given to allow fail-over.  
 
 
topic describe命令:
topic所有的partition
 bin/kafka-topics.sh --describe --topic dirkzhang --zookeeper host34/kafka-dirktest
在复制的partition
 bin/kafka-topics.sh --describe --topic dirkzhang --zookeeper host34/kafka-dirktest --under-replicated-partitions    
没有leader的partition
 bin/kafka-topics.sh --describe --topic dirkzhang --zookeeper host34/kafka-dirktest --unavailable-partitions
 打印新配置
  bin/kafka-topics.sh --describe --topic dirkzhang --zookeeper host34/kafka-dirktest --topics-with-overrides
 
 
topic create 命令
bin/kafka-topics.sh --create --topic testcreate2 --zookeeper host34/kafka-dirktest --partitions 3 --replication-factor 2
数据定位具体的brokerid
在用replica-assignment的时候,不允许用partitions和replication-factor
并且replica不能重复
bin/kafka-topics.sh --create --topic testcreate --zookeeper host34/kafka-dirktest  --replica-assignment 0341:0361,0341:0371,0341:0361
 
topic add命令
增加partition,partitions必须是增多的
bin/kafka-topics.sh --alter --topic testcreate --zookeeper host34/kafka-dirktest --partitions 4 
以下命令不管用 bug:
bin/kafka-topics.sh --alter --topic testcreate --zookeeper host34/kafka-dirktest --partitions 4  --replica-assignment 0341:0361
 
修改topic的delete时间为6小时
  bin/kafka-topics.sh --alter --zookeeper host211/kafka-real --topic report_rtb_request --config delete.retention.ms=21600000
 
 
页: [1]
查看完整版本: kafka topic命令