kafka基于lunix系统的安装使用

步骤1:下载程式码

下载 2.5.0发行版并将其解压缩。

> tar -xzf kafka_2.12-2.5.0.tgz
> cd kafka_2.12-2.5.0

步骤2:启动服务器

Kafka使用ZooKeeper,因此如果您还没有,请先启动ZooKeeper服务器。您可以使用kafka随附的便利脚本来获取快速且肮脏的单节点ZooKeeper实例。

> bin/zookeeper-server-start.sh config/zookeeper.properties &
[2013-04-22 15:01:37,495] INFO Reading configuration from: config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
...

现在启动Kafka服务器:

> bin/kafka-server-start.sh config/server.properties &
[2013-04-22 15:01:47,028] INFO Verifying properties (kafka.utils.VerifiableProperties)
[2013-04-22 15:01:47,051] INFO Property socket.send.buffer.bytes is overridden to 1048576 (kafka.utils.VerifiableProperties)
...

步骤3:建立主题

让我们用一个分区和一个副本创建一个名为“ test”的主题:

> bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test

现在,如果我们运行list topic命令,便可以看到该主题:

> bin/kafka-topics.sh --list --bootstrap-server localhost:9092
test

第4步:发送一些消息

Kafka带有一个命令行客户端,它将从文件或标准输入中获取输入,并将其作为消息发送到Kafka集群。默认情况下,每行将作为单独的消息发送。

运行生产者,然后在控制台中键入一些消息以发送到服务器。

 

> bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test
This is a message
This is another message

 

步骤5:启动消费者

Kafka还有一个命令行使用者,它将消息转储到标准输出

> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message
原文地址:https://www.cnblogs.com/zcsheng/p/12992509.html