4.2 案例二:Oozie 逻辑调度执行多个 Job

目标:使用Oozie执行多个Job调度

步骤1: 把刚才的 shell 文件夹重新复制一份, 并更名为 shell2

cp -r shell shell2

步骤2: 在 shell2 内创建文件 p2.sh

#!/bin/bash
/sbin/ifconfig > p2.log

步骤3: 修改 job.properties 文件

# namenode 地址
nameNode=hdfs://hadoop201:8000
# ResouceManager 地址, 端口默认是 8032
jobTracker=hadoop202:8032
# 队列地址
queueName=default
#案例的根路径
my1=oozie-apps
# 前面的几个路径用来组成 workflow 应用在hdfs上的路径
oozie.wf.application.path=${nameNode}/user/${user.name}/${my1}/shell2

# 定义一个变量, 在工作流文件中使用
currentTime=p1.sh
ip=p2.sh

步骤4: 修改 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>${currentTime}</exec>
            <file>/user/atguigu/oozie-apps/shell2/${currentTime}#${currentTime}</file>
            <capture-output/>
        </shell>
        <ok to="shell-node2"/>
        <error to="fail"/>
    </action>
    <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>${ip}</exec>
            <file>/user/atguigu/oozie-apps/shell2/${ip}#${ip}</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>
    <kill name="fail-output">
        <message>Incorrect output, expected [Hello Oozie] but was [${wf:actionData('shell-node')['my_output']}]</message>
    </kill>
    <end name="end"/>
</workflow-app>

步骤5: 上传任务

/opt/module/cdh/hadoop-2.5.0-cdh5.3.6/bin/hadoop fs -put oozie-apps/shell2 /user/atguigu/oozie-apps

步骤6: 执行任务

bin/oozie job -oozie http://hadoop201:11000/oozie -config oozie-apps/shell2/job.properties -run
Copyright © 尚硅谷大数据 2019 all right reserved,powered by Gitbook
该文件最后修订时间: 2019-03-28 11:17:42

results matching ""

    No results matching ""