oozie4.1.x 执行shell脚本-执行多个任务 作者:马育民 • 2021-11-26 10:50 • 阅读:10118 上接:https://www.malaoshi.top/show_1IX2FgcaJoO9.html # 编写shell ### 编写脚本 在 `std1_shell` 目录 下编写 `test_oozie2.sh` ``` vim test_oozie2.sh ``` 内容如下: ``` echo lilei lucy >> /program/oozie_hello2.txt ``` **注意:**要写生成文件的路径 `/program/oozie_hello2.txt`,否则不好找该文件 # 编写 job.properties 在 `std1_shell` 目录下修改 `job.properties` 文件 ``` vim job.properties ``` 内容如下: ``` nameNode=hdfs://hadoop1:8020 jobTracker=hadoop2:8032 queueName=default examplesRoot=oozie_apps oozie.wf.application.path=${nameNode}/${examplesRoot}/std1_shell EXEC=test_oozie.sh EXEC2=test_oozie2.sh shellpath=/${examplesRoot}/std1_shell/${EXEC} shellpath2=/${examplesRoot}/std1_shell/${EXEC2} ``` **解释:** - nameNode:namenode ip、port - jobTracker:resources Manager ip、port - queueName:默认队列 - examplesRoot:工作目录 - oozie.wf.application.path:hdfs上的路径 - EXEC:要执行的脚本 - EXEC2:第二个要执行的脚本 - shellpath:shell脚本在 hdfs 上的路径 - shellpath2:第二个 shell脚本在 hdfs 上的路径 # 编写 workflow.xml 在 `std1_shell` 目录下修改 `workflow.xml` 文件 ``` vim workflow.xml ``` 内容如下: ``` ${jobTracker} ${nameNode} mapred.job.queue.name ${queueName} ${EXEC} ${shellpath} ${jobTracker} ${nameNode} mapred.job.queue.name ${queueName} ${EXEC2} ${shellpath2} Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}] ``` # 重新上传 重新上传需要先删除 hdfs 的相关文件夹 ``` hadoop fs -rm -r /oozie_apps/std1_shell ``` ### 上传 ``` cd /program/oozie-4.1.0-cdh5.14.0/ ``` ``` hadoop fs -put oozie_apps / ``` **job.properties 可以不上传到 HDFS** # 执行 ``` cd /program/oozie-4.1.0-cdh5.14.0 ``` ``` bin/oozie job -oozie http://hadoop3:11000/oozie -config oozie_apps/std1_shell/job.properties -run ``` **解释:** - `oozie_apps/std1_shell/job.properties`:本机 `job.properties` 所在的路径 写绝对路径也可以:`/program/oozie-4.1.0-cdh5.14.0/oozie_apps/std1_shell/job.properties` # 在 oozie web查看 访问 http://hadoop3:11000 [](https://www.malaoshi.top/upload/pic/oozie/Snipaste_2021-11-26_10-54-41.png) # 在 yarn 查看结果 访问:http://hadoop2:8088/ [](https://www.malaoshi.top/upload/pic/oozie/Snipaste_2021-11-19_00-12-35.png) 可知:这2个任务在不同服务器执行 # 在服务器查看生成的文件 根据上图的提示,到 相应服务器 的 `/program` 目录下查找 `oozie_hello.txt` 文件,如果有该文件,说明任务成功 原文出处:http://malaoshi.top/show_1IX2IS0dQ8tN.html