kafka常用命令
以下是kafka常用命令行总结:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
1、kafka服务启动
./kafka-server-start.sh -daemon ../config/server.properties

<!-- more -->

2、创建topic
./kafka-topics.sh --create --zookeeper hadoop01:2181 --replication-factor 1 --partitions 1 --topic test

2.1、为topic增加副本
./kafka-reassign-partitions.sh -zookeeper hadoop01:2181 -reassignment-json-file json/partitions-to-move.json -execute

2.2、为topic增加partition
./bin/kafka-topics.sh –zookeeper hadoop01:2181 –alter –partitions 20 –topic test

3、查看有哪些topic:
./kafka-topics.sh --list --zookeeper hadoop01:2181

4、查看topic的详细信息
./kafka-topics.sh -zookeeper hadoop01:2181 -describe -topic test

5、kafka生产者客户端命令
./kafka-console-producer.sh --broker-list hadoop01:9092 --topic test

6、kafka消费者客户端命令
./kafka-console-consumer.sh -zookeeper hadoop01:2181 --from-beginning --topic test


**<<** 更多精彩尽在『程序萌部落』**>>**
**<<** [https://www.cxmoe.com](https://www.cxmoe.com) **>>**

[成功]

7、下线broker
./kafka-run-class.sh kafka.admin.ShutdownBroker --zookeeper hadoop01:2181 --broker #brokerId# --num.retries 3 --retry.interval.ms 60
shutdown broker

8、删除topic
./kafka-run-class.sh kafka.admin.DeleteTopicCommand --topic test --zookeeper hadoop01:2181
./kafka-topics.sh --zookeeper hadoop01:2181 --delete --topic test
实际不会删除,只会显示marked for deletion

9、查看consumer组内消费的offset
./kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper hadoop01:2181 --group test --topic test
./kafka-consumer-offset-checker.sh --zookeeper hadoop01:2181 --group group1 --topic group1
1
2
3
4
5
6
7
8
9
10
11
12
13
[hadoop@hadoop01 bin]$ kafka-topics.sh --create --zookeeper hadoop01,hadoop02,hadoop03 --replication-factor 1 --partitions 3 --topic hadoop01
Created topic "hadoop01".
[hadoop@hadoop01 bin]$ kafka-topics.sh --create --zookeeper hadoop01,hadoop02,hadoop03 --replication-factor 3 --partitions 1 --topic hadoop02
Created topic "hadoop02".
[hadoop@hadoop01 bin]$ kafka-topics.sh --list --zookeeper localhost:2181
hadoop01
hadoop02
[hadoop@hadoop01 bin]$ kafka-topics.sh --describe --zookeeper localhost:2181 --topic hadoop01
Topic:hadoop01 PartitionCount:3 ReplicationFactor:1 Configs:
Topic: hadoop01 Partition: 0 Leader: 3 Replicas: 3 Isr: 3
Topic: hadoop01 Partition: 1 Leader: 1 Replicas: 1 Isr: 1
Topic: hadoop01 Partition: 2 Leader: 2 Replicas: 2 Isr: 2
----------------------------------



全站共计 313.7k 字,自豪地使用 Volantis 主题

博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议