簡介
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