一、单机版kafka启动命令:
1.启动zookeeper:
./zookeeper-server-start.sh config/zookeeper.properties &
2.启动kafka:
./kafka-server-start.sh config/server.producer &
3.创建topic(一个分区,一个副本):
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
4.为topic增加partition:
./bin/kafka-topics.sh –zookeeper localhost:2181 –alter –partitions 5 –topic test
5.为topic增加:
./kafka-reassign-partitions.sh -zookeeper localhost:2181 -reassignment-json-file json/partitions-to-move.json -execute
6.查看所有topic:
./kafka-topics.sh --list --zookeeper localhost:2181
7.查看topic的详细信息:
./kafka-topics.sh -zookeeper localhost:2181 -describe -topic test
8.运行producer:
./kafka-console-producer.sh --broker-list localhost:9092--topic test
9.运行consumer(从头消费):
./kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic test
10.下线broker:
./kafka-run-class.sh kafka.admin.ShutdownBroker --zookeeper localhost:2181 --broker #brokerId# --num.retries 3 --retry.interval.ms 60
shutdown broker
11.查看consumer组内消费的offset:
./kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper localhost:2181 --group test --topic test
12.删除topic:
./kafka-topics.sh --delete --zookeeperlocalhost:2181 --topic test
注意:kafka启动时加载的配置文件中server.properties没有配置delete.topic.enable=true,那么此时的删除不是真正的删除,只是标记为marked for deletion
若想完全删除还需执行下面的操作:
(1.)找到zookeeper相关路径,打开zookeeper client;如:/home/zookeeper/bin/zkCli.sh
(2.)找到topic所在目录:ls /brokers/topics
(3.)找到要删除的topic,执行命令:rmr /brokers/topics/[topic name]
(4.)被标记为marked for deletion的topic你可以在zookeeper客户端通过命令获得:ls /admin/delete_topics/[topic name];
如果你删除了此处的topic,那么marked for deletion标记就会消失。
(5.)重启zookeeper和kafka。