-
编辑job.properties
#HDFS地址 nameNode=hdfs://hadoop111:8020 #ResourceManager地址,默认端口8032 jobTracker=hadoop112:8032 #队列名称 queueName=default examplesRoot=oozie-apps #这里指定的是job.properties和workflow.xml文件上传到hdfs上的路径 #结果:http://192.168.191.111:8020/user/kgf/oozie-apps/shell2 oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/shell2
-
编辑workflow.xml文件
<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf"> <!--开始节点--> <start to="p1-shell-node"/> <!--动作节点1--> <action name="p1-shell-node"> <shell xmlns="uri:oozie:shell-action:0.2"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>mkdir</exec> <argument>/usr/local/module/OozieTest/shell2</argument> <capture-output/> </shell> <!--成功后调用动作节点2--> <ok to="p2-shell-node"/> <error to="fail"/> </action> <!--动作节点2--> <action name="p2-shell-node"> <shell xmlns="uri:oozie:shell-action:0.2"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>mkdir</exec> <argument>/usr/local/module/OozieTest/shell3</argument> <capture-output/> </shell> <ok to="end"/> <error to="fail"/> </action> <kill name="fail"> <message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message> </kill> <end name="end"/> </workflow-app>
-
将job.properties文件和workflow.xml文件放到/usr/local/module/oozie-4.0.0-cdh5.3.6/oozie-apps/shell2目录下
-
将shell2目录文件上传到hdfs上去
-
执行任务,在/usr/local/module/oozie-4.0.0-cdh5.3.6根目录下执行
命令:bin/oozie job -oozie http://hadoop111:11000/oozie -config oozie-apps/shell2/job.properties -run
-
注意!!!!!!!!!!
因为我们是在hadoop集群上运行oozie,那么我们在运行oozie调用shell命令时一定要注意权限的问题,
比如上面我们执行的是mkdir /usr/local/module/OozieTest/shell3 和 mkdir /usr/local/module/OozieTest/shell2
但是因为OozieTest这个中间目录不存在,那么我们的hadoop111,hadoop112,hadoop113都要先创建/usr/local/module/OozieTest/
目录,否则肯定创建失败。 -
还有一个带有分支结构的例子如下
a:job.properties#HDFS地址 nameNode=hdfs://hadoop111:8020 #ResourceManager地址,默认端口8032 jobTracker=hadoop112:8032 #队列名称 queueName=default examplesRoot=oozie-apps #这里指定的是job.properties和workflow.xml文件上传到hdfs上的路径 #结果:http://192.168.191.111:8020/user/kgf/oozie-apps/shell2 oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/xshell
b:workflow.xml
<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf"> <!--开始节点--> <start to="p1-shell-node"/> <!--动作节点1--> <action name="p1-shell-node"> <shell xmlns="uri:oozie:shell-action:0.2"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>mkdir</exec> <argument>/usr/local/module/OozieTest/shell1</argument> <capture-output/> </shell> <ok to="forking"/> <error to="fail"/> </action> <!--动作节点2--> <action name="p2-shell-node"> <shell xmlns="uri:oozie:shell-action:0.2"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>mkdir</exec> <argument>/usr/local/module/OozieTest/shell2</argument> <capture-output/> </shell> <ok to="joining"/> <error to="fail"/> </action> <!--动作节点3--> <action name="p3-shell-node"> <shell xmlns="uri:oozie:shell-action:0.2"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>mkdir</exec> <argument>/usr/local/module/OozieTest/shell3</argument> <capture-output/> </shell> <ok to="joining"/> <error to="fail"/> </action> <!--动作节点4--> <action name="p4-shell-node"> <shell xmlns="uri:oozie:shell-action:0.2"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>mkdir</exec> <argument>/usr/local/module/OozieTest/shell4</argument> <capture-output/> </shell> <ok to="end"/> <error to="fail"/> </action> <fork name="forking"> <path start="p2-shell-node"/> <path start="p3-shell-node"/> </fork> <join name="joining" to="p4-shell-node"/> <kill name="fail"> <message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message> </kill> <end name="end"/> </workflow-app>
c:流程图
Oozie调度执行多个Job
最新推荐文章于 2023-04-10 21:17:42 发布