• Kafka3.x安装以及使用


    一、Kafka下载

    下载地址:https://kafka.apache.org/downloads
    在这里插入图片描述

    二、Kafka安装

    因为选择下载的是 .zip 文件,直接跳过安装,一步到位。
    选择在任一磁盘创建空文件夹(不要使用中文路径),解压之后把文件夹内容剪切进去(本人选择 D:\env-java\路径下,即完成安装)。
    linux解压命令tar -zxvf kafka_2.13-3.5.1.tgz,linux环境下指令是在\kafka_2.13-3.5.1\bin目录。
    windows直接解压即可,windows环境下指令是在kafka_2.13-3.5.1\bin\windows目录。
    注意:不同系统指令所在的目录不同。
    执行命令当前目录D:\env-java\kafka_2.13-3.5.1

    修改 kafka-server 和zookeeper配置

    进入到目录:kafka_2.13-3.5.1/config/server.properties以及kafka_2.13-3.5.1/config/zookeeper.properties

    • linux系统:
    broker.id=1
    log.dir=/Users/imagetask/kafka-logs
    
       
       
    • 1
    • 2

    在这里插入图片描述

    • windows系统:
    broker.id=1
    log.dirs=/env-java/kafka_2.13-3.5.1/kafka-logs
    
       
       
    • 1
    • 2

    在这里插入图片描述
    在这里插入图片描述
    /:表示当前的根路径,即D盘。没有就会创建对应的文件夹。

    三、启动Kafka服务

    1、启动ZooKeeper
    • linux系统:
    bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
    
       
       
    • 1
    • windows系统:
    bin\windows\zookeeper-server-start.bat config\zookeeper.properties	
    
       
       
    • 1
    2、启动kafka
    • linux系统:
    bin/kafka-server-start.sh config/server.properties
    
       
       
    • 1
    • windows系统:
    bin\windows\kafka-server-start.bat config\server.properties
    
       
       
    • 1

    四、Kafka的使用

    1、创建主题
    • linux系统:
    bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
    
       
       
    • 1
    • windows系统:
    bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
    
       
       
    • 1
    2、删除主题
    • linux系统:
    bin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic test
    
       
       
    • 1
    • windows系统:
    bin\windows\kafka-topics.bat --delete --bootstrap-server localhost:9092 --topic test
    
       
       
    • 1
    3、查看Topic 列表
    • linux系统:
    bin/kafka-topics.sh --list --bootstrap-server localhost:9092
    
       
       
    • 1
    • windows系统:
    bin\windows\kafka-topics.bat --list --bootstrap-server localhost:9092
    
       
       
    • 1
    4、启动 Producer
    • linux系统:
    bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
    
       
       
    • 1
    • windows系统:
    bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test
    
       
       
    • 1
    5、启动 Consumer
    • linux系统:
    bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
    
       
       
    • 1
    • windows系统:
    bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
    
       
       
    • 1
    6、查看Topic 相关信息(test)
    • linux系统:
    bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test
    
       
       
      • 1
      • windows系统:
      bin\windows\kafka-topics.bat --describe --bootstrap-server localhost:9092 --topic test
      
         
         
      • 1
      7、删除Topic 数据(test)
      • linux系统:
      bin\windows\kafka-delete-records.sh--bootstrap-server localhost:9092 --offset-json-file d:\delete_script.json
      
         
         
        • 1
        • windows系统:
        bin\windows\kafka-delete-records.bat --bootstrap-server localhost:9092 --offset-json-file d:\delete_script.json
        
           
           
        • 1
        delete_script.json文件内容为:{"partitions":[{"topic": "test", "partition": 0, "offset": -1}]}
        
           
           
        • 1

      • 相关阅读:
        Spring for Apache Kafka概述和简单入门
        【计算机网络笔记四】应用层(一)DNS域名解析
        接口测试vs功能测试
        【软件测试】(北京)字节跳动科技有限公司二面笔试题
        现代循环神经网络 - 序列到序列学习
        【paper】Cam2BEV论文浅析
        「RocketMQ」消息的刷盘机制
        Dart语言入门
        大数据培训之phoenix的索引分类
        源码深度剖析Spring Cloud Gateway如何处理一个请求(只能那么细了)【云原生】
      • 原文地址:https://blog.csdn.net/zhangjunli/article/details/133981972