2013-05-09 210 views
4

我试图通过oozie执行shell脚本,但我遇到了一些问题。通过oozie运行shell脚本

我有这样的(import.properties)属性文件:

startIndex=2000 
chunkSize=2000 

的想法是,在每一个执行的startIndex值将由块大小更新。所以如果我执行它,它应该有

startIndex=4000 
chunkSize=2000 

我已经单独测试了脚本,它工作正常。这是我的其他相关文件。

job.properties

nameNode=hdfs://192.168.56.101:8020 
jobTracker=192.168.56.101:50300 
wfeRoot=wfe 
queueName=default 
EXEC=script.sh 
propertyLoc=import.properties 

oozie.use.system.libpath=true 
oozie.wf.application.path=${nameNode}/user/${user.name}/${wfeRoot}/coordinator 

workflow.xml

<workflow-app xmlns='uri:oozie:workflow:0.2' name='shell-wf'> 
<start to='shell1' /> 
<action name='shell1'> 
    <shell xmlns="uri:oozie:shell-action:0.1"> 
     <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>${EXEC}#${EXEC}</file> 
     <file>${propertyLoc}#${propertyLoc}</file> 
    </shell> 
    <ok to="end" /> 
    <error to="fail" /> 
</action> 
<kill name="fail"> 
    <message>Script failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message> 
</kill> 
<end name='end' /> 

script.sh

#!/bin/sh 
file=import.properties 
. $file 

SCRIPT=$(readlink -f $file) 
SCRIPTPATH=$(dirname $SCRIPT) 
echo $SCRIPTPATH 

newStartIndex=`expr $chunkSize + $startIndex` 
newStartIndexStr=startIndex=$newStartIndex 

oldStartIndexStr=startIndex=$startIndex 
chunkSizeStr=chunkSize=$chunkSize 

sed -i "s|$oldStartIndexStr|$newStartIndexStr|g" $file 

我把我HDFS工作目录中的所有这些文件:

[[email protected] coordinator]$ hadoop fs -lsr /user/ambari_qa/wfe/coordinator 
-rw-rw-rw- 1 ambari_qa hdfs   32 2013-05-09 00:12 /user/ambari_qa/wfe/coordinator/import.properties 
-rw-rw-rw- 1 ambari_qa hdfs  533 2013-05-09 01:19 /user/ambari_qa/wfe/coordinator/script.sh 
-rw------- 1 ambari_qa hdfs  852 2013-05-09 00:50 /user/ambari_qa/wfe/coordinator/workflow.xml 

我期待每次执行后都会更改import.properties文件。但是,即使oozie工作成功,我也发现这并没有改变。为了调试的目的,我在执行过程中打印出来的文件的位置,并发现它复制到另一个位置(从日志):

>>> Invoking Shell command line now >> 

Stdoutput /hadoop/mapred/taskTracker/ambari_qa/distcache/-5756672768810005023_889271025_125659265/192.168.56.101/user/ambari_qa/wfe/coordinator 
Stdoutput startIndex=4000 
Stdoutput startIndex=2000 
Exit code of the Shell command 0 
<<< Invocation of Shell command completed <<< 

我需要做的,这样它的影响HDFS的工作目录是什么?提前致谢。

更新:

改变基于克里斯的建议,该脚本之后,就变成(最后3行):

hadoop fs -rm hdfs://ip-10-0-0-92:8020/user/ambari_qa/wfe/shell-oozie/$file 
sed -i "s|$oldStartIndexStr|$newStartIndexStr|g" $file 
hadoop fs -put $file /user/ambari_qa/wfe/shell-oozie 

但后来,我开始对着权限问题。我给了该文件和文件夹的写入权限。

[[email protected] shell-oozie]$ hadoop fs -ls /user/ambari_qa/wfe/shell-oozie 

找到3项:

-rw-rw-rw- 3 ambari_qa hdfs   32 2013-05-10 16:55 /user/ambari_qa/wfe/shell-oozie/import.properties 
-rw-rw-rw- 3 ambari_qa hdfs  540 2013-05-10 16:48 /user/ambari_qa/wfe/shell-oozie/script.sh 
-rw-rw-rw- 3 ambari_qa hdfs  826 2013-05-10 15:29 /user/ambari_qa/wfe/shell-oozie/workflow.xml 

以下是错误日志:

rm: org.apache.hadoop.security.AccessControlException: Permission denied: user=mapred, access=EXECUTE, inode="ambari_qa":ambari_qa:hdfs:rwxrwx--- 
put: org.apache.hadoop.security.AccessControlException: Permission denied: user=mapred, access=EXECUTE, inode="ambari_qa":ambari_qa:hdfs:rwxrwx--- 
Failing Oozie Launcher, Main class [org.apache.oozie.action.hadoop.ShellMain], exit code [1] 

回答

2

sed的是该文件的本地分布式缓存版本上运行 - 你需要管通过hadoop fs shell返回sed的输出结果(记得在上传之前删除文件),例如:

hadoop fs -rm /user/ambari_qa/wfe/coordinator/$file 

sed "s|$oldStartIndexStr|$newStartIndexStr|g" $file \ 
    hadoop fs -put - /user/ambari_qa/wfe/coordinator/$file 

有可能你可以找到hdfs中的协调器路径,而不是硬编码到脚本中。

更新

的权限问题是由于Oozie的作业运行作为mapred用户,但该文件只对用户ambari_qa和组hdfs

user=mapred, access=EXECUTE, inode="ambari_qa":ambari_qa:hdfs:rwxrwx--- 

我会rwx权限将修改文件和父文件夹的文件权限,以便mapred用户可以删除/替换文件,或者将伪装看作具有正确权限的用户

+0

感谢您的答复了很多克里斯

我可以通过添加

hadoop_user=${2} export HADOOP_USER_NAME=${hadoop_user}

hadoop_user作为$通过解决这个问题。在此基础上,我稍微改变了我的脚本 'Hadoop的FS -rm /用户/ ambari_qa/WFE /协调员/ $文件 SED -i “S | $ oldStartIndexStr | $ newStartIndexStr | G” $文件 Hadoop的FS -put $ file/user/ambari_qa/wfe/coordinator' 但面临权限问题。对于我想通过oozie工作流程修改的文件,应该期待什么权限?再次感谢。 – dreamer 2013-05-10 15:51:55

+0

oozie服务器是否以自己的用户身份运行,和/或您是否在HDFS中启用了用户伪装功能。基本上谁拥有该文件,并且可以发布完整的异常消息(更新您的问题而不是评论) – 2013-05-10 17:28:08

+0

再次感谢@Chris。我更新了我的问题。 – dreamer 2013-05-10 17:34:05

0

我有一个类似的问题。 {:用户WF}在工作流作为参数传递给动作