oozie shell 实战(完整配置文件)
有一个这样的需求,apache oozie调用shell命令(x.sh的脚本文件),x.sh的逻辑为先执行第一个jar包命令,后执行一个spark任务,第一个jar任务命令执行成功后返回的结果作为参数传递给第二个命令,再执行第二个spark-submit命令。不要问为什么不用两个action(一个为shellaction,另外一个为spark action)的话,啥叫需求,反正你懂。调试过程中,发现诸多问题,此类问题还不好解决,特写此分享,供各位同行少走弯路。我相信赠人玫瑰手有余香。此分享包含如下:
- shell脚本文件
- workflow.xml文件
- job.properties文件
- 错误摘要经验分享
环境:
Apache Ambari:2.7.3.0
HDP:HDP-3.1.0.0
oozie:4.3.1
oozie4.3.1官网地址
一、shell脚本文件
二、shell脚本文件
<?xml version="1.0" encoding="utf-8"?>
<workflow-app xmlns="uri:oozie:workflow:0.5" name="defaultBuilder">
<start to="cid1129343684748382208"/>
<action name="cid1129343684748382208">
<shell xmlns="uri:oozie:shell-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<exec>${nameNode}/business/oozie/hub/hub.sh</exec>
<argument>参数1字符串</argument>
<argument>参数2字符串</argument>
<file>${nameNode}/business/oozie/hub/hub.sh</file>
<file>${nameNode}/business/oozie/hub/ostar-etl.jar</file>
<file>${nameNode}/business/oozie/dhe-dipc.jar</file>
<capture-output/>
</shell>
<ok to="end"/>
<error to="error"/>
</action>
<kill name="error">
<message>spark failed.error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>
三、 job.properties文件
nameNode=hdfs://bdpcluster
#yarn.resourcemanager.address
jobTracker=bj-smzy-scrm-cdp-test-v-52-134.xcm.cn:8050
queueName=default
jobRoot=business/oozie/scheduler
#workflow.xml存放位置
oozie.wf.application.path=${nameNode}/${jobRoot}/${schedulerId}
oozie.use.system.libpath=true
#当前程序需要以来的其他JAR包路径
oozie.libpath=${nameNode}/business/oozie
security_enabled=false
dryrun=false
master=yarn
mode=cluster
sparkOpt=--executor-cores 5 --executor-memory 3G --num-executors 5 --conf spark.driver.cores=5 --conf spark.driver.maxResultSize=0 --conf spark.driver.memony=5g
schedulerId=default-scheduler
jobName=bi-job
四、错误摘要经验分享
- 提示找不到jar,或者sh文件
请注意在workflow.xml文件中,是否包含file属性
- 执行第一个jar命令,提示找不到java命令
在sh命令中,需要添加 export JAVA_HOME=/usr/java/jdk1.8
- Cannot run program “hub.sh” (in directory “/hadoop/yarn/local/usercache/hdfs/appcache/application_1557221091029_0826/container_e65_1557221091029_0826_01_000002”): error=13, Permission denied
此问题不一定是权限问题,我刚开始出现此问题,赋777还是报这个错,最后发现是由于sh文件的格式为dos,需要set ff=unix下问题解决
- shell脚本中deploy-mode需要设置为client
1、如果设置为cluster,第二个命令不会执行,oozie status执行完第一个任务后,直接kill掉任务
2、由于oozie执行shell action的流程是随机找一台机器进行执行,所以请保证集群中每一台机器是否按照了yarn或sparak client(后续看能否指定某一台执行)
- shell的参数,我传输的是json字符串,参数大或特殊字符的时候,会出现被截断,一个参数会变成多个
所有参数请用双引号引起来,保证不被截断(主要是我shell太菜了,不然不会犯怎么低级的错误)
- 此文章持续更新。。。