上一篇文章我们简单介绍了一下Oozie以及怎样安装部署Oozie,本文我们通过几个案例来看一下怎样使用Oozie。关注专栏《破茧成蝶——大数据篇》,查看更多相关的内容~
目录
一、Oozie调度shell脚本
二、Oozie调度多个job
三、Oozie调度MapReduce任务
四、Oozie定时任务
1、创建目录
[root@master oozie-4.0.0-cdh5.3.6]# mkdir -p oozie-apps/shell
2、在创建的shell目录下创建两个文件
[root@master shell]# touch workflow.xml job.properties
3、编辑job.properties
#HDFS地址
nameNode=hdfs://master:8020
#ResourceManager地址
jobTracker=slave01:8032
#队列名称
queueName=default
examplesRoot=oozie-apps
oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/shell
4、编辑workflow.xml
${jobTracker}
${nameNode}
mapred.job.queue.name
${queueName}
mkdir
/root/files/xzw
Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]
5、上传配置文件到HDFS上
[root@master hadoop-2.5.0-cdh5.3.6]# bin/hdfs dfs -put /opt/modules/oozie-4.0.0-cdh5.3.6/oozie-apps/ /user/root
6、执行任务
[root@master oozie-4.0.0-cdh5.3.6]# bin/oozie job -oozie http://master:11000/oozie -config oozie-apps/shell/job.properties -run
被执行的脚本是创建目录xzw,我们可以去对应目录看一下是否创建成功:
当然也可以通过监控界面进行查看:
7、杀死某个任务
bin/oozie job -oozie http://master:11000/oozie -kill 0000001-210412154035993-oozie-root-W
1、编辑job.properties
nameNode=hdfs://master:8020
jobTracker=slave01:8032
queueName=default
examplesRoot=oozie-apps
oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/shells
2、编辑workflow.xml
${jobTracker}
${nameNode}
mapred.job.queue.name
${queueName}
mkdir
/root/files/aaa1
${jobTracker}
${nameNode}
mapred.job.queue.name
${queueName}
mkdir
/root/files/aaa2
${jobTracker}
${nameNode}
mapred.job.queue.name
${queueName}
mkdir
/root/files/aaa3
${jobTracker}
${nameNode}
mapred.job.queue.name
${queueName}
mkdir
/root/files/aaa4
Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]
3、上传配置文件到HDFS上
[root@master hadoop-2.5.0-cdh5.3.6]# bin/hdfs dfs -put /opt/modules/oozie-4.0.0-cdh5.3.6/oozie-apps/shells/ /user/root/oozie-apps
4、执行任务
bin/oozie job -oozie http://master:11000/oozie -config oozie-apps/shells/job.properties -run
5、查看执行结果
1、我们使用Oozie里面自带的examples,首先我们解压。
tar -zxvf oozie-examples.tar.gz
2、将examples目录下的map-reduce案例拷贝到我们oozie-apps目录下
[root@master apps]# pwd
/opt/modules/oozie-4.0.0-cdh5.3.6/examples/apps
[root@master apps]# cp -r ./map-reduce/ ../../oozie-apps/
3、删除不相关的目录
4、拷贝MapReduce的执行jar包到map-reduce的lib目录下
[root@master map-reduce]# cp /opt/modules/cdh/hadoop-2.5.0-cdh5.3.6/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.0-cdh5.3.6.jar lib/
5、修改workflow.xml文件
${jobTracker}
${nameNode}
mapred.job.queue.name
${queueName}
mapred.mapper.new-api
true
mapred.reducer.new-api
true
mapreduce.job.map.class
org.apache.hadoop.examples.WordCount$TokenizerMapper
mapreduce.job.reducer.class
org.apache.hadoop.examples.WordCount$IntSumReducer
mapreduce.job.output.key.class
org.apache.hadoop.io.Text
mapreduce.job.output.value.class
org.apache.hadoop.io.IntWritable
mapred.map.tasks
1
mapreduce.input.fileinputformat.inputdir
/xzw/input
mapreduce.output.fileoutputformat.outputdir
/xzw/output
Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]
6、修改job.properties文件
nameNode=hdfs://master:8020
jobTracker=slave01:8032
queueName=default
oozie.wf.application.path=${nameNode}/user/${user.name}/oozie-apps/map-reduce/workflow.xml
7、上传到HDFS中
bin/hdfs dfs -put /opt/modules/oozie-4.0.0-cdh5.3.6/oozie-apps/map-reduce/ /user/root/oozie-apps
8、执行任务
bin/oozie job -oozie http://master:11000/oozie -config oozie-apps/map-reduce/job.properties -run
9、查看执行结果
1、配置oozie-site.xml文件
oozie.processing.timezone
GMT+0800
Oozie server timezone. Valid values are UTC and GMT(+/-)####, for example 'GMT+0530' would be India
timezone. All dates parsed and genered dates by Oozie Coordinator/Bundle will be done in the specified
timezone. The default value of 'UTC' should not be changed under normal circumtances. If for any reason
is changed, note that GMT(+/-)#### timezones do not observe DST changes.
2、重启Oozie,并将时区改为东八区
3、将examples目录下的cron案例拷贝到我们oozie-apps目录下
4、修改coordinator.xml配置文件
${workflowAppUri}
jobTracker
${jobTracker}
nameNode
${nameNode}
queueName
${queueName}
5、修改workflow.xml配置文件
${jobTracker}
${nameNode}
mapred.job.queue.name
${queueName}
append_time.sh
/user/root/oozie-apps/cron/append_time.sh
Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]
6、修改job.properties配置文件
nameNode=hdfs://master:8020
jobTracker=slave01:8032
queueName=default
oozie.coord.application.path=${nameNode}/user/${user.name}/oozie-apps/cron
start=2021-04-16T15:50+0800
end=2021-04-16T16:25+0800
workflowAppUri=${nameNode}/user/${user.name}/oozie-apps/cron
7、上传到HDFS上
[root@master hadoop-2.5.0-cdh5.3.6]# bin/hdfs dfs -put /opt/modules/oozie-4.0.0-cdh5.3.6/oozie-apps/cron/ /user/root/oozie-apps
8、执行任务
bin/oozie job -oozie http://master:11000/oozie -config oozie-apps/cron/job.properties -run
9、查看结果
以上就是本文的所有内容,比较简单。你们在此过程中遇到了什么问题,欢迎留言,让我看看你们都遇到了哪些问题~