Kafka运维

一、启动Server

(1)启动Zookeeper

bin/zookeeper-server-start.sh config/zookeeper.properties

 (2)启动Kafka

bin/kafka-server.start.sh config/server.properties

 二、关于Topic

(1)创建Topic,名为test(partition:分片;replica:副本)

bin/kafka-topic.sh --create --zookeeper XXX:2181,YYY:2182 --replication-factor 1 --partitions 1 --topic test

 (2)查看Topic列表

bin/kafka-topics.sh --list --zookeeper XXX:2181,YYY:2182

 (3)查看指定Topic的Partition

bin/kafka-topics.sh --describe --zookeeper XXX:2181,YYY:2182 --topic test

 输出如下:

Topic:testTopic1        PartitionCount:2       ReplicationFactor:2           configs:
Topic:testTopic1        Partition:0             Leader:1     Replicas:1,2       Isr:1,2
Topic:testTopic2        Partition:1             Leader:2     Replicas:2,3       Isr:2,3

 表示:分区0的Leader是1;分区1的Leader是2

(4)修改指定Topic的Partition数量

bin/kafka-topics.sh --zookeeper XXX:2181,YYY:2182 -alter --topic test --alter --partition 10

 (5)删除指定Topic

bin/kafka-topics.sh --delete --zookeeper  XXX:2181,YYY:2182 --topic hello

(6)在Kafka上对一个topic增加partition(分区新增到20)

./kafka-topics.sh -zookeeper XXX:2181,YYY:2182  -alter -partitions 20 -topic blog

(7)发送消息-接收消息模拟

A.发送消息
./kafka-console-producer.sh --broker-list XXX:9002,YYY:9003 --topic test
B.接收消息
./kafka-console-consumer.sh --zookeeper XXX:2181 --topic test --from-beginning

 其它命令操作请参见:http://blog.csdn.net/itleochen/article/details/18407063

posted @ 2016-12-01 21:43  moonandstar08  阅读(870)  评论(0编辑  收藏  举报