[关闭]
@tsing1226 2015-12-25T10:43:55.000000Z 字数 2099 阅读 1462

oozie

Oozie workflow中四个Action解析--Shell Action

Shell Action部署

在本地创建项目目录

oozie$:mkdir oozie-apps/shell

拷贝example中shell项目到指定目录

oozie$:cp -r examples/apps/shell/* oozie-apps/shell/

修改配置文件

job.properties

nameNode=hdfs://hadoop-senior01.grc.com:8020
jobTracker=hadoop-senior01.grc.com:8032
queueName=default
oozieAppsRoot=user/grc/oozie-apps
oozieDataRoot=user/grc/oozie-datas

oozie.wf.application.path=${nameNode}/${oozieAppsRoot}/shell
#Shell Script to run
EXEC=emp-join-demp.sh

workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.5" 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>${nameNode}/${oozieAppsRoot}/shell/${EXEC}#${EXEC}</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>

脚本

创建emp-join-demp.sh脚本

#!/bin/sh
## set system enviroment variable
 . /etc/profile
## set HIVE_HOME
HIVE_HOME=/opt/cdh3.5.6/hive-0.13.1-cdh5.3.6
$HIVE_HOME/bin/hive -e "create table db_1206.tb_join as select e.empno, e.ename, e.job, d.deptno, d.dname from db_1206.emp e join db_1206.dept d on e.deptno = d.deptno ;"

Note:但是在开发中我们更希望把操作单独写成文件,这样方便我们日后管理调试。

emp-join-demp.sh脚本

#!/bin/sh
## set system enviroment variable
 . /etc/profile
##set SCRIPT_PATH
SCRIPT_PATH=/opt/cdh3.5.6/oozie-4.0.0-cdh5.3.6/oozie-apps/shell/
## set HIVE_HOME
HIVE_HOME=/opt/cdh3.5.6/hive-0.13.1-cdh5.3.6
$HIVE_HOME/bin/hive -f $SCRIPT_PATH/emp_join_dept.sql

emp-join-dept.sql

create table db_1206.tb_join2 
  as 
select 
     e.empno, e.ename, e.job, d.deptno, d.dname 
from 
     db_1206.emp e 
join 
    db_1206.dept d 
on 
   e.deptno = d.deptno ;

赋予脚本执行权限

chmod u+x oozie-apps/shell/emp-join-demp.sh

在HDFS上创建项目存储目录

/opt/cdh3.5.6/hadoop-2.5.0-cdh5.3.6/bin/hdfs dfs -mkdir oozie-apps/shell

上传配置文件及脚本到项目目录

/opt/cdh3.5.6/hadoop-2.5.0-cdh5.3.6/bin/hdfs dfs -put oozie-apps/shell oozie-apps/shell

运行项目

bin/oozie job --config oozie-apps/shell/job.properties -run 

查看运行结果

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注