oozie4.1.x 执行shell脚本 作者:马育民 • 2020-11-18 19:26 • 阅读:10191 # 介绍 通过 oozie 启动 shell 脚本,理解 oozie 的使用 # 创建 工作目录 在 `/program/oozie-4.1.0-cdh5.14.0` 目录下创建 `oozie_apps` 目录 ``` cd /program/oozie-4.1.0-cdh5.14.0 ``` ``` mkdir oozie_apps ``` # 编写shell ### 创建 目录 在 `oozie_apps` 目录下创建 `std1_shell` 目录 ``` cd oozie_apps ``` ``` mkdir std1_shell ``` ``` cd std1_shell ``` ### 编写脚本 ``` vim test_oozie.sh ``` 内容如下: ``` echo hello world >> /program/oozie_hello.txt ``` **注意:**要写生成文件的路径 `/program/oozie_hello.txt`,否则不好找该文件 ### 测试脚本是否可执行 修改权限: ``` chmod 777 test_oozie.sh ``` 执行脚本: ``` ./test_oozie.sh ``` 执行结果:在 `/program/` 目录下生成 `oozie_hello.txt` 文件,内容是: ``` hello world ``` 最后一定要删除 `/program/oozie_hello.txt` 文件,否则无法验证 是刚才手动执行的脚本,还是由 oozie执行的脚本 # 编写 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 shellpath=/${examplesRoot}/std1_shell/${EXEC} ``` **解释:** - nameNode:namenode ip、port - jobTracker:resources Manager ip、port - queueName:默认队列 - examplesRoot:工作目录 - oozie.wf.application.path:hdfs上的路径 - EXEC:要执行的脚本 - shellpath:shell脚本在 hdfs 上的路径 # 编写 workflow.xml 在 `std1_shell` 目录下创建 `workflow.xml` 文件 ``` vim workflow.xml ``` 内容如下: ``` ${jobTracker} ${nameNode} mapred.job.queue.name ${queueName} ${EXEC} ${shellpath} Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}] ``` **解释:** - `${jobTracker}`、`${nameNode}`、`${queueName}`、`${EXEC}`、`${shellpath}` 是 `job.properties` 文件的配置项 - `` 定义 `shell-node` 是任务的起点 # job.properties 和 workflow.xml 关系 [![](http://65242847.gitee.io/pic/oozie/3DE53068-1FA8-40eb-BB65-C25639B4F62B.png)](http://65242847.gitee.io/pic/oozie/3DE53068-1FA8-40eb-BB65-C25639B4F62B.png) # 上传到 hdfs ``` cd /program/oozie-4.1.0-cdh5.14.0/ ``` ``` hadoop fs -put oozie_apps / ``` **job.properties 可以不上传到 HDFS** ### 重新上传 重新上传需要先删除 hdfs 的相关文件夹 ``` hadoop fs -rm -r /oozie_apps/std1_shell ``` # job.properties 和 hdfs 上文件的关系 [![](http://65242847.gitee.io/pic/oozie/3E7F212B-0B00-4dcf-B0BE-64ED99693118.png)](http://65242847.gitee.io/pic/oozie/3E7F212B-0B00-4dcf-B0BE-64ED99693118.png) # 执行 ``` 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 **注意:**建议用 **Chrome** 或 **Firefox** 浏览器 [![](http://65242847.gitee.io/pic/oozie/Snipaste_2021-11-19_00-22-54.png)](http://65242847.gitee.io/pic/oozie/Snipaste_2021-11-19_00-22-54.png) [![](http://65242847.gitee.io/pic/oozie/Snipaste_2021-11-26_10-03-00.png)](http://65242847.gitee.io/pic/oozie/Snipaste_2021-11-26_10-03-00.png) # 在 yarn 查看结果 访问:http://hadoop2:8088/ [![](http://65242847.gitee.io/pic/oozie/Snipaste_2021-11-19_00-12-35.png)](http://65242847.gitee.io/pic/oozie/Snipaste_2021-11-19_00-12-35.png) # 在服务器查看生成的文件 根据上图的提示,到 hadoop3 的 `/program` 目录下查找 `oozie_hello.txt` 文件,如果有该文件,说明任务成功 原文出处:http://malaoshi.top/show_1IX2FgcaJoO9.html