zoukankan      html  css  js  c++  java
  • Kafka安装

    一、安装

    1. 开放防火墙9092端口
    2. 修改配置文件 /conf/server-properties

        broker.id=1 #当前serverID

        listeners=PLAINTEXT://192.168.34.160:9092

        log.dirs=/usr/local/kafka/logs

        num.partitions=2   #根据机器数设置

        zookeeper.connect=192.168.34.161:2181,192.168.34.160:2181

        offsets.topic.replication.factor=3

        transaction.state.log.replication.factor=3

        transaction.state.log.min.isr=1

    二、创建kafka topic

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

    十、查看topic消费进度

    这个会显示出consumer groupoffset情况, 必须参数为--group, 不指定--topic,默认为所有topic

    Displays the: Consumer Group, Topic, Partitions, Offset, logSize, Lag, Owner for the specified set of Topics and Consumer Group

    bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker

     

    required argument: [group]

    Option Description

    ------ -----------

    --broker-info Print broker info

    --group Consumer group.

    --help Print this message.

    --topic Comma-separated list of consumer

       topics (all topics if absent).

    --zkconnect ZooKeeper connect string. (default: localhost:2181)

     

    Example,

     

    bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group pv

     

    Group           Topic              Pid Offset   logSize    Lag    Owner

    pv              page_visits        0   21       21         0      none

    pv              page_visits        1   19       19         0      none

    pv              page_visits        2   20       20         0      none

    以上参数含义解释如下:
    topic:创建时topic名称
    pid:分区编号
    offset:表示该parition已经消费了多少条message
    logSize:表示该partition已经写了多少条message
    Lag:表示有多少条message没有被消费。
    Owner:表示消费者

  • 相关阅读:
    敲七
    二维指针数组**p
    食物链(待解决)
    蛇行矩阵
    快速排序 QuickSort
    堆排序
    猪的安家
    百度语言翻译机
    HTML <base> 标签
    免费网络管理流量监控软件大比拼
  • 原文地址:https://www.cnblogs.com/michaelcnblogs/p/11330827.html
Copyright © 2011-2022 走看看