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、扩展集群: