centos7 kafka安装

环境:
  • jdk1.8
  • kafka2.11
  • centos7

kafka必须依赖zookeeper集群环境才能启动成功。

cd kafka #进入自己创建的kafka目录
wget
http://mirror.bit.edu.cn/apache/kafka/2.6.0/kafka_2.13-2.6.0.tgz #下载安装包
tar -zxvf kafka_2.13-2.6.0.tgz #解压

启动kafka命令:

[root@cat kafka_2.13-2.6.0]# bin/kafka-server-start.sh -daemon config/server.properties   #加上 -daemon 让服务在后台运行

 停止kafka命令:

bin/kafka-server-stop.sh

创建主题:(1个副本,1个分区)

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

查看主题:

bin/kafka-topics.sh --list --zookeeper localhost:2181

 查看某个主题的详细信息:

bin/kafka-topics.sh --describe --topic test --zookeeper localhost:2181

 测试消费发送和消费:

生产者发送消息

两种都可以:
bin/kafka-console-producer.sh --topic test --broker-list localhost:9092

bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test  

消费者消费消息

bin/kafka-console-consumer.sh --topic test --zookeeper localhost:2181 #旧版本的

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic test #新版本的
原文地址:https://www.cnblogs.com/cat520/p/14091622.html