Confluent

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索

Confluent是一家公司,同时也是该公司Apache Kafka产品线的产品名。

简介

Confluent是Apache Kafka发明人出来开的公司,也是目前最知名的Kafka商业支援服务。同时Confluent也是该公司推出的软件品牌,提供了众多的Open Source套件用以管理Kafka Cluster(即社群版本元件),另外提供商用版本,包括Control Center(提供三十天试用)。

硬件

在PoC时我使用了三台t3.small(2 GB RAM,另外手动设定加上512 MB Swap),三台都安装完整的套件并且跑起来,一开始不会有问题,但跑一阵子后会因为内存不足而异常。

建议在正式环境下,ZooKeeper与Kafka分开跑,都使用m5a.large(8 GB RAM)或是更好的机器执行。

安装

当然要先装Java,然后安装社群版本,这边因为官方还没有提供jammy版本(Ubuntu 22.04),这边手动写成focal

wget -qO - https://packages.confluent.io/deb/7.4/archive.key | gpg --dearmor | sudo tee /etc/apt/keyrings/confluent.gpg > /dev/null; echo -e "deb [arch=amd64 signed-by=/etc/apt/keyrings/confluent.gpg] https://packages.confluent.io/deb/7.4 stable main\ndeb [signed-by=/etc/apt/keyrings/confluent.gpg] https://packages.confluent.io/clients/deb focal main" | sudo tee /etc/apt/sources.list.d/confluent.list; sudo apt update; sudo apt install -y confluent-community-2.13 default-jre; sudo apt clean

ZooKeeper模式或是KRaft模式

现在这个时间点比较尴尬,得看需求背景取舍。很粗略的来说,如果你是既有的应用要使用Kafka,用ZooKeeper模式会比较保险;如果你是自己开发的软件要使用Kafka,用KRaft模式有机会减少将来的技术债。

ZooKeeper

ZooKeeper模式比较成熟,软件的问题会比较少,但官方已经宣布有计划要淘汰掉ZooKeeper模式了。

KRaft

KRaft模式是官方要取代ZooKeeper模式所提出的方案,但目前还有很多限制与问题。

基本操作

依照模式的不同会有不同的参数设定:

  • ZooKeeper模式的操作会有指定任何一台ZooKeeper服务,像是--zookeeper lb-zookeeper.example.com这样的参数。
  • KRaft模式的操作则是指定任何一台Broker服务,像是--bootstrap-server lb-broker.example.com这样的参数。

topic

topic的操作都是透过kafka-topics处理,使用--zookeeper指定ZooKeeper位置(可省略Port资讯,预设使用2181)。

建立是--create

kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --create --topic test --replication-factor 3 --partitions 2

观看是透过--list(简易)或是--describe(详细):

kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --list
kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --describe

删除topic则是透过--delete

kafka-topics --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --delete --topic test

预设值只会标记(MarkedForDeletion),而非实际删除:

Topic test is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.

讯息

把目前的日期资讯传到test里:

date | kafka-console-producer --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --topic test

接收讯息,并且从头开始收(--from-beginning):

kafka-console-consumer --zookeeper internal-test-kafka-zookeeper-lb-123456789.ap-southeast-1.elb.amazonaws.com --topic test --from-beginning

新版的会使用Broker的点而非ZooKeeper的点,这时候会使用--bootstrap_server加上Broker的位置,而非--zookeeper加上ZooKeeper的位置,像是这样:

kafka-console-consumer --bootstrap_server internal-test-kafka-broker-lb-123456789.ap-southeast-1.elb.amazonaws.com:9092 --topic test --from-beginning

额外设定Schema Registry

修改/etc/schema-registry/schema-registry.properties

kafkastore.bootstrap.servers=PLAINTEXT://kafka-broker.srv.example.net:9092
metadata.encoder.secret=x
host.name=kafka-mishmash-1.private.example.net

启动Schema Registry:

sudo systemctl enable --now confluent-schema-registry
sudo service confluent-schema-registry status

设定其他套件

启动Kafka Connect:

sudo service confluent-kafka-connect start
sudo service confluent-kafka-connect status

启动Kafka REST Proxy:

sudo service confluent-kafka-rest start
sudo service confluent-kafka-rest status

启动KSQL:

sudo service confluent-ksql start
sudo service confluent-ksql status

相关连结

外部链接