kafka安装&使用

Precondition

jdk安装
zookeeper安装

安装kafka

kafka 官网:
http://kafka.apache.org/downloads.html
zookeeper官网:
http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.8/

tar zxvf kafka_2.11-0.8.2.2.tgz
mv kafka_2.11-0.8.2.2 kafka
cd kafka
ps: 最好建立软链  ln -s source newFolder

启动Kafka 服务

使用kafka-server-start.sh 启动kafka 服务:

bin/kafka-server-start.sh config/server.properties

[2015-10-26 04:28:56,115] INFO Verifying properties (kafka.utils.VerifiableProperties)
[2015-10-26 04:28:56,141] INFO Property broker.id is overridden to 0 (kafka.utils.VerifiableProperties)

创建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 test

产生消息

使用kafka-console-producer.sh 发送消息:

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test 

Hello world!
Hello Kafka!


消费消息

使用kafka-console-consumer.sh 接收消息并在终端打印:

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

Hello world!
Hello Kafka!

引用:

https://mos.meituan.com/library/32/how-to-install-kafka-on-centos7/

你可能感兴趣的:(kafka安装&使用)