kafka常用命令

1、启动Kafka

# 通过zookepper
./bin/zookeeper-server-start.sh config/zookeeper.properties
# 通过kRaft
./bin/kafka-server-start.sh ./config/server.properties &

2、停止Kafka

./bin/kafka-server-stop.sh

3、创建Topic

# 通过zookepper
./bin/kafka-topics.sh --create --partitions 3 --replication-factor 2 --topic test --zookeeper 192.168.209.102:2181
# 通过kRaft
./bin/kafka-topics.sh --create --partitions 3 --replication-factor 2 --topic test --bootstrap-server 192.168.209.102:9092

4、查看已经创建的Topic信息

# 通过zookepper
./bin/kafka-topics.sh --list --zookeeper 192.168.209.102:2181
# 通过kRaft
./bin/kafka-topics.sh --list --bootstrap-server 192.168.209.102:9092,192.168.209.102:9093,192.168.209.102:9094

5、查看topic详情

# 通过zookepper
./bin/kafka-topics.sh --describe --topic test --zookeeper 192.168.209.102:2181
# 通过kRaft
./bin/kafka-topics.sh  --describe --topic test --bootstrap-server 192.168.209.102:9092,192.168.209.102:9093,192.168.209.102:9094

6、删除topic

# 通过zookepper
./bin/kafka-topics.sh  --delete --topic test --zookeeper  192.168.209.102:2181
# 通过kRaft
./bin/kafka-topics.sh --delete --topic test --bootstrap-server 192.168.209.102:9092,192.168.209.102:9093,192.168.209.102:9094

7、发送消息

./bin/kafka-console-producer.sh --topic test --broker-list 192.168.209.102:9092,192.168.209.102:9093,192.168.209.102:9094

8、接收消息

./bin/kafka-console-consumer.sh --topic test --bootstrap-server 192.168.209.102:9092,192.168.209.102:9093,192.168.209.102:9094
posted @ 2023-10-07 11:27  尐海爸爸  阅读(42)  评论(0编辑  收藏  举报