./kafka-server-start.sh -daemon ./../config/server.properties
./kafka-topics.sh --list --bootstrap-server xx.xx.xx.xx:9092
./kafka-topics.sh --describe --topic
./kafka-console-consumer --bootstrap-server xx.xx.xx.xx:9092 --topic
./kafka-consumer-groups.sh --bootstrap-server xx.xx.xx.xx:9092 --list
./kafka-consumer-groups.sh --bootstrap-server xx.xx.xx.xx:9092 --describe --group
1.1.创建主题
./kafka-topics.sh --bootstrap-server localhost:9092 --create --topic mytesttopic
1.2.指定主题的分区数、副本数创建主题
./kafka-topics.sh --bootstrap-server localhost:9092 --create --replication-factor 1 --partitions 1 --topic mytesttopic
1.3.查看kafka中的主题列表信息
./kafka-topics.sh --bootstrap-server localhost:9092 --list
1.4.查看kafka找那个特定主题的详细信息
./kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic mytesttopic
1.5.修改主题的分区数(只能从小往大改)
./kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic mytesttopic --partitions 2
1.6.删除主题
./kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic mytesttopic
2.1.生产者向指定主题发送消息
./kafka-console-producer.sh broker-list --bootstrap-server localhost:9092 --topic mytesttopic
## 下面为提示的消息输入框
>send message 1
>send message 2
2.2.消费者监听指定消息(消费者每次启动都从主题中最开始的消息开始监听)
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mytesttopic --from-beginning
2.3.消费者监听指定主题的消息(消费者每次启动都从最新的消息开始监听)
注意:该监听方式,如果消费者想监听到消息,那么需要在消费者监听成功后,再使用命令让生产者发送消息
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testtopic0914
3.1.创建一下消费者监听消息,并将该消费者放在名为testgroup消费者组下
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --consumer-property group.id=testgroup --topic testtopic0914
3.2.查看消费者组列表
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
3.3.查看消费者组的详细信息
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group testgroup
消费者组中的各项列表含义如下:
GROUP:消费者组名称
TOPIC:消费者组监听的消息
PARTITON:使用的是第几个分区
CURRENT-OFFSET:当前消息的偏移量
LOG-END-OFFSET:消费的偏移量
LAG:还有多少消费没有被消费,即积压的消息数
3.4.删除消费者组
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group {消费组}
4.1.向集群中发送消息
[root@localhost kafka_2.12-3.5.1]# ./bin/kafka-console-producer.sh --broker-list 192.168.154.128:9092,192.168.154.128:9093,192.168.154.128:9094 --topic topic0921
需要在命令后加上配置
--command-config /kafka/kafka-client-jaas.conf
/kafka/kafka-client-jaas.conf 的位置和文件都是个人放置的
kafka-client-jaas.conf 文件内容:
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="username" password="password"
例如:
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list --command-config /kafka/kafka-client-jaas.conf
补充:
实时查看(1s刷新一次)
watch -n 1 './kafka-topics.sh --bootstrap-server xx.xx.xx.xx:9092 --describe --topic
--command-config /kafka/kafka-client-jaas.conf '
模糊查看
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list --command-config /kafka/kafka-client-jaas.conf | grep topicaaaa