常用命令
创建topic
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic my-replicated-topic
查看topic
./bin/kafka-topics.sh --list --zookeeper localhost:2181
查看topic的详细信息
./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic
为topic增加副本
./bin/kafka-reassign-partitions.sh -zookeeper localhost:2181 -reassignment-json-file json/partitions-to-move.json -execute
为topic增加partition
./bin/kafka-topics.sh –zookeeper localhost:2181 –alter –partitions 20 –topic my-replicated-topic
kafka生产者客户端命令
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-replicated-topic
kafka消费者客户端命令
./bin/kafka-console-consumer.sh -zookeeper localhost:2181 --from-beginning --topic my-replicated-topic
kafka服务启动
./bin/zookeeper-server-start.sh -daemon config/zookeeper.properties ./bin/kafka-server-start.sh -daemon ./config/server.properties
下线broker
./bin/kafka-run-class.sh kafka.admin.ShutdownBroker --zookeeper localhost:2181 --broker #brokerId# --num.retries 3 --retry.interval.ms 60 shutdown broker
删除topic
./bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --topic my-replicated-topic --zookeeper localhost:2181
./bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic my-replicated-topic
查看consumer组内消费的offset
./bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper localhost:2181 --group test --topic my-replicated-topic
./bin/kafka-consumer-offset-checker.sh --zookeeper localhost:2181 --group group1 --topic my-replicated-topic
性能测试
./bin/kafka-producer-perf-test.sh --topic batchTopic --throughput 100000 --num-records 100000 --producer-props bootstrap.servers=localhost:9092 acks=all --record-size 1000
./bin/kafka-consumer-perf-test.sh --messages 100000 --topic batchTopic --broker-list localhost:9092 --message-size 10
Comments