-
編輯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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.