学习链接:https://www.bilibili.com/video/BV1vr4y1677k?p=65&spm_id_from=pageDriver&vd_source=b9e4f35102d61e6d02e0a5e1bbfea480


1 Kafka-Kraft架构

QQ截图20220709185016.png
左图为 Kafka 现有架构,元数据在 zookeeper 中,运行时动态选举 controller,由controller 进行 Kafka 集群管理。右图为 kraft 模式架构(实验性),不再依赖 zookeeper 集群,而是用三台 controller 节点代替 zookeeper,元数据保存在 controller 中,由 controller 直接进行 Kafka 集群管理。

2 Kafka-Kraft集群部署

  1. 关闭Kafka集群

    1. [qtbhy@hadoop102 ~]$ kf.sh stop
  2. 解压kafka安装包

    1. [qtbhy@hadoop102 software]$ tar -zxvf kafka_2.12-3.0.0.tgz -C /opt/module
  3. 重命名为kafka2

    1. [qtbhy@hadoop102 module]$ mv kafka_2.12-3.0.0/ kafka2
  4. 在 hadoop102 上修改/opt/module/kafka2/config/kraft/server.properties 配置文件 ```shell

    The role of this server. Setting this puts us in KRaft mode

    process.roles=broker,controller

The node id associated with this instance’s roles

node.id=2

The connect string for the controller quorum

controller.quorum.voters=2@hadoop102:9093,3@hadoop103:9093,4@hadoop104:9093

Hostname and port the broker will advertise to producers and consumers. If not set,

it uses the value for “listeners” if configured. Otherwise, it will use the value

returned from java.net.InetAddress.getCanonicalHostName().

advertised.listeners=PLAINTEXT://hadoop102:9092

A comma separated list of directories under which to store log files

log.dirs=/opt/module/kafka2/data

  1. 5. 分发kafka2
  2. ```shell
  3. [qtbhy@hadoop102 module]$ xsync kafka2
  1. hadoop103,hadoop104上修改node.id分别为3,4
  2. hadoop103,hadoop104上修改advertised.Listeners
  3. 初始化集群数据目录

    1. 生成存储目录唯一ID

      1. [qtbhy@hadoop102 kafka2]$ bin/kafka-storage.sh random-uuid
      2. z-CJvwWeSw6aP0GALadNxA
    2. 用该uuid格式化kafka存储目录

      1. [qtbhy@hadoop102 kafka2]$ bin/kafka-storage.sh format -t z-CJvwWeSw6aP0GALadNxA -c /opt/module/kafka2/config/kraft/server.properties
      2. [qtbhy@hadoop103 kafka2]$ bin/kafka-storage.sh format -t z-CJvwWeSw6aP0GALadNxA -c /opt/module/kafka2/config/kraft/server.properties
      3. [qtbhy@hadoop104 kafka2]$ bin/kafka-storage.sh format -t z-CJvwWeSw6aP0GALadNxA -c /opt/module/kafka2/config/kraft/server.properties
    3. 启动kafka集群

      1. [qtbhy@hadoop102 kafka2]$ bin/kafka-server-start.sh -daemon config/kraft/server.properties
      2. [qtbhy@hadoop103 kafka2]$ bin/kafka-server-start.sh -daemon config/kraft/server.properties
      3. [qtbhy@hadoop104 kafka2]$ bin/kafka-server-start.sh -daemon config/kraft/server.properties