服务启动、停止
# 启动服务(所有节点)
bin/kafka-server-start.sh config/server.properties &
# 停止服务(所有节点)
bin/kafka-server-stop.sh
topic 创建、列出、删除
# 创建 topic
bin/kafka-topics.sh --create \
--zookeeper zk1:2181,zk2:2181,zk3:2181 \ # 指定 zk 地址
# --bootstrap-server broker1:9092 # or 指定 broker 地址
--replication-factor 3 \ # 指定 topic 副本数量
--partitions 3 \ # 指定 topic 分区数量
--topic test-topic # 指定 topic 名称
# 查询指定 topic 信息
bin/kafka-topics.sh --describe \
--zookeeper zk1:2181,zk2:2181,zk3:2181 \
--topic yunweimao
# 列出所有 topic
bin/kafka-topics.sh --list \
--zookeeper zk1:2181,zk2:2181,zk3:2181
# 删除 topic
bin/kafka-topics.sh --delete \
--zookeeper zk1:2181,zk2:2181,zk3:2181 \
--topic test-topic
创建 producer 发送消息测试
bin/kafka-console-producer.sh --broker-list broker1:9092 -topic test-topic
>hello word
>assad welcome
创建 consumer 消费消息测试
bin/kafka-console-consumer.sh \
--bootstrap-server broker2:9092\
--from-beginning \
-topic test-topic