datax的工具包可以根据github地址上开源的代码进行下载编译,下载后需要maven等环境。推荐直接下载开源的工具包,开箱即用。
http://datax-opensource.oss-cn-hangzhou.aliyuncs.com/datax.tar.gz
解压到/usr/local/datax
编写json需要注意对应的reader和writer有相对应的需要字段。我这里需要的是sqlserverreader和clickhousewriter,配置好对应的字段好库表、账号密码即可。如果有清空表等前置sql,可以填写到preSql字段里面。
{
"job":{
"setting":{
"speed":{
"channel":3
},
"errorLimit":{
"record":0,
"percentage":0.02
}
},
"content":[
{
"reader":{
"name":"sqlserverreader",
"parameter":{
"username":"yaya_yh",
"password":"*******",
"column":[
"Sale_date",
"GMV_amount",
"Picture",
"Shop_id",
"Fashion_code",
"Channel_id",
"Channel_name",
"ETL_TIME",
"Category1",
"Category2",
"url"
],
"connection":[
{
"table":[
"dbo.DM_FASHION_SALE_D"
],
"jdbcUrl":[
"jdbc:sqlserver://rm-bp163rqqg8289090oeo.sqlserver.rds.aliyuncs.com;database=YaYa_BI"
]
}
]
}
},
"writer":{
"name":"clickhousewriter",
"parameter":{
"batchByteSize":134217728,
"batchSize":65536,
"column":[
"Sale_date",
"GMV_amount",
"Picture",
"Shop_id",
"Fashion_code",
"Channel_id",
"Channel_name",
"ETL_TIME",
"Category1",
"Category2",
"url"
],
"connection":[
{
"jdbcUrl":"jdbc:clickhouse://127.0.0.1:8123/YaYa_TEST",
"table":[
"DM_FASHION_SALE_D"
]
}
],
"dryRun":false,
"password":"*******",
"postSql":[
],
"preSql":[
],
"username":"default",
"writeMode":"insert"
}
}
}
]
}
}
需要python环境,一般linux上都是自带python2.7的。没有的话需要额外安装。
./bin/datax_new.py ./job/job.json
运行成功
执行脚本以后没有文件或者目录。
原因是datax.py文件格式不是linux上的python格式,需要处理一下才能运行。
格式转换语句:
cat -v ./bin/datax.py | sed -e '1,$s/\^M$//g' > ./bin/datax_new.py