楔子
oozie顺序执行sh脚本。
1 描述
依次执行
p1.sh
和p2.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个博客介绍的比较详细一点。可以参考