4.1 案例一: Oozie调度shell脚本

目标:使用Oozie调度Shell脚本

步骤1: 解压官方案例模板

tar -zxvf oozie-examples.tar.gz

步骤2: 创建工作目录

在这个目录下存储我们的工作任务.

在 Oozie 的根目录下创建

mkdir oozie-apps

步骤3: 拷贝任务模板到oozie-apps/目录

cp -r examples/apps/shell/ oozie-apps

步骤4: 编写脚本p1.sh

cd oozie-apps/shell
vim p1.sh

内容: 打印当前时间

#!/bin/bash
date > /opt/module/p1.log

步骤5: 修改 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}/${examplesRoot}/shell

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

步骤5: 修改 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/shell/${currentTime}#${currentTime}</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>

步骤6: 上传任务

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

步骤7: 执行任务

bin/oozie job -oozie http://hadoop201:11000/oozie -config oozie-apps/shell/job.properties -run

杀死某个任务

如果某个任务长时间不能结束, 也可以手动杀死这个任务

bin/oozie job -oozie http://hadoop102:11000/oozie -kill 0000004-170425105153692-oozie-z-W
Copyright © 尚硅谷大数据 2019 all right reserved,powered by Gitbook
该文件最后修订时间: 2019-03-28 11:17:42

results matching ""

    No results matching ""