kafka安装

安装

1.下载kafka_2.13-3.0.0.tar 不同版本,命令稍有不同(2.13是scala版本,3.0.0是kafka版本)

2.放到/usr/local/share/kafka

3.解压tar -xvf kafka_2.13-3.0.0.tar

4.修改名字mv kafka_2.13-3.0.0 kafka3

 

单机测试,不修改zookeeper.properties 和 server.properties

1.启动zookeeper

bin/zookeeper-server-start.sh config/zookeeper.properties
使用 bin/zookeeper-server-start.sh -daemon config/zookeeper.properties 以守护进程启动

2. 启动kafka

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

3.创建topic

bin/kafka-topics.sh --create --topic topicName --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
//--bootstrap-server localhost:9092 指定consumer,由kafka来维护信息; 老的使用--zookeeper ip:2181,这样就由zk来维护信息。
//官网没有指定partitions,命令运行后会提示你指定
//replication-factor数量不能超过broker数量
//操作系统重启后,需要重新创建,原因是server.properties默认配置log在/tmp下,数据存储地址zookeeper.properties默认也是/tmp

4.查看所有topic

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

5.查看topic

bin/kafka-topics.sh --describe --topic name --bootstrap-server localhost:9092

 

6.生产消息(write event)

bin/kafka-console-producer.sh --topic name --bootstrap-server localhost:9092
This is my first event (回车即表示一条结束)
This is my second event

control+c 退出

7.消费消息(read event)

bin/kafka-console-consumer.sh --topic name --from-beginning --bootstrap-server localhost:9092
This is my first event
This is my second event

8.删除topic

bin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic topicName

 

posted @ 2021-09-27 16:58  jason47  阅读(426)  评论(0编辑  收藏  举报