Debezium:kafka 连接器配置

9 篇文章 2 订阅
8 篇文章 2 订阅

目的:构建基于hbase的实时数仓

解决的问题:RDBMS到Hbase的数据实时采集

方法:Postgresql    ----->     Debezium     ----->     Kafka     ------>     Sparkstreaming    ------>     Phoenix

本文:本文主要是kafka连接器一些相关配置

官网参考地址:

Debezium:https://debezium.io/docs/connectors/postgresql/

Kafka:Apache Kafka


kafka提供两种连接器:(例子为通过debezium连接postgresql)

一、connect-standalone.sh:用于测试开发

  1. 命令:./connect-standalone.sh /opt/cloudera/parcels/KAFKA/etc/kafka/conf.dist/connect-standalone.properties /opt/cloudera/parcels/KAFKA/etc/kafka/conf.dist/postgres.properties
  2. standalone模式需要配置两个参数:

    第一个是系统配置文件connect-standalone.properties,修改:bootstrap.servers=10.0.10.94:9092 (默认为localhost)

    第二个是连接配置文件postgres.properties,配置connector:

    name=test-connector

    slot.name=debezium

    connector.class=io.debezium.connector.postgresql.PostgresConnector

    database.hostname=10.0.10.76

    database.port=5432

    database.user=postgres

    database.password=postgres

    database.dbname=test

    database.history.kafka.bootstrap.servers=localhost:9092

    database.server.name=test

    table.whitelist=public.test2

    plugin.name=wal2json

二、connect-distributed.sh:用于正式环境线上

  1. 命令:./connect-distributed.sh /opt/cloudera/parcels/KAFKA/etc/kafka/conf.dist/connect-distributed.properties如上,distributed模式不提供连接配置,connector需要后续以API形式倒入
  2. 配置文件connect-distributed.properties需要同样修改:bootstrap.servers=10.0.10.94:9092
  3. distributed模式需要创建topic来存放一些连接信息

    config.storage.topic=connect-configs 保存connector配置信息

    ./kafka-topics.sh --create --zookeeper localhost:2181 --topic connect-configs --replication-factor 3 --partitions 1

    offset.storage.topic=connect-offsets 保存offset信息

    ./kafka-topics.sh --create --zookeeper localhost:2181 --topic connect-offsets --replication-factor 3 --partitions 50

    status.storage.topic=connect-status 保存connector状态信息

    ./kafka-topics.sh --create --zookeeper localhost:2181 --topic connect-status --replication-factor 3 --partitions 10

  4. distributed模式常用API:

    GET /connectors – return a list of active connectors 返回活跃的connectors

    POST /connectors –  create a new connector; the request body should be a JSON object containing a string name field and an object config field with the connector configuration parameters  创建一个新的connector

    GET /connectors/{name} – get information about a specific connector 获取指定connetor的信息

    GET /connectors/{name}/config – get the configuration parameters for a specific connector 获取指定connector的配置信息

    PUT /connectors/{name}/config – update the configuration parameters for a specific connector 更新指定connector的配置信息

    GET /connectors/{name}/status – get current status of the connector, including if it is running, failed, paused, etc., which worker it is assigned to, error information if it has failed, and the state of all its tasks 获取指定connector状态

    GET /connectors/{name}/tasks – get a list of tasks currently running for a connector 获取指定connector正在运行的task

    GET /connectors/{name}/tasks/{taskid}/status – get current status of the task, including if it is running, failed, paused, etc., which worker it is assigned to, and error information if it has failed 获取指定connector的task状态信息

    PUT /connectors/{name}/pause – pause the connector and its tasks, which stops message processing until the connector is resumed 暂停connector和它的task

    PUT /connectors/{name}/resume –  resume a paused connector (or do nothing if the connector is not paused) 恢复一个被暂停的connector

    POST /connectors/{name}/restart – restart a connector (typically because it has failed) 重启一个connector 

    POST /connectors/{name}/tasks/{taskId}/restart –  restart an individual task (typically because it has failed) 重启一个task

    DELETE /connectors/{name} –  delete a connector, halting all tasks and deleting its configuration 删除一个connector

  5. 例子

    新建一个connector:

    curl 'http://localhost:8083/connectors' -X POST -i -H "Content-Type:application/json" -d '{

    "name": "test-connector",

    "config": {

    "connector.class": "io.debezium.connector.postgresql.PostgresConnector",

    "database.hostname": "10.0.10.76",

    "database.port": "5432",

    "database.user": "postgres",

    "database.password": "postgres",

    "database.dbname" : "test",

    "database.history.kafka.bootstrap.servers":"localhost:9092",

    "database.server.name": "test",

    "table.whitelist": "public.test2",

    "plugin.name":"wal2json" 

    }

    }'

    获取connector:

    curl -X GET 'http://localhost:8083/connectors'

    重启connector:

    curl -X POST 'http://localhost:8083/connectors/test-connector/restart'                 

    更新connector配置:

    curl -X PUT 'http://localhost:8083/connectors/test-connector/config' -i -H "Content-Type:application/json" -d '

    {

        "connector.class": "io.debezium.connector.postgresql.PostgresConnector",

        "database.hostname": "10.0.10.76",

        "database.port": "5432",

        "database.user": "postgres",

        "database.password": "postgres",

        "database.dbname" : "test",

        "database.history.kafka.bootstrap.servers":"localhost:9092",

        "database.server.name": "test",

        "table.whitelist": "public.test2,public.nt_sale_order_test",

        "decimal.handling.mode": "string",

        "plugin.name":"wal2json"

    }' 

                                                                          

首先,Kafka是一个分布式流处理平台,用于在高吞吐量的情况下处理大量的实时数据流。Hive是一个基于Hadoop的数据仓库工具,用于存储和查询大规模结构化和半结构化数据。 要将Kafka写入Hive,需要使用Debezium它是一个开源的、基于事件的可信变更数据捕获(CDC)平台。Debezium可以将数据库的变更事件转换为Kafka主题中的实时流,并且可以实时监控数据库中的变动。 要实现Kafka写入Hive,首先需要配置Debezium将数据库的变更事件连接到Kafka中。Debezium会以JSON格式将变更事件转换为Kafka消息,并将其写入指定的主题中。 然后,可以使用Kafka Connect来读取Kafka主题中的消息,并将其写入Hive中。Kafka Connect是Kafka提供的一组工具,用于将Kafka主题与外部数据系统进行连接。 在Kafka Connect中,可以使用HDFS Connector来将Kafka消息写入Hive。HDFS Connector会将Kafka消息转换为Hive支持的格式,并将其写入Hive表中。 需要配置HDFS Connector的连接器以指定Kafka主题、Hive表和目标位置。连接器会自动将Kafka消息转换为Hive表的列,并将其写入Hive表中的对应位置。 一旦连接器配置完成并启动,Kafka中的变更事件就会实时地写入Hive表中。可以通过查询Hive表来获取Kafka中的数据,并根据需要进行分析和处理。 总而言之,要将Kafka写入Hive,可以使用Debezium将数据库变更事件转换为Kafka消息,并使用Kafka Connect的HDFS Connector将Kafka消息写入Hive表中。这样就能实现将实时数据流从Kafka写入Hive的目的。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值