简介
oozie不仅可以执行单个任务,也可以在一个任务中执行多个job,只需要添加多个的action,并让第一个任务成功之后指向第二个任务等以此类推。
执行多个job任务
相比执行多个任务,我们的oozie的任务配置文件是需要做改动的。
job.properties
nameNode=hdfs://master:8020
jobTracker=master:8032
queueName=default
myRoot=oozie-apps
#第一个任务文件名称
execFile1=my.sh
#第二个任务文件名称
execFile2=two.sh
#该任务的HDFS的存放路径地址
oozie.wf.application.path=${nameNode}/user/${user.name}/${myRoot}/shell2
workflow.xml
<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf-my2">
<!--start指向第一个任务-->
<start to="shell-node1"/>
<!-- 第一个shell任务 -->
<action name="shell-node1">
<shell xmlns="uri:oozie:shell-action:0.2">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<exec>${execFile1}</exec>
<!--修改为任务1的文件 -->
<file>/user/root/oozie-apps/shell/${execFile1}#${execFile1}</file>
<capture-output/>
</shell>
<!-- 运行成功 指向第二个任务 -->
<ok to="shell-node2"/>
<error to="fail"/>
</action>
<!-- 第二个shell任务 -->
<action name="shell-node2">
<shell xmlns="uri:oozie:shell-action:0.2">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<exec>${execFile2}</exec>
<!-- <argument>my_output=Hello Oozie</argument> -->
<file>/user/root/oozie-apps/shell/${execFile2}#${execFile2}</file>
<capture-output/>
</shell>
<ok to="end"/>
<error to="fail"/>
</action>
<kill name="fail">
<message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>
my.sh
第一个任务文件
#!/bin/bash
date > /opt/module/my.log
two.sh
第二个任务文件
#!/bin/bash
date > /opt/module/two.log
这两个任务都是获取时间,重定向到不同的日志文件
上传到HDFS
root@master:/opt/module/oozie-4.0.0-cdh5.3.6/oozie-apps# hadoop fs -put shell2/ /user/root/oozie-apps
注意自己的地址,按照自己的实际地址
提交oozie任务
root@master:/opt/module# oozie-4.0.0-cdh5.3.6/bin/oozie job -oozie http://master:11000/oozie -config oozie-4.0.0-cdh5.3.6/oozie-apps/shell2/job.properties -run
job: 0000001-190902153908594-oozie-root-W
root@master:/opt/module#
注意命令:
oozie-4.0.0-cdh5.3.6/bin/oozie job -oozie http://master:11000/oozie -config oozie-4.0.0-cdh5.3.6/oozie-apps/shell2/job.properties -run
oozie-4.0.0-cdh5.3.6/bin/oozie
:服务器上oozie的bin目录中的oozie的地址
http://master:11000/oozie
:自己服务器上的oozie提交地址
oozie-4.0.0-cdh5.3.6/oozie-apps/shell2/job.properties
:服务器上的配置文件地址,不是HDFS上的地址也不是其他地址
运行截图:
运行日志:
查看结果:
相差也就两分钟。
如果你想杀掉某个oozie任务:
root@master:/opt/module/oozie-4.0.0-cdh5.3.6# bin/oozie job -oozie http://master:11000/oozie -kill 0000001-190902153908594-oozie-root-W