KAFKA CONNECT 使用说明

一、概述

kafka connect 是一个可扩展的、可靠的在kafka和其他系统之间流传输的数据工具。简而言之就是他可以通过Connector(连接器)简单、快速的将大集合数据导入和导出kafka。可以接收整个数据库或收集来自所有的应用程序的消息到kafka的topic中,kafka connect 功能包括:

1,kafka连接器通用框架:kafka connect 规范了kafka和其他数据系统集成,简化了开发、部署和管理。

2,分布式和单机式:扩展到大型支持整个organization的集中管理服务,也可以缩小到开发,测试和小规模生产部署。

3,REST接口:通过rest API 来提交(和管理)Connector到kafka connect 集群。

4,offset自动化管理:从Connector 获取少量信息,connect来管理offset提交。

5,分布式和默认扩展:kafka connect建立在现有的组管理协议上,更多的工作可以添加扩展到connect集群。

6,流/批量集成:利用kafka现有能力,connect是一个桥接流和批量数据系统的理想解决方案。

在这里我们测试connect的kafka版本是:0.9.0.0

二,单机模式

单机模式的命令格式如下:

bin/connect-standalone.sh config/connect-standalone.properties Connector1.properties [Connector2.properties ...]

现在就上述文件我的配

1,connect-standalone.sh 是执行单机模式的命令。

#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. base_dir=$(dirname $) if [ "x$KAFKA_LOG4J_OPTS" = "x" ]; then
export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:$base_dir/../config/connect-log4j.properties"
fi
if [ -z "$KAFKA_HEAP_OPTS" ]; then
export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9901 "
fi
if [ -z "$KAFKA_HEAP_OPTS" ]; then
export KAFKA_HEAP_OPTS="-Xmx1024M"
fi
exec $(dirname $)/kafka-run-class.sh org.apache.kafka.connect.cli.ConnectStandalone "$@"

在这里可以设置给connect的虚拟机内存设置:

if [ -z "$KAFKA_HEAP_OPTS" ]; then
export KAFKA_HEAP_OPTS="-Xmx1024M"
fi 也可以设置JMS配置:
if [ -z "$KAFKA_HEAP_OPTS" ]; then
export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9901 "
fi 2,connect-standalone.properties的配置:
 
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. # These are defaults. This file just demonstrates how to override some settings.
bootstrap.servers=10.253.129.237:,10.253.129.238:,10.253.129.239: # The converters specify the format of data in Kafka and how to translate it into Connect data. Every Connect user will
# need to configure these based on the format they want their data in when loaded from or stored into Kafka
key.converter=org.apache.kafka.connect.json.JsonConverter
value.converter=org.apache.kafka.connect.json.JsonConverter
# Converter-specific settings can be passed in by prefixing the Converter's setting with the converter we want to apply
# it to
key.converter.schemas.enable=true
value.converter.schemas.enable=true # The internal converter used for offsets and config data is configurable and must be specified, but most users will
# always want to use the built-in default. Offset and config data is never visible outside of Copcyat in this format.
internal.key.converter=org.apache.kafka.connect.json.JsonConverter
internal.value.converter=org.apache.kafka.connect.json.JsonConverter
internal.key.converter.schemas.enable=false
internal.value.converter.schemas.enable=false offset.storage.file.filename=/datafs//connect.offsets
# Flush much faster than normal, which is useful for testing/debugging
offset.flush.interval.ms=


这里需要注意broker的配置,其余配置在kafka官网都有说明参考:

http://kafka.apache.org/090/documentation.html#connectconfigs

3,connect-file-source.properties的配置

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. name=test_source2
connector.class=FileStreamSource
tasks.max=
file=/datafs//json2/log.out
topic=TEST_MANAGER5

注意路径和topic的配置

4,connect-file-sink.properties 的配置:

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. name=test_sink1
connector.class=FileStreamSink
#connector.class=org.apache.kafka.connect.file.FileStreamSinkConnector
tasks.max=
file=/datafs//a.out
topics=TEST_MANAGER5

三,集群模式

命令格式:

bin/connect-distributed.sh config/connect-distributed.properties
在不同的类中,配置参数定义了 Kafka Connect 如何处理,哪里存储配置,如何分配 work,哪里存储 offset 和任务状态。在分布式模式中,Kafka Connect topic 中存储 offset,配置和任务状态。建议手动创建 offsettopic,可以自己来定义需要的分区数和副本数。如果启动 Kafka Connect 时还没有创建 topic,那么 topic 将自动创建(使用默认的分区和副本),这可能不是最合适的(因为 Kafka 可不知道业务需要,只能根据默认参数创建)。特别是以下配置参数尤为关键,启动集群之前设置:
group.id (默认 connect-cluster):Connect cluster group 使用唯一的名称;注意这不能和 consumer group ID(消费者组)冲突。
config.storage.topic (默认 connect-configs):topic 用于存储 Connector 和任务配置;注意,这应该是一个单个的 partition,多副本的 topic。你需要手动创建这个 topic,以确保是单个 partition(自动创建的可能会有多个partition)。
offset.storage.topic (默认 connect-offsets) :topic 用于存储 offsets;这个topic应该配置多个 partition 和副本。
status.storage.topic (默认 connect-status):topic 用于存储状态;这个 topic 可以有多个 partitions 和副本
注意,在分布式模式中,Connector(连接器)配置不能使用命令行。要使用下面介绍的 REST API 来创建,修改和销毁 Connector

{"name":"test","config":{"topic":"TEST_MANAGER","connector.class":"FileStreamSource","tasks.max":"2","file":"/datafs/log1.out"}}

四,REST API

由于 Kafka Connect 的目的是作为一个服务运行,提供了一个用于管理 ConnectorREST API。默认情况下,此服务的端口是8083。以下是当前支持的终端入口:
GET /Connectors:返回活跃的 Connector 列表
POST /Connectors:创建一个新的 Connector;请求的主体是一个包含字符串name字段和对象 config 字段(Connector 的配置参数)的 JSON 对象。
GET /Connectors/{name}:获取指定 Connector 的信息
GET /Connectors/{name}/config:获取指定 Connector 的配置参数
PUT /Connectors/{name}/config:更新指定 Connector 的配置参数
GET /Connectors/{name}/status:获取 Connector 的当前状态,包括它是否正在运行,失败,暂停等。
GET /Connectors/{name}/tasks:获取当前正在运行的 Connector 的任务列表。
GET /Connectors/{name}/tasks/{taskid}/status:获取任务的当前状态,包括是否是运行中的,失败的,暂停的等,
PUT /Connectors/{name}/pause:暂停连接器和它的任务,停止消息处理,直到 Connector 恢复。
PUT /Connectors/{name}/resume:恢复暂停的 Connector(如果 Connector 没有暂停,则什么都不做)
POST /Connectors/{name}/restart:重启 ConnectorConnector 已故障)
POST /Connectors/{name}/tasks/{taskId}/restart:重启单个任务 (通常这个任务已失败)

DELETE /Connectors/{name}:删除 Connector, 停止所有的任务并删除其配置

Kafka Connector 还提供了获取有关 Connector plugins 信息的 REST API
GET /Connector-plugins:返回已在 Kafka Connect 集群安装的 Connector plugin 列表。请注意,API 仅验证处理请求的 worker  Connector。这以为着你可能看不不一致的结果,特别是在滚动升级的时候(添加新的 Connector jar
PUT /Connector-plugins/{Connector-type}/config/validate :对提供的配置值进行验证,执行对每个配置验证,返回验证的建议值和错误信息

kafka connect 使用说明的更多相关文章

  1. Kafka Connect使用入门-Mysql数据导入到ElasticSearch

    1.Kafka Connect Connect是Kafka的一部分,它为在Kafka和外部存储系统之间移动数据提供了一种可靠且伸缩的方式,它为连接器插件提供了一组API和一个运行时-Connect负责 ...

  2. Streaming data from Oracle using Oracle GoldenGate and Kafka Connect

    This is a guest blog from Robin Moffatt. Robin Moffatt is Head of R&D (Europe) at Rittman Mead, ...

  3. Build an ETL Pipeline With Kafka Connect via JDBC Connectors

    This article is an in-depth tutorial for using Kafka to move data from PostgreSQL to Hadoop HDFS via ...

  4. Kafka connect快速构建数据ETL通道

    摘要: 作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 业余时间调研了一下Kafka connect的配置和使用,记录一些自己的理解和心得,欢迎 ...

  5. 使用kafka connect,将数据批量写到hdfs完整过程

    版权声明:本文为博主原创文章,未经博主允许不得转载 本文是基于hadoop 2.7.1,以及kafka 0.11.0.0.kafka-connect是以单节点模式运行,即standalone. 首先, ...

  6. 基于Kafka Connect框架DataPipeline可以更好地解决哪些企业数据集成难题?

    DataPipeline已经完成了很多优化和提升工作,可以很好地解决当前企业数据集成面临的很多核心难题. 1. 任务的独立性与全局性. 从Kafka设计之初,就遵从从源端到目的的解耦性.下游可以有很多 ...

  7. 基于Kafka Connect框架DataPipeline在实时数据集成上做了哪些提升?

    在不断满足当前企业客户数据集成需求的同时,DataPipeline也基于Kafka Connect 框架做了很多非常重要的提升. 1. 系统架构层面. DataPipeline引入DataPipeli ...

  8. 以Kafka Connect作为实时数据集成平台的基础架构有什么优势?

    Kafka Connect是一种用于在Kafka和其他系统之间可扩展的.可靠的流式传输数据的工具,可以更快捷和简单地将大量数据集合移入和移出Kafka的连接器.Kafka Connect为DataPi ...

  9. 打造实时数据集成平台——DataPipeline基于Kafka Connect的应用实践

    导读:传统ETL方案让企业难以承受数据集成之重,基于Kafka Connect构建的新型实时数据集成平台被寄予厚望. 在4月21日的Kafka Beijing Meetup第四场活动上,DataPip ...

随机推荐

  1. 最全面的Redis命令行查阅手册(收藏查看)

    Redis是用C语言实现的,一般来说C语言实现的程序“距离”操作系统更近,执行速度相对会更快. Redis使用了单线程架构,预防了多线程可能产生的竞争问题. 作者对于Redis源代码可以说是精打细磨, ...

  2. Selenium常用API详解介绍

    转至元数据结尾   由 黄从建创建, 最后修改于一月 21, 2019 转至元数据起始   一.selenium元素定位 1.selenium定位方法 2.定位方法的用法 二.控制浏览器操作 1.控制 ...

  3. 启动fiddler导致浏览器无法上网的解决方法

    1. 开发fiddler,进入Tools->Fiddler Tools,按照如图3部配置,即可实现无法上网的问题. 2. 见图1: 3.见图2: 4.见图3. 4. 完成以上配置后,重启fidd ...

  4. Html.Raw用法

    比如有个字符串是这样的<font color='red'>红字</font> 如果是用@Html.Raw('<font color='red'>红字</fon ...

  5. zsh 缺省输入设置

    zsh 默认缺省方式和bash不兼容,终端输入指令带有* 并不能对所有以已经输入的部分作为开头的文件作处理,解决这个问题的方式是在.zshrc文件中加入 setopt no_match 即可

  6. 【转】反编译D-Link路由器固件程序并发现后门

    固件是D-link无线路由器(型号:DIR-100 revA)的固件程序 v1.13.使用工具Binwalk,很快的就从中发现并提取出一个只读SquashFS文件系统,没用多大功夫我就将这个固件程序的 ...

  7. iftop流量监控工具

    下载iftop工具的源码包 # wget http:oss.aliyuncs.com/aliyunecs/iftop-0.17.tar.gz 安装所需的依赖包 # yum -y install gcc ...

  8. golang channel

    ex1 package main /* goroutine 是由GO运行时管理的轻量级线程 go f(x,y, z) 就启动了一个goroutine, 其中f,x,y,z在当前goroutine中立即 ...

  9. DPDK - gsg文档(介绍与编译)

    && Hugepage 提前分配hugepage内存,可以减少虚拟页地址转换到物理地址所需的时间. 相关命令: 在虚拟机上运行时,在没有NUMA的机器上,执行“echo 1024 &g ...

  10. hyperscan应用参数

    >>hs_compile_ext_multi 使用额外的参数编译表达式, 额外的参数包括: MIN_OFFSET 距离开始的最小偏移开始匹配 MAX_OFFSET 距离开始的最大偏移结束匹 ...