安装
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,命令运行后会提示你指定
//创建topic过程的问题,replication-factor
个数不能超过 broker 的个数
//操作系统重启后,需要重新创建
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