1.查看topic详细信息
./kafka-topics.sh -zookeeper ip:port -describe -topic topicname
kafka/bin/kafka-topics.sh -zookeeper hostname:2181 -describe -topic topicname
2.为topic增加副本
./kafka-reassign-partiotions.sh -zookeeper ip:port -reassignment-json-file
json/partitions-to-move.json -execute
kafka/bin/kafka-reassign-partitions.sh -zookeeper hostname:2181
-reassignment-json-file json/partitions-to-move.json -execute
3.创建topic
./kafka-topics.sh --create --zookeeper ip:port --replication-factor 1
--partitions 1 --topic topicname
kafka/bin/kafka-topics.sh --create --zookeeper hostname:2181
--replication-factor 1 --partitions 1 --topic topicname
4.为topic增加partition
./bin/kafka-topics.sh -zookeeper ip:port -alter -partitions 20 -topic topicname
kafka/bin/kafka-topics.sh --zookeeper hostname:2181 -alter -partitions 6
-topic topicname
5.Kafka生产者客户端命令
./kafka-console-producer.sh --broker-list ip:port --topic topicname
kafka/bin/kafka-console-producer.sh --broker-list
hostname1:9092,hostname2:9092 --topic topicname
6.Kafka消费者客户端命令
./kafka-console-consumer.sh -zookeeper ip:port --topic topicname
./kafka-console-consumer.sh -zookeeper ip:port --from-beginning --topic
topicname
kafka/bin/kafka-console-consumer.sh -zookeeper hostname:2181 --from-beginning
--topic topicname
7.Kafka服务启动
./kafka-server-start.sh -daemon ../config/server.properties
8.下线broker
./kafka-run-class.sh kafka.admin.ShutdownBroker --zookeeper ip:port --broker
#brokerId# --run.retries 3 --retry.interval.ms 60 shutdown broker
9.删除topic
./kafka-run-class.sh kafka.admin.DeleteTopicCommand --topic
topicname--zookeeper ip:port ./kafka-topics.sh --zookeeper ip:port --delete
--topic topicname
./kafka-topics.sh --delete --zookeeper ip:port --topic topicname
kafka/bin/kafka-topics.sh --delete --zookeeper hostname:2181 --topic topicname
10.查看consumer组内消费的offset
./kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper ip:port
--group test --topic topicname
11.查看消费
./kafka-topics.sh --zookeeper ip:port --describe --topic topicname
kafka/bin/kafka-topics.sh --zookeeper hostname:2181 --describe --topic
topicname
12.查找Kafka版本
find / -name \*kafka_\*|head -1|grep -o '\kafka[^\n]*'
热门工具 换一换