查看“Kafka:命令大全”的源代码
←
Kafka:命令大全
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
[[category:Kafka]] == 关于 == kafka相关的常用命令 == 管理 == <syntaxhighlight lang="bash" highlight=""> ## 创建topic(4个分区,2个副本) # kafka版本 < 2.2 bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 4 --topic test # kafka版本 >= 2.2 bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test ## 分区扩容 # kafka版本 < 2.2 bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic topic1 --partitions 2 # kafka版本 >= 2.2 bin/kafka-topics.sh --bootstrap-server broker_host:port --alter --topic topic1 --partitions 2 ## 删除topic bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic test </syntaxhighlight> == 查询 == <syntaxhighlight lang="bash" highlight=""> ## 查询集群描述 bin/kafka-topics.sh --describe --zookeeper 127.0.0.1:2181 ## topic列表查询 bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list ## topic列表查询(支持0.9版本+) bin/kafka-topics.sh --list --bootstrap-server localhost:9092 ## 新消费者列表查询(支持0.9版本+) bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --list ## 新消费者列表查询(支持0.10版本+) bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list ## 显示某个消费组的消费详情(0.9版本 - 0.10.1.0 之前) bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --describe --group test-consumer-group ## 显示某个消费组的消费详情(0.10.1.0版本+) bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group ## 显示某个消费组的消费详情(仅支持offset存储在zookeeper上的) bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper localhost:2181 --group test </syntaxhighlight> == 发送和消费 == <syntaxhighlight lang="bash" highlight=""> ## 生产者 bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test ## 消费者 bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test ## 新生产者(支持0.9版本+) bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test --producer.config config/producer.properties ## 新消费者(支持0.9版本+) bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --new-consumer --from-beginning --consumer.config config/consumer.properties ## kafka-verifiable-consumer.sh(消费者事件,例如:offset提交等)【???】 bin/kafka-verifiable-consumer.sh --broker-list localhost:9092 --topic test --group-id groupName ## 高级点的用法【???】 bin/kafka-simple-consumer-shell.sh --brist localhost:9092 --topic test --partition 0 --offset 1234 --max-messages 10 </syntaxhighlight> == 切换leader == <syntaxhighlight lang="bash" highlight=""> # kafka版本 <= 2.4 > bin/kafka-preferred-replica-election.sh --zookeeper zk_host:port/chroot # kafka新版本 > bin/kafka-preferred-replica-election.sh --bootstrap-server broker_host:port </syntaxhighlight> == kafka自带压测命令【???】 == <syntaxhighlight lang="bash" highlight=""> bin/kafka-producer-perf-test.sh --topic test --num-records 100 --record-size 1 --throughput 100 --producer-props bootstrap.servers=localhost:9092 </syntaxhighlight> == kafka持续发送消息【???】 == 持续发送消息到指定的topic中,且每条发送的消息都会有响应信息: <syntaxhighlight lang="bash" highlight=""> kafka-verifiable-producer.sh --broker-list $(hostname -i):9092 --topic test --max-messages 100000 </syntaxhighlight> == zookeeper-shell.sh【Zookeeper 命令】 == 如果kafka集群的zk配置了chroot路径,那么需要加上 /path: <syntaxhighlight lang="bash" highlight=""> bin/zookeeper-shell.sh localhost:2181[/path] ls /brokers/ids get /brokers/ids/0 </syntaxhighlight> == 迁移分区 == # 创建规则json: #: <syntaxhighlight lang="bash" highlight=""> cat > increase-replication-factor.json <<EOF {"version":1, "partitions":[ {"topic":"__consumer_offsets","partition":0,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":1,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":2,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":3,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":4,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":5,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":6,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":7,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":8,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":9,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":10,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":11,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":12,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":13,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":14,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":15,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":16,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":17,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":18,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":19,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":20,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":21,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":22,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":23,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":24,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":25,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":26,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":27,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":28,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":29,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":30,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":31,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":32,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":33,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":34,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":35,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":36,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":37,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":38,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":39,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":40,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":41,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":42,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":43,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":44,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":45,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":46,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":47,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":48,"replicas":[0,1]}, {"topic":"__consumer_offsets","partition":49,"replicas":[0,1]}] } EOF </syntaxhighlight> # 执行: #: <syntaxhighlight lang="bash" highlight=""> bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --execute </syntaxhighlight> # 验证: #: <syntaxhighlight lang="bash" highlight=""> bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --verify </syntaxhighlight>
返回至“
Kafka:命令大全
”。
导航菜单
个人工具
登录
命名空间
页面
讨论
大陆简体
已展开
已折叠
查看
阅读
查看源代码
查看历史
更多
已展开
已折叠
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
笔记
服务器
数据库
后端
前端
工具
《To do list》
日常
阅读
电影
摄影
其他
Software
Windows
WIKIOE
所有分类
所有页面
侧边栏
站点日志
工具
链入页面
相关更改
特殊页面
页面信息