安装 kafka
下载地址:http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.3.0/kafka_2.11-2.3.0.tgz
tar -zxvf kafka_2.11-2.3.0.tgz cd /usr/local/kafka_2.11-2.3.0/
修改 kafka-server 的配置文件
vi /usr/local/kafkaa_2.11-2.3.0/config/server.properties
修改如下
broker.id=1 log.dir=/data/kafka/logs-1
常用功能
1、启动 zookeeper
使用安装包中的脚本启动单节点 Zookeeper 实例:
sh bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
2、启动Kafka 服务
使用 kafka-server-start.sh
启动 kafka 服务:
sh bin/kafka-server-start.sh config/server.properties
3、创建 topic
使用 kafka-topics.sh
创建单分区单副本的 topic test:
sh bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
查看是否创建成功
bin/kafka-topics.sh --list --zookeeper localhost:2181
5、消费消息
使用 kafka-console-consumer.sh
接收消息并在终端打印:
sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic second-kafka-topic--from-beginning
会卡在这里,启动一个窗口
输入命令
sh bin/kafka-console-producer.sh --broker-list localhost:9092 --topic second-kafka-topic
会出现箭头输入发送信息
这里就接受到了
6、查看描述 topics 信息
sh bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic second-kafka-topic