赞
踩
一、环境准备
二、DataX安装
DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL、SQL Server、Oracle、PostgreSQL、HDFS、Hive、HBase、OTS、ODPS 等各种异构数据源之间高效的数据同步功能。
DataX本身作为数据同步框架,将不同数据源的同步抽象为从源头数据源读取数据的Reader插件,以及向目标端写入数据的Writer插件,理论上DataX框架可以支持任意数据源类型的数据同步工作。同时DataX插件体系作为一套生态系统, 每接入一套新数据源该新加入的数据源即可实现和现有的数据源互通。
1、基础环境:Linux、JDK8以上、Python2或者python3、maven3.6以上
2、下载Datax源码,Datax源码位置
3、clone下载Datax源码
4、通过maven进行打包
5、打包成功后,日志显示:
打包成功后,位置:
6、上传datax.tar.gz到服务器,并进行解压:
解压:tar -zxvf datax.tar.gz
7、进入datax下面的bin目录下,编写stream2stream.json:
- #stream2stream.json
- {
- "job": {
- "content": [
- {
- "reader": {
- "name": "streamreader",
- "parameter": {
- "sliceRecordCount": 10,
- "column": [
- {
- "type": "long",
- "value": "10"
- },
- {
- "type": "string",
- "value": "hello,你好,世界-DataX"
- }
- ]
- }
- },
- "writer": {
- "name": "streamwriter",
- "parameter": {
- "encoding": "UTF-8",
- "print": true
- }
- }
- }
- ],
- "setting": {
- "speed": {
- "channel": 5
- }
- }
- }
- }
启动datax,在bin目录下,执行python3 datax.py ./stream2stream.json,会报错:
错误原因是缺少plugin.json,将源码中的plugin.json文件上传到服务器指定位置中,
上传成功后,进入到datax下面的bin目录下,再次执行python3 datax.py ./stream2stream.json
执行成功后:
8、在job目录下,编辑job.json:
- {
- "job": {
- "setting": {
- "speed": {
- "channel": 5,
- "byte": 1048576
- },
- "errorLimit": {
- "record": 0,
- "percentage": 0.02
- }
- },
- "content": [
- {
- "reader": {
- "name": "mysqlreader",
- "parameter": {
- "username": "root",
- "password": "P@ssw0rd!2",
- "column": [
- "`id`",
- "`client_id`",
- "`client_secret`",
- "`scope`",
- "`authorized_grant_types`",
- "`web_server_redirect_uri`",
- "`access_token_validity`",
- "`refresh_token_validity`",
- "`create_user`",
- "`create_dept`",
- "`create_time`",
- "`update_user`",
- "`update_time`",
- "`status`",
- "`is_deleted`"
- ],
- "splitPk": "",
- "connection": [
- {
- "table": [
- "blade_client"
- ],
- "jdbcUrl": [
- "jdbc:mysql://ip:3306/test1?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true"
- ]
- }
- ]
- }
- },
- "writer": {
- "name": "postgresqlwriter",
- "parameter": {
- "username": "postgres",
- "password": "P@ssw0rd!",
- "column": [
- "\"id\"",
- "\"client_id\"",
- "\"client_secret\"",
- "\"scope\"",
- "\"authorized_grant_types\"",
- "\"web_server_redirect_uri\"",
- "\"access_token_validity\"",
- "\"refresh_token_validity\"",
- "\"create_user\"",
- "\"create_dept\"",
- "\"create_time\"",
- "\"update_user\"",
- "\"update_time\"",
- "\"status\"",
- "\"is_deleted\""
- ],
- "connection": [
- {
- "table": [
- "public.blade_client"
- ],
- "jdbcUrl": "jdbc:postgresql://ip:5432/test2"
- }
- ]
- }
- }
- }
- ]
- }
- }
9.在bin目录下执行:python3 datax.py ../job/job.json,出现错误提示:
处理bps错误问题,进入conf文件夹下,修改core.json:
将byte:-1修改为byte:2000000,保存,重新执行文件即可。
执行结果:
总结:datax安装会有或多或少的一些小问题,针对问题解决问题就可以。再次感谢datax开源组织的劳动成果。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。