1.创建 lib 目录并拷贝 mysql 支持包
2.修改 job.properties 文件
nameNode=hdfs://cen-ubuntu.cenzhongman.com:8020
jobTracker=localhost:8032
queueName=default
oozieAppsRoot=oozie-apps
oozie.use.system.libpath=true
oozie.wf.application.path=${nameNode}/user/cen/${oozieAppsRoot}/sqoop-import/
outputDir=sqoop-import/output
3.修改 workflow.xml 文件
<workflow-app xmlns="uri:oozie:workflow:0.5" name="sqoop-import-wf">
<start to="sqoop-node"/>
<action name="sqoop-node">
<sqoop xmlns="uri:oozie:sqoop-action:0.3">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<prepare>
<delete path="${nameNode}/user/cen/${oozieAppsRoot}/${outputDir}"/>
</prepare>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<command>import --options-file sqoop-import.sql</command>
</sqoop>
<ok to="end"/>
<error to="fail"/>
</action>
<kill name="fail">
<message>Sqoop failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>
注意事项
- workflow 版本0,5 sqoop action 版本0.3
- 使用的是新版本的API,但旧版本依旧支持使用(可以不用改)
- 上文command>支持三种使用 sqoop 方式,下文会说明
- 特别重要的 command> 只支持 “ ”
4.上传文件到HDFS文件系统
5.执行程序
export OOZIE_URL=http://cen-ubuntu:11000/oozie/
bin/oozie job --config /opt/cdh5.3.6/oozie-4.1.0-cdh5.12.0/oozie-apps/sqoop-import/job.properties -run
注:三种命令方式
1.直接执行 sqoop 命令
<command>import --connect jdbc:mysql://cen-ubuntu:3306/mysql --username root --password ubuntu --table user --target-dir /user/cen/oozie-apps/sqoop-import/output --fields-terminated-by " " --num-mappers 1 --direct</command>
<command>import --options-file sqoop-import.sql</command>
# job.properties文件名
EXEC=xxx.sql
# workflow.xml
<!--Copy the executable to compute node's current working directory -->
<file>${nameNode}/user/cen/${oozieAppsRoot}/sqoop-import/${EXEC}#${EXEC}</file>
3.从绝对路径导入
# job.properties
sqoop-import=${nameNode}/user/cen/${oozieAppsRoot}/sqoop-import/sqoop-import
# workflow.xml
<command>import --options-file ${sqoop-import}</command>