版本选择

目前阿里云最新版本是基于2.2.0版本开发

下载

# http://kafka.apache.org/downloads
# https://archive.apache.org/dist/kafka/2.2.0/kafka_2.12-2.2.0.tgz

tar xzf kafka_2.12-2.2.0.tgz
[ -d /usr/local/kafka ] || mv kafka_2.12-2.2.0 /usr/local/kafka

测试

# 创建topic
cd /usr/local/kafka
# 新版本用的bootstrap-server参数直接访问kafka的broker
# 老版本还是连接的zk
bin/kafka-topics.sh --create --zookeeper 127.0.0.1:2181 --replication-factor 1 --partitions 1 --topic test

# 查看topic
bin/kafka-topics.sh --list --zookeeper 127.0.0.1:2181
# 发送消息
> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message
This is another message

# 接收消息
> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message

/usr/local/kafka/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning