本套系列博客從真實商業環境抽取案例進行總結和分享,並給出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公開源碼,部分是個人測試案例,若有雷同某位大神私有內容,請直接留言於我,我來從新修正案例。
秦凱新 於深圳