--------------- 前言 ---------------
💻系统版本:CentOS Linux release 7.9.2009
🦆Python:Python 2.7.5
☕️Java: openjdk version "1.8.0_352"
📦DataX: https://github.com/alibaba/DataX
🔧DataX-web: https://github.com/WeiYe-Jing/datax-web
--------------- 前言 ---------------
DataX执行需要python环境,使用python -v命令测试,如果没有需要安装
1.安装DataX
DataX的下载地址在github页面的Quick Start下
https://datax-opensource.oss-cn-hangzhou.aliyuncs.com/202210/datax.tar.gz
202210为tag版本,需要视情况自己选择,我这里下载的最新的tag版本
# 系统中执行如下命令开始下载
wget https://datax-opensource.oss-cn-hangzhou.aliyuncs.com/202210/datax.tar.gz
下载完成后需要解压文件,讲datax解压到/usr/local目录下,datax最终地址为/usr/local/datax
tar -zxvf datax.tar.gz -C /usr/local/
进入 /usr/local/datax/bin,开始自检
cd /usr/local/datax/bin
python datax.py ../job/job.json
自检如果正常,将会返回如下结果
[root@XXB bin]# python datax.py ../job/job.json
DataX (DATAX-OPENSOURCE-3.0), From Alibaba !
Copyright (C) 2010-2017, Alibaba Group. All Rights Reserved.
2022-11-30 09:27:30.221 [main] INFO MessageSource - JVM TimeZone: GMT+08:00, Locale: zh_CN
2022-11-30 09:27:30.223 [main] INFO MessageSource - use Locale: zh_CN timeZone: sun.util.calendar.ZoneInfo[id="GMT+08:00",offset=28800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
2022-11-30 09:27:30.249 [main] INFO VMInfo - VMInfo# operatingSystem class => sun.management.OperatingSystemImpl
2022-11-30 09:27:30.254 [main] INFO Engine - the machine info =>
osInfo: Red Hat, Inc. 1.8 25.352-b08
jvmInfo: Linux amd64 3.10.0-1160.76.1.el7.x86_64
cpu num: 4
totalPhysicalMemory: -0.00G
freePhysicalMemory: -0.00G
maxFileDescriptorCount: -1
currentOpenFileDescriptorCount: -1
GC Names [PS MarkSweep, PS Scavenge]
MEMORY_NAME | allocation_size | init_size
PS Eden Space | 256.00MB | 256.00MB
Code Cache | 240.00MB | 2.44MB
Compressed Class Space | 1,024.00MB | 0.00MB
PS Survivor Space | 42.50MB | 42.50MB
PS Old Gen | 683.00MB | 683.00MB
Metaspace | -0.00MB | 0.00MB
2022-11-30 09:27:30.270 [main] INFO Engine -
{
"content":[
{
"reader":{
"name":"streamreader",
"parameter":{
"column":[
{
"type":"string",
"value":"DataX"
},
{
"type":"long",
"value":19890604
},
{
"type":"date",
"value":"1989-06-04 00:00:00"
},
{
"type":"bool",
"value":true
},
{
"type":"bytes",
"value":"test"
}
],
"sliceRecordCount":100000
}
},
"writer":{
"name":"streamwriter",
"parameter":{
"encoding":"UTF-8",
"print":false
}
}
}
],
"setting":{
"errorLimit":{
"percentage":0.02,
"record":0
},
"speed":{
"channel":1
}
}
}
2022-11-30 09:27:30.286 [main] WARN Engine - prioriy set to 0, because NumberFormatException, the value is: null
2022-11-30 09:27:30.287 [main] INFO PerfTrace - PerfTrace traceId=job_-1, isEnable=false, priority=0
2022-11-30 09:27:30.287 [main] INFO JobContainer - DataX jobContainer starts job.
2022-11-30 09:27:30.289 [main] INFO JobContainer - Set jobId = 0
2022-11-30 09:27:30.312 [job-0] INFO JobContainer - jobContainer starts to do prepare ...
2022-11-30 09:27:30.313 [job-0] INFO JobContainer - DataX Reader.Job [streamreader] do prepare work .
2022-11-30 09:27:30.313 [job-0] INFO JobContainer - DataX Writer.Job [streamwriter] do prepare work .
2022-11-30 09:27:30.313 [job-0] INFO JobContainer - jobContainer starts to do split ...
2022-11-30 09:27:30.313 [job-0] INFO JobContainer - Job set Channel-Number to 1 channels.
2022-11-30 09:27:30.313 [job-0] INFO JobContainer - DataX Reader.Job [streamreader] splits to [1] tasks.
2022-11-30 09:27:30.314 [job-0] INFO JobContainer - DataX Writer.Job [streamwriter] splits to [1] tasks.
2022-11-30 09:27:30.329 [job-0] INFO JobContainer - jobContainer starts to do schedule ...
2022-11-30 09:27:30.333 [job-0] INFO JobContainer - Scheduler starts [1] taskGroups.
2022-11-30 09:27:30.334 [job-0] INFO JobContainer - Running by standalone Mode.
2022-11-30 09:27:30.343 [taskGroup-0] INFO TaskGroupContainer - taskGroupId=[0] start [1] channels for [1] tasks.
2022-11-30 09:27:30.351 [taskGroup-0] INFO Channel - Channel set byte_speed_limit to 2000000.
2022-11-30 09:27:30.351 [taskGroup-0] INFO Channel - Channel set record_speed_limit to -1, No tps activated.
2022-11-30 09:27:30.363 [taskGroup-0] INFO TaskGroupContainer - taskGroup[0] taskId[0] attemptCount[1] is started
2022-11-30 09:27:30.965 [taskGroup-0] INFO TaskGroupContainer - taskGroup[0] taskId[0] is successed, used[603]ms
2022-11-30 09:27:30.966 [taskGroup-0] INFO TaskGroupContainer - taskGroup[0] completed it's tasks.
2022-11-30 09:27:40.351 [job-0] INFO StandAloneJobContainerCommunicator - Total 100000 records, 2600000 bytes | Speed 253.91KB/s, 10000 records/s | Error 0 records, 0 bytes | All Task WaitWriterTime 0.052s | All Task WaitReaderTime 0.505s | Percentage 100.00%
2022-11-30 09:27:40.352 [job-0] INFO AbstractScheduler - Scheduler accomplished all tasks.
2022-11-30 09:27:40.353 [job-0] INFO JobContainer - DataX Writer.Job [streamwriter] do post work.
2022-11-30 09:27:40.353 [job-0] INFO JobContainer - DataX Reader.Job [streamreader] do post work.
2022-11-30 09:27:40.353 [job-0] INFO JobContainer - DataX jobId [0] completed successfully.
2022-11-30 09:27:40.354 [job-0] INFO HookInvoker - No hook invoked, because base dir not exists or is a file: /usr/local/datax/hook
2022-11-30 09:27:40.358 [job-0] INFO JobContainer -
[total cpu info] =>
averageCpu | maxDeltaCpu | minDeltaCpu
-1.00% | -1.00% | -1.00%
[total gc info] =>
NAME | totalGCCount | maxDeltaGCCount | minDeltaGCCount | totalGCTime | maxDeltaGCTime | minDeltaGCTime
PS MarkSweep | 0 | 0 | 0 | 0.000s | 0.000s | 0.000s
PS Scavenge | 0 | 0 | 0 | 0.000s | 0.000s | 0.000s
2022-11-30 09:27:40.359 [job-0] INFO JobContainer - PerfTrace not enable!
2022-11-30 09:27:40.360 [job-0] INFO StandAloneJobContainerCommunicator - Total 100000 records, 2600000 bytes | Speed 253.91KB/s, 10000 records/s | Error 0 records, 0 bytes | All Task WaitWriterTime 0.052s | All Task WaitReaderTime 0.505s | Percentage 100.00%
2022-11-30 09:27:40.362 [job-0] INFO JobContainer -
任务启动时刻 : 2022-11-30 09:27:30
任务结束时刻 : 2022-11-30 09:27:40
任务总计耗时 : 10s
任务平均流量 : 253.91KB/s
记录写入速度 : 10000rec/s
读出记录总数 : 100000
读写失败总数 : 0
如果自检失败,需要手动删除
datax/plugin/reader/ 下所有._xxxx(.开头的)隐藏文件
datax/plugin/writer/ 下所有._xxxx(.开头的)隐藏文件
# 分别在两个目录下执行
rm -rf ._*
删除完成后再次执行自检,通过后即可进入DataX-web的安装
2.Datax-web安装
DataX执行需要jdk和jre环境,如果没有需要安装
没有环境的特征是安装后启动报错,日志提示 jps: 未找到命令
解决方法参考如下博文:https://blog.csdn.net/prxhlirr/article/details/126704994
2.1本地拉取DataX-web代码
# 这里直接拉取的master分支最新版,稳妥一点可以获取tag版本
git clone https://github.com/WeiYe-Jing/datax-web.git
2.2 本地IDEA打开代码,并等待maven解析完成
2.3 配置项目
这里可以配置项目的admin和executor模块的端口号,注册地址等
端口号可以自己视情况选择性的配置,但是有个比较重要的配置需要修改
datax-executor模块的application.yml的address配置
# web port
server:
port: ${server.port}
#port: 8081
# log config
logging:
config: classpath:logback.xml
path: ${data.path}/applogs/executor/jobhandler
#path: ./data/applogs/executor/jobhandler
datax:
job:
admin:
### datax admin address list, such as "http://address" or "http://address01,http://address02"
#addresses: http://127.0.0.1:8080
# 这里的ip地址需要改成admin模块运行的ip地址
# 例如我的项目是admin和executor都部署在局域网的ip为192.168.1.193的服务器上
addresses: http://192.168.1.193:${datax.admin.port}
executor:
appname: datax-executor
ip:
#port: 9999
port: ${executor.port:9999}
### job log path
#logpath: ./data/applogs/executor/jobhandler
logpath: ${data.path}/applogs/executor/jobhandler
### job log retention days
logretentiondays: 30
### job, access token
accessToken:
executor:
#jsonpath: D:\\temp\\executor\\json\\
jsonpath: ${json.path}
#pypath: F:\tools\datax\bin\datax.py
pypath: ${python.path}
2.3 选择项目maven结构的根项目,执行maven的install命令
执行install命令后,会在代码目录下生成一个build文件夹,文件夹下会包含一个
datax-web-2.1.2.tar.gz文件,具体的文件名跟所选择的代码版本有关,该文件即为DataX-web的安装包
2.4 将文件发往服务器安装
我将文件放在服务器的/home/路径下
cd /home
# 解压文件
tar -zxvf datax-web-2.1.2.tar.gz
# 安装文件
cd /home/datax-web-2.1.2
# 修改executor的配置
vim /home/datax-web-2.1.2/modules/datax-executor/bin/env.properties
datax-executor -> env.properties
# environment variables
#JAVA_HOME=""
SERVICE_LOG_PATH=${BIN}/../logs
SERVICE_CONF_PATH=${BIN}/../conf
DATA_PATH=${BIN}/../data
## datax json文件存放位置
JSON_PATH=${BIN}/../json
## executor_port
EXECUTOR_PORT=9528
## 保持和datax-admin端口一致
DATAX_ADMIN_PORT=
## PYTHON脚本执行位置
## 这个文件的地址即为datax安装目录下的,我将datax安装在/usr/local/下,
## 地址即为如下配置
PYTHON_PATH=/usr/local/datax/bin/datax.py
## dataxweb 服务端口
SERVER_PORT=9504
#PID_FILE_PATH=${BIN}/service.pid
#debug 远程调试端口
#REMOTE_DEBUG_SWITCH=true
#REMOTE_DEBUG_PORT=7004
2.5执行安装
cd /home/datax-web-2.1.2/bin
# 执行如下命令后,依次输入数据库连接,账号,密码等
# 该配置的数据库为DataX-web系统的数据库,保存任务配置信息等内容
sh install.sh
# 安装完成后,执行如下命令启动全部模块
sh start-all.sh
# 如果想启动一个模块,执行
# sh start-all.sh -m datax-admin
# 关闭命令同理
启动完成后执行如下命令看是否启动成功,下面是启动成功的返回
[root@XXB bin]# ps -ef|grep 9504
root 20980 1 0 11月29 ? 00:01:37 java -Xms2g -Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:HeapDumpPath=/home/datax-web-2.1.2/modules/datax-executor/bin/../logs -Dlog.path=/home/datax-web-2.1.2/modules/datax-executor/bin/../logs -Duser.dir=/home/datax-web-2.1.2/modules/datax-executor/bin/../ -Dserver.port=9504 -Ddata.path=/home/datax-web-2.1.2/modules/datax-executor/bin/../data -Dexecutor.port=9528 -Djson.path=/home/datax-web-2.1.2/modules/datax-executor/bin/../json -Dpython.path=/usr/local/datax/bin/datax.py -Ddatax.admin.port=9527 -Dlogging.config=/home/datax-web-2.1.2/modules/datax-executor/bin/../conf/logback.xml -classpath /home/datax-web-2.1.2/modules/datax-executor/bin/../lib/*:/home/datax-web-2.1.2/modules/datax-executor/bin/../conf:. com.wugui.datax.executor.DataXExecutorApplication
root 30817 23650 0 10:02 pts/1 00:00:00 grep --color=auto 9504
[root@XXB bin]# ps -ef|grep 9527
root 2669 23650 0 10:05 pts/1 00:00:00 grep --color=auto 9527
root 20684 1 0 11月29 ? 00:03:38 java -Xms2g -Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:HeapDumpPath=/home/datax-web-2.1.2/modules/datax-admin/bin/../logs -Dlog.path=/home/datax-web-2.1.2/modules/datax-admin/bin/../logs -Duser.dir=/home/datax-web-2.1.2/modules/datax-admin/bin/../ -Dserver.port=9527 -Ddata.path=/home/datax-web-2.1.2/modules/datax-admin/bin/../data -Dmail.username=datax -Dmail.password=123456 -Dlogging.config=/home/datax-web-2.1.2/modules/datax-admin/bin/../conf/logback.xml -classpath /home/datax-web-2.1.2/modules/datax-admin/bin/../lib/*:/home/datax-web-2.1.2/modules/datax-admin/bin/../conf:. com.wugui.datax.admin.DataXAdminApplication
root 20980 1 0 11月29 ? 00:01:38 java -Xms2g -Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:HeapDumpPath=/home/datax-web-2.1.2/modules/datax-executor/bin/../logs -Dlog.path=/home/datax-web-2.1.2/modules/datax-executor/bin/../logs -Duser.dir=/home/datax-web-2.1.2/modules/datax-executor/bin/../ -Dserver.port=9504 -Ddata.path=/home/datax-web-2.1.2/modules/datax-executor/bin/../data -Dexecutor.port=9528 -Djson.path=/home/datax-web-2.1.2/modules/datax-executor/bin/../json -Dpython.path=/usr/local/datax/bin/datax.py -Ddatax.admin.port=9527 -Dlogging.config=/home/datax-web-2.1.2/modules/datax-executor/bin/../conf/logback.xml -classpath /home/datax-web-2.1.2/modules/datax-executor/bin/../lib/*:/home/datax-web-2.1.2/modules/datax-executor/bin/../conf:. com.wugui.datax.executor.DataXExecutorApplication
如果启动失败,需要查看启动日志,排查原因
cat /home/datax-web-2.1.2/modules/datax-admin/bin/console.out
cat /home/datax-web-2.1.2/modules/datax-executor/bin/console.out
报错无非就是端口冲突或者缺少java开发环境导致的 jps: 未找到命令
2.6 访问admin并配置任务
admin访问地址
# 初始账号密码 admin/123456
http://服务器IP:9527/index.html
查看执行器是否注册成功,执行期管理如果显示如下,在线机器一栏有显示地址,则说明执行器注册成功
|排序|名称|分组标识|注册方式|在线机器|
|-------|-------|-------|-------|-------|
|1|datax执行器|datax-executor|自动注册|171.168.1.193:9528|
依次配置如下项目:
1.配置数据源
2.配置项目
3.DataX任务模版
4.任务构建
任务报错分析
1.数据库为MongoDB,集合文档数据存在为空的,datax-web识别不出该集合字段
目前版本datax-web还是存在该问题,如果datax-web丢字段可以自己手动修改生成的datax的json文件,补齐字段,参考如下issue:
https://github.com/WeiYe-Jing/datax-web/issues/143
2.数据库配置正确,但是连接数据库失败
经测试发现,datax-web在使用mongodb数据库的情况下,生成datax的json文件中会丢失数据库的账号密码等信息,需要自己手动在json中添加,参考如下issue:(原因就是datax-web生成的json丢失数据库信息,自己手动补齐)
https://github.com/WeiYe-Jing/datax-web/issues/300
3.列配置信息有错误. 因为您配置的任务中,源头读取字段数:15 与 目的表要写入的字段数:16 不相等. 请检查您的配置并作出修改.
该bug是因为datax读取不出表中存在空数据的字段。目前datax中已修复,需要使用新版本的datax,老版本参考如下issue:
https://github.com/alibaba/DataX/issues/1017
https://github.com/alibaba/DataX/issues/1101
4.Datax-web连不上mysql,配置正确也报错
datax-web的mysql驱动版本是针对mysql5.0的,如果是mysql8.0需要修改对应的驱动依赖,修改源码的pom.xml或者替换/home/datax-web-2.1.2/modules/datax-admin/lib/下的驱动jar包