hadoop – 通过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工作目录中:

[ambari_qa@sandbox 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的工作目录?提前致谢.

更新:

根据Chris的建议更改脚本后,它变为(最后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

但后来我开始面临许可问题.我给了该文件和文件夹的写权限.

[ambari_qa@ip-10-0-0-91 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]

最佳答案 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具有rwx权限

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

我要么修改文件和父文件夹的文件权限,以便mapred用户可以删除/替换文件,或者伪装成具有正确权限的用户

点赞