kafka命令(整理)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fengzheku/article/details/52873067
1、启动Kafka:
      bin/kafka-server-start.sh config/server.properties

2、创建topic:
      bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 24 --topic topic_test 

3、发送消息:
      bin/kafka-console-producer.sh --broker-list localhost:9092 --topic page_visits

4、消费消息:
       bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic page_visits --from-beginning(这个会从头开始消费)
        bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic page_visits (消费从未消费过的消息)

5、删除topic:
       bin/kafka-topics.sh --zookeeper zk_host:port --delete --topic my_topic_name

6、查看topic:
      ./kafka-topics.sh --zookeeper  zk_host:port --list

7、增加kafka分区:
       ./kafka-topics.sh --zookeeper    zk_host:port --alter  --topic us_forward  --partitions 24

8、查看topic的分区:
      ./kafka-topics.sh --zookeeper  zk_host:port --describe --topic us_general

9、查看各个消费组的偏移量:
      ./kafka-run-class.sh  kafka.tools.ConsumerOffsetChecker --zookeeper  zk_host:port -group test_groupid

10、重新平衡分区和领导者:
        ./kafka-preferred-replica-election.sh --zookeeper  zk_host:port

11、描述kafka的topic
       ./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic test-topic 

11、扩展集群:
        

1)、先把要转移的topic写成json格式topics-to-move.json

{"topics": [

{"topic": "SYNC_DATABASE_UPDATE"},

{"topic": "SYNC_REALTIME_ALARM"},

{"topic": "SYNC_STATION_INFO"},

{"topic": "SYNC_VEHICLE_REG"},

{"topic": "ds_ctrlreq"},

{"topic": "us_ctrlrsp"},

{"topic": "us_forward"},

{"topic": "us_general"},

{"topic": "us_packet"}

],

 "version":1

}

2)、用脚本生成一个自动分区的计划

./kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --generate --topics-to-move-json-file topics-to-move.json  --broker-list 1,2,3 

3)、把生成的建议分区保存成json  topics-to-move-execute.json

4)、执行分区计划

/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --execute

5)、检查集群扩展是否完成

/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --verify

12、增加副本数

1)、编写扩展文件,可以利用扩展集群的方式导出现在的分布然后做修改

{ "version":1,

"partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]

}

2)、执行分区计划

/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --execute

3)、检查集群扩展是否完成

/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --verify 

猜你喜欢

转载自blog.csdn.net/fengzheku/article/details/52873067
今日推荐