Kafka常用操作备忘

启动
nohup ./bin/zookeeper-server-start.sh config/zookeeper.properties &
nohup ./bin/kafka-server-start.sh config/server.properties &

创建topic
kafka-topics.sh --create --zookeeper localhost:2181/kafka --replication-factor 1 --partitions 1 --topic $TOPIC

topic状态
./kafka-topics.sh --describe --zookeeper localhost:2181 --topic test

topic列表
./kafka-topics.sh --list --zookeeper localhost:2181

限流(根据每秒字节数)
kafka-configs.sh --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=24576000,consumer_byte_rate=24576000' --entity-type clients --entity-default
./kafka-configs.sh --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024' --entity-type clients --entity-default
.kafka-configs.sh --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1536000'--entity-type clients --entity-default

消费状态
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group group_name

生产消费
kafka-console-producer.sh --broker-list localhost:9092 --topic test
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

动态增加副本:
./bin/kafka-reassign-partitions.sh --zookeeper localhost:2181/kafka --reassignment-json-file increase-replication-factor.json --execute
{"version":1,"partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]}

reassign检验:

kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --verify

jstack -l pid

jmap -dump:live,format=b,file=/opt/map.bin pid

jps|grep Kafka|awk '{print $1}'|xargs kill -9

posted @ 2018-10-26 14:10  _fred  阅读(446)  评论(0编辑  收藏  举报