kafka运维常用命令
所属分类 kafka
浏览量 2846
./kafka-broker-api-versions.sh --bootstrap-server localhost:9092
验证不同Kafka版本之间服务器和客户端的适配性
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --list
bin/kafka-log-dirs.sh --bootstrap-server localhost:9092 --describe
./kafka-run-class.sh kafka.tools.JmxTool --jmx-url service:jmx:rmi:///jndi/rmi://localhost:9995/jmxrmi
列出所有的topic
./bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list
./bin/kafka-topics.sh --zookeeper 127.0.0.1:2182/kafka --list
注意 zk地址 ,尤其是chroot , 路径不对 无法显示 ,查不到结果
查看 topic信息
./bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --describe --topic topicName
./bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --describe --topic __consumer_offsets
./bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --describe --topic kafka_demo_test_topic
./bin/kafka-topics.sh --zookeeper 127.0.0.1:2182/kafka --describe --topic ".*"
查看所有的group
./bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 localhost:2181 --list
查看消费情况
./bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --describe --group kafkademo_test_group
kafka-consumer-groups.sh
老版本 消费元数据存在zk上 使用 --zookeeper localhost:2181
新版本 使用 --bootstrap-server 127.0.0.1:9092
./bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --describe --topic kafka_demo_test_topic
Topic:kafka_demo_test_topic PartitionCount:6 ReplicationFactor:1 Configs:
Topic: kafka_demo_test_topic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: kafka_demo_test_topic Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: kafka_demo_test_topic Partition: 2 Leader: 0 Replicas: 0 Isr: 0
Topic: kafka_demo_test_topic Partition: 3 Leader: 0 Replicas: 0 Isr: 0
Topic: kafka_demo_test_topic Partition: 4 Leader: 0 Replicas: 0 Isr: 0
Topic: kafka_demo_test_topic Partition: 5 Leader: 0 Replicas: 0 Isr: 0
./bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 localhost:2181 --list
Note: This will not show information about old Zookeeper-based consumers.
kafka_demo_test_topic
kafkademo_test_group
./bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --describe --group kafkademo_test_group
Note: This will not show information about old Zookeeper-based consumers.
TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
kafka_demo_test_topic 1 114 114 0 consumer-1-e989cb0d-d9b5-4473-8317-feb897e2e686 /127.0.0.1 consumer-1
kafka_demo_test_topic 2 98 98 0 consumer-1-e989cb0d-d9b5-4473-8317-feb897e2e686 /127.0.0.1 consumer-1
kafka_demo_test_topic 5 95 95 0 consumer-1-e989cb0d-d9b5-4473-8317-feb897e2e686 /127.0.0.1 consumer-1
kafka_demo_test_topic 0 99 99 0 consumer-1-e989cb0d-d9b5-4473-8317-feb897e2e686 /127.0.0.1 consumer-1
kafka_demo_test_topic 4 84 84 0 consumer-1-e989cb0d-d9b5-4473-8317-feb897e2e686 /127.0.0.1 consumer-1
kafka_demo_test_topic 3 100 100 0 consumer-1-e989cb0d-d9b5-4473-8317-feb897e2e686 /127.0.0.1 consumer-1
CURRENT_OFFSET 当前消费offset
LOG_ENG_OFFSET 最新的offset
LAG 落后多少
增加分区数 只能加不能减
./bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --alter --partitions 8 --topic kafka_demo_test_topic
查看主题offset
./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --time -1 --topic kafka_demo_test_topic
--time timestamp of the offsets before that (earliest) (default: -1)
查看数据文件数据
./kafka-run-class.sh kafka.tools.DumpLogSegments --files /Users/dugang/soft/elk/kafka-cluster/kafka0/kafka-logs/kafka_demo_test_topic-1/00000000000000000023.log | head -n 10
./kafka-run-class.sh kafka.tools.DumpLogSegments --deep-iteration --files /Users/dugang/soft/elk/kafka-cluster/kafka0/kafka-logs/kafka_demo_test_topic-1/00000000000000000023.log | head -n 10
./kafka-run-class.sh kafka.tools.DumpLogSegments --print-data-log --files /Users/dugang/soft/elk/kafka-cluster/kafka0/kafka-logs/kafka_demo_test_topic-1/00000000000000000023.log | head -n 10
--print-data-log 显示消息数据
offset: 23 position: 0 CreateTime: 1598148413924 isvalid: true keysize: 16 valuesize: 45 magic: 2 compresscodec: NONE producerId: -1 producerEpoch: -1 sequence: -1 isTransactional: false headerKeys: [] key: 1598148413924_14 payload: 1598148413924_14,Sun Aug 23 10:06:53 CST 2020
offset: 24 position: 130 CreateTime: 1598148413961 isvalid: true keysize: 16 valuesize: 45 magic: 2 compresscodec: NONE producerId: -1 producerEpoch: -1 sequence: -1 isTransactional: false headerKeys: [] key: 1598148413960_18 payload: 1598148413960_18,Sun Aug 23 10:06:53 CST 2020
offset: 25 position: 260 CreateTime: 1598148414002 isvalid: true keysize: 16 valuesize: 45 magic: 2 compresscodec: NONE producerId: -1 producerEpoch: -1 sequence: -1 isTransactional: false headerKeys: [] key: 1598148414001_23 payload: 1598148414001_23,Sun Aug 23 10:06:54 CST 2020
性能压测
./kafka-producer-perf-test.sh --topic kafka_demo_test_topic --num-records 1000000 --throughput -1 --record-size 128 --producer-props bootstrap.servers=localhost:9092 acks=-1 linger.ms=2000 compression.type=lz4
./kafka-consumer-perf-test.sh --broker-list localhost:9092 --messages 1000000 --topic producer
检查复制是否有延迟
bin/kafka-replica-verification.sh --broker-list localhost:9092 --topic-white-list kafka_demo_test_topic
verification process is started.
2020-08-24 08:51:02,458: max lag is 0 for partition kafka_demo_test_topic-1 at offset 169043 among 6 partitions
2020-08-24 08:51:32,459: max lag is 0 for partition kafka_demo_test_topic-1 at offset 169043 among 6 partitions
2020-08-24 08:52:02,460: max lag is 0 for partition kafka_demo_test_topic-1 at offset 169043 among 6 partitions
2020-08-24 08:52:32,462: max lag is 0 for partition kafka_demo_test_topic-1 at offset 169043 among 6 partitions
消息发送与消费测试
bin/kafka-verifiable-producer.sh --broker-list 127.0.0.1:9092 --topic kafka_demo_test_topic --max-messages 1000
bin/kafka-verifiable-consumer.sh --broker-list 127.0.0.1:9092 --topic kafka_demo_test_topic --group-id group001
上一篇
下一篇
寒冬里说经济周期
kafka consumer均衡算法
Kafka1.1.0 Broker配置
程序员的誓言
zookeeper使用场景
arthas使用