zoukankan      html  css  js  c++  java
  • kafka使用

    启动zookeeper
    
    bin/zookeeper-server-start.sh config/zookeeper.properties &
    
    启动kafka
    
    bin/kafka-server-start.sh config/server.properties &
    
    停止kafka
    bin/kafka-server-stop.sh
    
    停止zookeeper
    bin/zookeeper-server-stop.sh
    
    创建topic
    bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
    
    展示topic
    bin/kafka-topics.sh --list --zookeeper localhost:2181
    
    描述topic
    bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic
    
    生产者:
    bin/kafka-console-producer.sh --broker-list 130.51.23.95:9092 --topic my-replicated-topic
    
    消费者:
    bin/kafka-console-consumer.sh --zookeeper 130.51.23.95:2181 --topic test --from-beginnin
    

    创建kafka topic

    bin/kafka-topics.sh --zookeeper node01:2181 --create --topic t_cdr --partitions 30  --replication-factor 2
    

    注: partitions指定topic分区数,replication-factor指定topic每个分区的副本数

    • partitions分区数:
      • partitions :分区数,控制topic将分片成多少个log。可以显示指定,如果不指定则会使用broker(server.properties)中的num.partitions配置的数量
      • 虽然增加分区数可以提供kafka集群的吞吐量、但是过多的分区数或者或是单台服务器上的分区数过多,会增加不可用及延迟的风险。因为多的分区数,意味着需要打开更多的文件句柄、增加点到点的延时、增加客户端的内存消耗。
      • 分区数也限制了consumer的并行度,即限制了并行consumer消息的线程数不能大于分区数
      • 分区数也限制了producer发送消息是指定的分区。如创建topic时分区设置为1,producer发送消息时通过自定义的分区方法指定分区为2或以上的数都会出错的;这种情况可以通过alter –partitions 来增加分区数。
    • replication-factor副本
      • replication factor 控制消息保存在几个broker(服务器)上,一般情况下等于broker的个数。
      • 如果没有在创建时显示指定或通过API向一个不存在的topic生产消息时会使用broker(server.properties)中的default.replication.factor配置的数量

    查看所有topic列表

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

    查看指定topic信息

    bin/kafka-topics.sh --zookeeper node01:2181 --describe --topic t_cdr
    

    控制台向topic生产数据

    bin/kafka-console-producer.sh --broker-list node86:9092 --topic t_cdr
    

    控制台消费topic的数据

    bin/kafka-console-consumer.sh  --zookeeper node01:2181  --topic t_cdr --from-beginning
    

    查看topic某分区偏移量最大(小)值

    bin/kafka-run-class.sh kafka.tools.GetOffsetShell --topic hive-mdatabase-hostsltable  --time -1 --broker-list node86:9092 --partitions 0
    

    注: time为-1时表示最大值,time为-2时表示最小值

    增加topic分区数

    为topic t_cdr 增加10个分区

    bin/kafka-topics.sh --zookeeper node01:2181  --alter --topic t_cdr --partitions 10
    

    删除topic,慎用,只会删除zookeeper中的元数据,消息文件须手动删除

    bin/kafka-run-class.sh kafka.admin.DeleteTopicCommand --zookeeper node01:2181 --topic t_cdr
    
  • 相关阅读:
    cmd中输入vue ui不起作用
    win10下如何让别人访问自己的数据库,开放3306端口
    maven出现报错:Failed to execute goal on project ***** Could not resolve dependencies for project com.**.**.**:jar:0.0.1-SNAPSHOT: Could not find artifact:jar:1.0-SNAPSHOT -> [Help 1]
    vue中改变字体大小,px不起作用
    vue安装教程
    Springboot快速入门
    【POI】Excel数据导入
    【MySQL】替换件需求
    【Git】Gitlab仓库访问拒绝,SSL校验影响
    【MySQL】java.sql.SQLException: Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '='
  • 原文地址:https://www.cnblogs.com/studyNotesSL/p/11420173.html
Copyright © 2011-2022 走看看