当前位置: 移动技术网 > IT编程>数据库>其他数据库 > Kafka运维命令大全

Kafka运维命令大全

2019年09月16日  | 移动技术网IT编程  | 我要评论
1、集群管理 前台启动broker Ctrl + C 关闭 后台启动broker 关闭broker 2、Topic管理 创建topic 删除topic 查询topic列表 查询topic详情 修改topic 3、Consumer Groups管理 查询消费者组 查询消费者组详情 重设消费者组位移 删 ...

1、集群管理

前台启动broker

bin/kafka-server-start.sh <path>/server.properties

ctrl + c 关闭

后台启动broker

bin/kafka-server-start.sh -daemon <path>/server.properties

关闭broker

bin/kafka-server-stop.sh

2、topic管理

创建topic

bin/kafka-topics.sh --create --zookeeper localhost:2181 --partitions 3 --replication-factor 3 --topic topicname 

删除topic

bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic topicname 

查询topic列表

bin/kafka-topics.sh --zookeeper localhost:2181 --list

查询topic详情

bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic topicname 

修改topic

bin/kafka-topics.sh --alter --zookeeper localhost:2181 --partitions 6 --topic topicname 

3、consumer-groups管理

查询消费者组

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list 

查询消费者组详情

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group groupname 

重设消费者组位移

最早处
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-earliest --execute
最新处
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-latest --execute
某个位置
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-offset 2000 --execute
调整到某个时间之后得最早位移
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-datetime 2019-09-15t00:00:00.000

删除消费者组

bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --delete --group groupname

4、脚本工具

producer脚本

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic topicname 
参数含义:
--compression-codec lz4  压缩类型
--request-required-acks all acks的值
--timeout 3000  linger.ms的值
--message-send-max-retries 10   retries的值
--max-partition-memory-bytes batch.size值

consumer脚本

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicname --from-beginning
指定groupid
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicname --from-beginning
--consumer-property group.id=old-consumer-group
指定分区
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicname --from-beginning
--partition 0

kafka-run-class脚本

kafka-run-class.sh kafka.tools.consoleconsumer   就是 kafka-console-consumer.sh
kafka-run-class.sh kafka.tools.consoleproducer   就是 kafka-console-producer.sh

获取topic当前消息数

kafka-run-class.sh kafka.tools.getoffsetshell --broker-list localhost:9092 --topic topicname --time -1

--time -1表示最大位移 --time -2表示最早位移

查询_consumer_offsets

bin/kafka-simple-consumer-shell.sh --topic _consumer_offsets --partition 12 --broker-list localhost:9092 --formatter "kafka.coorfinator.groupmetadatamanager\$offsetsmessageformatter"

5、mirrormaker

跨机房灾备工具

bin/kafka-mirror-maker.sh --consumer.config consumer.properties --producer.config producer.properties --whitelist topica|topicb

更多实时计算,flink,kafka等相关技术博文,欢迎关注实时流式计算

file

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网