kafka安装和简单测试

时间:2022-02-03 09:08:53

kafka安装和简单测试

# 安装zookeeper(apache-zookeeper-3.5.6-bin)
https://archive.apache.org/dist/zookeeper/zookeeper-3.5.6/apache-zookeeper-3.5.6-bin.tar.gz

# 安装kafka(kafka_2.11-2.3.1)
http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.3.1/kafka_2.11-2.3.1.tgz

# 启动zookeeper
[root@localhost apache-zookeeper-3.5.6-bin]# bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /svelldata/apache-zookeeper-3.5.6-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

# 启动kafka server
[root@localhost kafka_2.11-2.3.1]# bin/kafka-server-start.sh config/server.properties

# 创建一个话题,test话题2个分区
[root@localhost kafka_2.11-2.3.1]# bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 2 --topic mytopic

[root@localhost kafka_2.11-2.3.1]# bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic mytopic

# 显示所有话题
[root@localhost kafka_2.11-2.3.1]# bin/kafka-topics.sh --list --zookeeper localhost:2181

# 显示话题信息
[root@localhost kafka_2.11-2.3.1]# bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic mytopic

# 启动一个生产者(输入消息)
[root@localhost kafka_2.11-2.3.1]# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mytopic

# 启动一个消费者(等待消息)
# 注意这里的--from-beginning,每次都会从头开始读取,你可以尝试去掉和不去掉看下效果
[root@localhost kafka_2.11-2.3.1]# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mytopic --from-beginning

[root@localhost kafka_2.11-2.3.1]# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mytopic

https://github.com/edenhill/librdkafka
yum install librdkafka-devel

https://github.com/arnaud-lb/php-rdkafka
https://github.com/arnaud-lb/php-rdkafka#installation

参考:

https://www.jianshu.com/p/6ff7f0ad2de9

https://segmentfault.com/a/1190000015765348