Oozie——多脚本逻辑顺序执行

楔子

oozie顺序执行sh脚本。

1 描述

依次执行p1.shp2.sh。每个里面都是简单的打印信息。如下

p1.sh

[grq@hadoop102 shell]$ more p1.sh 
#!/bin/bash
echo ''>/tmp/p1.log
/sbin/ifconfig>>/tmp/p1.log
echo `date`>>/tmp/p1.log

p2.sh

[grq@hadoop102 shell]$ more p2.sh 
#!/bin/bash
/bin/date>>/tmp/p2.log
echo '-----------------'>>/tmp/p2.log

2 配置

配置文件如下

[grq@hadoop102 shell]$ ls
job.properties  p1.sh  p2.sh  workflow.xml

在这里插入图片描述

2.1 配置job.properties

nameNode=hdfs://hadoop102:9000
jobTracker=hadoop103:8032

# 队列名称
queueName=default
examplesRoot=oozie-apps

oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/shell
EXEC1=p1.sh
EXEC2=p2.sh

2.1 配置workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf">
    <start to="p1-shell-node"/>
    <action name="p1-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>${EXEC1}</exec>
			 <file>/user/grq/oozie-apps/shell/${EXEC1}#${EXEC1}</file>
            <!--<argument>my_output=Hello Oozie</argument> -->
            <capture-output/>
        </shell>
        <ok to="p2-shell-node"/>
        <error to="fail"/>
    </action>
    <action name="p2-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>${EXEC2}</exec>
			 <file>/user/grq/oozie-apps/shell/${EXEC2}#${EXEC2}</file>
            <!--<argument>my_output=Hello Oozie</argument> -->
            <capture-output/>
        </shell>
        <ok to="end"/>
        <error to="fail"/>
    </action>
    <decision name="check-output">
        <switch>
            <case to="end">
                ${wf:actionData('shell-node')['my_output'] eq 'Hello Oozie'}
            </case>
            <default to="fail-output"/>
        </switch>
    </decision>
    <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>

在这里插入图片描述

3上传并执行

-- 删除之前旧文件
hadoop fs -rm-rf /user/grq/oozie-apps
-- 上传
hadoop fs -put  ./oozie-apps /user/grq/
--执行 
bin/oozie job -oozie http://hadoop102:11000/oozie -config oozie-apps/shell/job.properties -run
-- 杀死进程
bin/oozie job -oozie http://hadoop102:11000/oozie -kill 进程ID

4 查找执行的机器

每个脚本是在哪台机器上执行的 查找shell命令执行的位置

在这里插入图片描述

后记

此处仅仅是简单的使用描述。以下2个博客介绍的比较详细一点。可以参考

Oozie基础入门
大数据调度工具oozie详细介绍

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值