zoukankan      html  css  js  c++  java
  • kafka:安装和命令行使用

    在讲kafka使用之前,可以简要介绍一下安装local版本

    • 在linux下安装本地版(localhost):

    1. 首先下载 kafka:http://kafka.apache.org/downloads

    2. 其次解压(命令:tar -xzf kafka_2.12-2.6.0.tgz)到某个文件夹下,假设选的版本是 kafka_2.12-2.6.0.tgz,解压之后得到文件夹:kafka_2.12-2.6.0

    3. cd kafka_2.12-2.6.0 即可开始使用kafka命令(主要命令全在该文件夹的bin目录下,例如创建topic,生产messgae,消费数据等)

    • windows下:

    kafka在windows下的安装可以参考:https://www.cnblogs.com/coloz/p/10487679.html 和 https://www.cnblogs.com/wdfordream/p/7325315.html,非常详细。

    注意:目前版本的kafka安装后,已经不需要再安装zookeeper;其次使用kafka必须安装 java 8,所以要先下载和安装 java jdk。

    kafka使用步骤

    1. 开启zookeeper服务
    2. 开启kafka服务
    3. 创建topic
    4. 生产或者消费message流数据

    kafka使用命令:

    windows下:

    1. 查看 consumer-group (老版用zookeeper参数,新版用bootstrap-server)
    cd Program_Fileskafka_2.12-2.6.0
    .inwindowskafka-consumer-groups.bat --bootstrap-server localhost:9092 --list
    
    2. 查看topics列表
    cd Program_Fileskafka_2.12-2.6.0
    .inwindowskafka-topics.bat --list --zookeeper localhost:2181
    
    3. 删除topic
    cd Program_Fileskafka_2.12-2.6.0 .inwindowskafka
    -topics.bat --delete --zookeeper localhost:2181 --topic test_topic 如果kafaka启动时加载的配置文件中server.properties没有配置delete.topic.enable=true,那么此时的删除并不是真正的删除,而是把topic标记为:marked for deletion 4. 查看consumer-group详情:使用--group与--describe参数 (老版用zookeeper参数,新版用bootstrap-server) cd Program_Fileskafka_2.12-2.6.0 .inwindowskafka-consumer-groups.bat --bootstrap-server localhost:9092 --group console-consumer-52402 --describe
    (console
    -consumer-52402: 消费者组名) 5. 查看某个topic详细信息 cd Program_Fileskafka_2.12-2.6.0 .inwindowskafka-topics.bat --zookeeper localhost:2181 --topic test_topic --describe 6. 开启 zookeeper cmd zkserver 7. 创建 topics cd Program_Fileskafka_2.12-2.6.0 .inwindowskafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test_topic 8. 开启kafka (目录不能太深) cd Program_Fileskafka_2.12-2.6.0 .inwindowskafka-server-start.bat .configserver.properties 9. 进入生产者进程: cd Program_Fileskafka_2.12-2.6.0 .inwindowskafka-console-producer.bat --broker-list localhost:9092 --topic test_topic 10. 进入消费者进程: cd Program_Fileskafka_2.12-2.6.0 .inwindowskafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test_topic --from-beginning .inwindowskafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test_topic(默认从latest)

    linux下使用与此类似,只不过是 sh命令:参考

    例如:

    1. 开启kafka
    cd kafka_2.12-2.6.0
    bin/kafka-server-start.sh config/server.properties
    
    2. 开启zookeeper
    bin/zookeeper-server-start.sh config/zookeeper.properties
    
    3. 创建topic
    bin/kafka-topics.sh --create --topic test_topic --bootstrap-server localhost:9092
    
    4. 详细查看topic
    bin/kafka-topics.sh --describe --topic test_topic --bootstrap-server localhost:9092
    
    5. 进入生产者,产生消息
    bin/kafka-console-producer.sh --topic test_topic --bootstrap-server localhost:9092
    
    6. 消费message
    bin/kafka-console-consumer.sh --topic test_topic --from-beginning --bootstrap-server localhost:9092

    #

    参考:

    http://kafka.apache.org/quickstart

  • 相关阅读:
    Spring Security
    用过sessionid防钓鱼
    request获取json
    相对于Statement,PreparedStatement的优点是什么?
    jquery中$.get()提交和$.post()提交有区别吗?
    相对于Statement,PreparedStatement的优点是什么?
    什么是Redis?
    如何解决表单提交的中文乱码问题
    execute,executeQuery,executeUpdate的区别是什么?
    根据你以往的经验简单叙述一下MYSQL的优化
  • 原文地址:https://www.cnblogs.com/qi-yuan-008/p/13912377.html
Copyright © 2011-2022 走看看