下载
wget http://mirror.bit.edu.cn/apache/kafka/1.0.0/kafka_2.11-1.0.0.tgz
解压并cd进去
tar -zvxf kafka_2.11-1.0.0.tgz -C /usr/local/
cd /usr/local/kafka_2.11-1.0.0/
修改配置文件
vim config/server.properties
修改内容:
broker.id=1
log.dirs=data/kafka-logs
功能验证
启动zookeeper:
使用安装包中的脚本启动单节点Zookeeper实例:
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
启动Kafka服务
使用kafka-server-start.sh启动kafka服务:
bin/kafka-server-start.sh config/server.properties
创建Topic
使用kafka-topics.sh 创建但分区单副本的topic test
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
查看Topic
bin/kafka-topics.sh --list --zookeeper localhost:2181
产生消息
使用kafka-console-producer.sh 发送消息
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
消费消息
使用kafka-console-consumer.sh 接收消息并在终端打印
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
删除Topic
bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic test
查看描述 Topic 信息
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test