本套系列博客从真实商业环境抽取案例进行总结和分享,并给出Spark商业应用实战指导,请持续关注本套博客。版权声明:本套Spark商业应用实战归做者(秦凯新)全部,禁止转载,欢迎学习。python
查看kafka topic列表,使用--list参数git
bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list
__consumer_offsets
lx_test_topic
test
复制代码
查看kafka特定topic的详情,使用--topic与--describe参数github
bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --topic lx_test_topic --describe
Topic:lx_test_topic PartitionCount:1 ReplicationFactor:1 Configs:
Topic: lx_test_topic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
复制代码
查看consumer group列表,使用--list参数算法
一样根据新/旧版本的consumershell
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server 127.0.0.1:9292 --list
lx_test
bin/kafka-consumer-groups.sh --zookeeper 127.0.0.1:2181 --list
console-consumer-86845
console-consumer-11967
复制代码
查看特定consumer group 详情,使用--group与--describe参数json
一样根据新/旧版本的consumer,分别指定bootstrap-server与zookeeper参数:bootstrap
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server 127.0.0.1:9292 --group lx_test --describe
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG OWNER
lx_test lx_test_topic 0 465 465 0 kafka-python-1.3.1_/127.0.0.1
bin/kafka-consumer-groups.sh --zookeeper 127.0.0.1:2181 --group console-consumer-11967 --describe
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG OWNER
Could not fetch offset from zookeeper for group console-consumer-11967 partition [lx_test_topic,0] due to missing offset data in zookeeper.
console-consumer-11967 lx_test_topic 0 unknown 465 unknown console-consumer-11967_aws-lx-1513787888172-d3a91f05-0
复制代码
管理运维
建立主题(4个分区,2个副本)
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 4 --topic test
复制代码
查询post
## 查询集群描述
bin/kafka-topics.sh --describe --zookeeper
## 消费者列表查询
bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list
## 新消费者列表查询(支持0.9版本+)
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --list
## 显示某个消费组的消费详情(仅支持offset存储在zookeeper上的)
bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper localhost:2181 --group test
## 显示某个消费组的消费详情(支持0.9版本+)
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --describe --group test-consumer-group
复制代码
发送和消费学习
## 生产者
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
## 高级点的用法
bin/kafka-simple-consumer-shell.sh --brist localhost:9092 --topic test --partition 0 --offset 1234 --max-messages 10
复制代码
平衡leader
bin/kafka-preferred-replica-election.sh --zookeeper zk_host:port/chroot
复制代码
增长副本
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]},
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --execute
bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --verify
复制代码
kafka-consumer-groups.sh 在2.0增长的新功能(查看组信息与状态)
--简约信息
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092,localhost:9093,localhost:9094
--describe --group test-group --members
CONSUMER-ID HOST CLIENT-ID #PARTITIONS
consumer-1-aa3f2e15-d577-4c51-acd5-aa0d488cc131 /127.0.0.1 consumer-1 8
consumer-1-f3b11334-b9eb-4d4f-80d1-766446c77ee9 /127.0.0.1 consumer-1 8
consumer-1-658e4d7b-a561-4430-bbdf-c3ab59a18f3a /127.0.0.1 consumer-1 9
--详细信息
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092,localhost:9093,localhost:9094
--describe --group test-group --members --verbose
CONSUMER-ID HOST CLIENT-ID #PARTITIONS ASSIGNMENT
consumer-1-aa3f2e15-d577-4c51-acd5-aa0d488cc131 /127.0.0.1 consumer-1 8 test-topic(9,10,11,12,13,14,15,16)
consumer-1-f3b11334-b9eb-4d4f-80d1-766446c77ee9 /127.0.0.1 consumer-1 8 test-topic(17,18,19,20,21,22,23,24)
consumer-1-658e4d7b-a561-4430-bbdf-c3ab59a18f3a /127.0.0.1 consumer-1 9 test-topic(0,1,2,3,4,5,6,7,8)
-- 组员状态信息
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092,localhost:9093,localhost:9094
--describe --group test-group --state
COORDINATOR (ID) ASSIGNMENT-STRATEGY STATE #MEMBERS
localhost:9092 (0) range Stable 3
复制代码
上面命令中比较关键的参数包括:
本节内容主要探讨了kafka集群管理重要操做指令运维,可能部分截图来自github公开源码,部分是个人测试案例,若有雷同某位大神私有内容,请直接留言于我,我来从新修正案例。
秦凯新 于深圳