Kettle 是一款基于Java開(kāi)發(fā)的開(kāi)源(Apache許可)的ETL工具,因其友好的許可来涨、可視化的設(shè)計(jì)器、可擴(kuò)展的插件機(jī)制,而被廣泛使用
Elasticsearch是一款基于Apache Lucene 開(kāi)發(fā)的開(kāi)源(混合型許可Apache許可+ Elastic License)的搜索服務(wù)+存儲(chǔ)引擎扇调,對(duì)文本型大數(shù)據(jù)量的搜索的亮眼性能而被廣泛使用
使用版本:
ElasticSearch 6.6.2+xpack 6.6.2(定制版)
Kettle 8.3.0.1 + Elasticsearch bulk insert (版本適配)
DB:mysql 5.6+
為什么選擇Kettle
可視:代碼不僅僅只是是用來(lái)執(zhí)行的,還必須考慮可維護(hù)性抢肛,看著一坨一坨的代碼狼钮,即使跑的很正常、注釋寫(xiě)的再好捡絮,也不一定有人耐下心看熬芜,Kettle插件的天生模塊化,把關(guān)注點(diǎn)進(jìn)行了很好的分離
統(tǒng)一:所有人福稳、所有實(shí)現(xiàn)是一致的涎拉,便于知識(shí)沉淀、便于知識(shí)的流淌
功能實(shí)現(xiàn)
① 創(chuàng)建ES Mapping【可選】
Tips:使用手工創(chuàng)建Mapping的圆,能夠更好的兼容實(shí)際的數(shù)據(jù)鼓拧、定制分詞引擎或通過(guò)指定Keyword等來(lái)降低不必要的索引存儲(chǔ),Elasticsearch bulk insert
可以根據(jù)index名稱進(jìn)行檢測(cè)越妈,如果指定的名稱不存在季俩,則會(huì)創(chuàng)建Index
put http://es-ip:9200/zqcust-ges-party-test
{
"settings": {
"index": {
"number_of_shards": "5",
"number_of_replicas": "1"
}
},
"mappings": {
"doc": {
"properties": {
"RegistCapi": {
"type": "text"
},
"Status": {
"type": "keyword", "null_value": "NULL"
},
"BelongOrg": {
"type": "text"
},
"CreditCode": {
"type": "text"
},
"No": {
"type": "text"
},
"OperName": {
"type": "text"
},
"Address": {
"type": "text"
},
"EconKind": {
"type": "text"
},
"RegistCapiUnit": {
"type": "text"
},
"Province": {
"type": "text"
},
"TermStart": {
"type": "date"
},
"StartDate": {
"type": "date"
},
"TeamEnd": {
"type": "date"
},
"Scope": {
"type": "text","analyzer": "ik_max_word"
},
"company_name": {
"type": "text"
},
"PhoneNumber": {
"type": "text"
},
"CheckDate": {
"type": "date"
},
"ProvinceCode": {
"type": "text"
}
}
}
}
}
② 源數(shù)據(jù)獲取
文檔使用“Table input”通過(guò)JDBC從數(shù)據(jù)庫(kù)獲取源數(shù)據(jù)(Kettle支持幾乎能想到的所有數(shù)據(jù)源類(lèi)型)
需加載的數(shù)據(jù)表:
來(lái)?xiàng)l數(shù)據(jù)預(yù)覽:
③ 字段類(lèi)型處理
通過(guò)設(shè)置字段類(lèi)型可以減少因類(lèi)型轉(zhuǎn)換而導(dǎo)致的異常
④ Elasticsearch bulk insert配置
配置index相關(guān)信息,如果指定的index不存在梅掠,則會(huì)新建:
字段映射:
配置ES服務(wù)信息:
配置cluster.name:
使用證書(shū)驗(yàn)證的配置:
性能調(diào)整
JDBC性能參數(shù)
fetchSize 參數(shù)調(diào)整酌住,參數(shù)效用參考附錄
對(duì)于大批量的數(shù)據(jù)讀店归,使用fetchSize、defaultRowPrefetch 會(huì)帶來(lái)比較好的性能赂韵,關(guān)于參數(shù)詳細(xì)說(shuō)明娱节,可參考附錄內(nèi)容。
ES批量插入?yún)?shù)
使用Kettle本身的線程配置機(jī)制祭示,右鍵修改插件運(yùn)行線程數(shù):
運(yùn)行
直接在Spoon中運(yùn)行
在Spoon的GUI窗口直接執(zhí)行肄满,一般在開(kāi)發(fā)階段
命令行執(zhí)行
在Linux上將命令存為.sh文件,并設(shè)置文件可執(zhí)行:
/soft/data-integration-8.3.0.1/pan.sh -file="/soft/kettle_run_file/zq-ges-party-oracle-to-es.ktr" -level=Minimal >> /soft/kettle_run_file/run_to_es.log
在windows將命令存亡.cmd文件质涛,執(zhí)行文件:
C:\data-integration-8.3.0.1\data-integration\Pan.bat /file:C:\kettle_App\zq-ges-party-oracle-to-es.ktr >> C:\kettle_App\log.txt
使用Pentaho Server執(zhí)行
將Transformations(轉(zhuǎn)換)發(fā)布到Pentaho Server上執(zhí)行
其他事項(xiàng)
依賴包放到Kettle的classpath下
將依賴的數(shù)據(jù)庫(kù)驅(qū)動(dòng)放置 ${Kettle_home}/lib目錄下稠歉,重啟Kettle加載
Kettle本地版本編譯
從github下載源碼進(jìn)行本地編譯,注意 Maven的遠(yuǎn)程倉(cāng)庫(kù)一定要參考官方的 setting.xml進(jìn)行配置:
官方提供地址:https://raw.githubusercontent.com/pentaho/maven-parent-poms/master/maven-support-files/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!--本地倉(cāng)庫(kù)地址-->
<localRepository>D:\dev_tools\maven-repository</localRepository>
<!-- This is the recommended settings.xml for development of Hitachi Vantara projects. -->
<!--
If your wish to mirror everything through pentaho-public's repo uncomment bellow. Not recommended for external developers.
-->
<!--
<mirrors>
<mirror>
<id>pentaho-public</id>
<url>http://nexus.pentaho.org/content/groups/omni</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
-->
<!--
You might want to tweak the 'updatePolicy' configuration to fit your need on having updated snapshots and releases. Our recommendation is to set it to 'never' and run maven with the '-U' flag when needed.
-->
<profiles>
<profile>
<id>pentaho</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>pentaho-public</id>
<name>Pentaho Public</name>
<url>http://nexus.pentaho.org/content/groups/omni</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>pentaho-public</id>
<name>Pentaho Public</name>
<url>http://nexus.pentaho.org/content/groups/omni</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- this lets you call plugins from these groups in their short form -->
<pluginGroups>
<pluginGroup>org.pentaho.maven.plugins</pluginGroup>
<pluginGroup>com.pentaho.maven.plugins</pluginGroup>
<pluginGroup>com.github.spotbugs</pluginGroup>
</pluginGroups>
</settings>
執(zhí)行構(gòu)建:
mvn clean install -DskipTests
插件依賴的ES版本調(diào)整
因Kettle默認(rèn)版本所使用的ES客戶端版本為 6.6.2并不支持xpack-transport的連接汇陆,需要對(duì)依賴庫(kù)進(jìn)行添加:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>x-pack-transport</artifactId>
<version>6.6.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>x-pack-core</artifactId>
<version>6.6.2</version>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>4.0.8</version>
</dependency>
將原代碼中使用的TransportClient進(jìn)行替換:
ElasticSearchBulk.java的481行:
//PreBuiltTransportClient tClient = new PreBuiltTransportClient( settingsBuilder.build() );
PreBuiltXPackTransportClient tClient = new PreBuiltXPackTransportClient( settingsBuilder.build() );
ElasticSearchBulkDialog.java的907行:
try ( PreBuiltXPackTransportClient client = new PreBuiltXPackTransportClient( settingsBuilder.build() ) ){
……
}
注意:不同版本的插件有可能會(huì)有差異怒炸,當(dāng)前使用的是8.3.0.1源碼;
插件的遠(yuǎn)程調(diào)試
首先配置啟動(dòng)參數(shù)毡代,使用遠(yuǎn)程調(diào)試阅羹,將參數(shù)添加到 spoon.sh或spoon.bat中:
"-Xdebug" "-Xnoagent" "-Djava.compiler=NONE" "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8080"
在Eclipse中配置遠(yuǎn)程調(diào)試:
打上斷點(diǎn),可以進(jìn)行代碼調(diào)試了
附錄:
JDBC fetchsize 參數(shù)說(shuō)明:https://blog.csdn.net/bisal/article/details/82735614
JDBC fetchsize 對(duì)比:http://makejavafaster.blogspot.com/2015/06/jdbc-fetch-size-performance.html
Kettle插件開(kāi)發(fā)說(shuō)明:https://help.pentaho.com/Documentation/8.2/Developer_Center/PDI/Extend
阿里巴巴 數(shù)據(jù)遷移中間件: https://github.com/alibaba/canal