oozie4.1.x 执行shell脚本-执行多个任务

上接:https://www.malaoshi.top/show_1IX2FgcaJoO9.html

编写shell

编写脚本

在 std1_shell 目录 下编写 test_oozie2.sh

vim test_oozie2.sh

内容如下:

echo lilei lucy >> /program/oozie_hello2.txt

注意:要写生成文件的路径 /program/oozie_hello2.txt,否则不好找该文件

编写 job.properties

在 std1_shell 目录下修改 job.properties 文件

vim job.properties

内容如下:

nameNode=hdfs://hadoop1:8020
jobTracker=hadoop2:8032
queueName=default
examplesRoot=oozie_apps
oozie.wf.application.path=${nameNode}/${examplesRoot}/std1_shell
EXEC=test_oozie.sh
EXEC2=test_oozie2.sh
shellpath=/${examplesRoot}/std1_shell/${EXEC}
shellpath2=/${examplesRoot}/std1_shell/${EXEC2}

解释:

  • nameNode:namenode ip、port
  • jobTracker:resources Manager ip、port
  • queueName:默认队列
  • examplesRoot:工作目录
  • oozie.wf.application.path:hdfs上的路径
  • EXEC:要执行的脚本
  • EXEC2:第二个要执行的脚本
  • shellpath:shell脚本在 hdfs 上的路径
  • shellpath2:第二个 shell脚本在 hdfs 上的路径

编写 workflow.xml

在 std1_shell 目录下修改 workflow.xml 文件

vim workflow.xml

内容如下:

<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf">
    <start to="shell-node"/>
    <action name="shell-node">
        <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>${EXEC}</exec>
            <file>${shellpath}</file>
            <capture-output/>
        </shell>
        <!-- 执行成功,继续执行shell2 -->
        <ok to="shell2"/>
        <error to="fail"/>
    </action>
    <action name="shell2">
        <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>${EXEC2}</exec>
            <file>${shellpath2}</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>

重新上传

重新上传需要先删除 hdfs 的相关文件夹

hadoop fs -rm -r /oozie_apps/std1_shell

上传

cd /program/oozie-4.1.0-cdh5.14.0/
hadoop fs -put oozie_apps /

job.properties 可以不上传到 HDFS

执行

cd /program/oozie-4.1.0-cdh5.14.0
bin/oozie job -oozie http://hadoop3:11000/oozie -config oozie_apps/std1_shell/job.properties -run

解释:

  • oozie_apps/std1_shell/job.properties:本机 job.properties 所在的路径
    写绝对路径也可以:/program/oozie-4.1.0-cdh5.14.0/oozie_apps/std1_shell/job.properties

在 oozie web查看

访问 http://hadoop3:11000

在 yarn 查看结果

访问:http://hadoop2:8088/

可知:这2个任务在不同服务器执行

在服务器查看生成的文件

根据上图的提示,到 相应服务器 的 /program 目录下查找 oozie_hello.txt 文件,如果有该文件,说明任务成功