1. 下载
wget http://mirror.bit.edu.cn/apache/kafka/2.3.0/kafka_2.12-2.3.0.tgz
2. 解压
tar
-xzf kafka_2.12-2.3.0.tgz
cd
kafka_2.12-2.3.0
软连接
mkdir /usr/kafka
ln -s /usr/local/kafka_2.12-2.3.0 /usr/kafka/latest
3. 启动服务
启动自带zookeeper
bin
/zookeeper-server-start
.sh config
/zookeeper
.properties
启动kafka server
bin
/kafka-server-start
.sh config
/server
.properties
创建topic
Let's create a topic named "test" with a single partition and only one replica:
创建名称为test的topic
bin
/kafka-topics
.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic
test
topic列表
bin
/kafka-topics
.sh --list --bootstrap-server localhost:9092
发送消息
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