linux环境安装kafka
1、wget下载想要的版本,版本信息见链接:link http://archive.apache.org/dist/kafka/具体版本/具体文件
2、下载到主机后解压缩,重命名文件
tar -zxvf kafka_2.12-3.1.0.tgz
mv kafka_2.12-3.1.0 kafka
3、修改配置文件server.properties,主要修改如下几个参数即可
listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://自己linux主机ip:9092
zookeeper.connect=127.0.0.1:2181
4、可以启动了
4.1 启动zk,因为kafka依赖zk
在解压后的目录下执行
./kafka/bin/zookeeper-server-start.sh ../config/zookeeper.properties
4.2 启动kafka
同样在解压后的路径下执行
./kafka/bin/kafka-server-start.sh ../config/server.properties
4.3 创建topic测试
./kafka/bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092
./kafka/bin/kafka-topics.sh --bootstrap-server 自己linux主机IP:9092 --create --partitions 1 --replication-factor 1 --topic test
以上两种创建方式均可,针对不同版本的执行,本文是kafka_2.12-3.1.0 使用--bootstrap-server,低于这个版本使用 --zookeeper
4.4 查看创建的topic
./kafka-topics.sh --bootstrap-server localhost:9092 --list
4.5 创建生产者、消费者
//生产者
./kafka-console-producer.sh --broker-list localhost:9092 --topic test
//消费者
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test
通过以上修改执行,kafka_2.12-3.1.0的下载、启动、简单使用基本完成,后续会将kafka整合springboot的操作更新