一、Hive Action
1、创建文件
[root@hadoop-senior oozie-apps]# pwd /opt/cdh-5.3.6/oozie-4.0.0-cdh5.3.6/oozie-apps [root@hadoop-senior oozie-apps]# mkdir hive-select ##job.properties nameNode=hdfs://hadoop-senior.ibeifeng.com:8020 jobTracker=hadoop-senior.ibeifeng.com:8032 queueName=default oozieAppsRoot=user/root/oozie-apps oozieDataRoot=user/root/oozie/datas oozie.use.system.libpath=true oozie.wf.application.path=${nameNode}/${oozieAppsRoot}/hive-select/ outputDir=hive-select/output ##workflow.xml <workflow-app xmlns="uri:oozie:workflow:0.5" name="wf-hive-select"> <start to="hive-node"/> <action name="hive-node"> <hive xmlns="uri:oozie:hive-action:0.5"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <prepare> <delete path="${nameNode}/${oozieDataRoot}/${outputDir}"/> </prepare> <job-xml>${nameNode}/${oozieAppsRoot}/hive-select/hive-site.xml</job-xml> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <script>select-student.sql</script> <param>OUTPUT=${nameNode}/${oozieDataRoot}/${outputDir}</param> </hive> <ok to="end"/> <error to="fail"/> </action> <kill name="fail"> <message>Hive failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message> </kill> <end name="end"/> </workflow-app>
##参数注释
<job-xml>${nameNode}/${oozieAppsRoot}/hive-select/hive-site.xml</job-xml> //指定hive-site.xml文件的路径,因为运行hive action要读取hive的配置
<script>select-student.sql</script> //指定要运行的sql脚本,默认和workflow.xml在同一目录下
2、上传到hdfs
##[root@hadoop-senior hive-select]# vim select-student.sql //内容如下
insert overwrite directory '${OUTPUT}'
select
count(1) cnt
from default.student ;
##
[root@hadoop-senior oozie-apps]# cp /opt/cdh-5.3.6/hive-0.13.1-cdh5.3.6/conf/hive-site.xml hive-select/
##
[root@hadoop-senior oozie-apps]# mkdir hive-select/lib
[root@hadoop-senior oozie-apps]# cp /opt/softwares/mysql-libs/mysql-connector-java-5.1.27/mysql-connector-java-5.1.27-bin.jar hive-select/lib/
##上传到hdfs
[root@hadoop-senior oozie-apps]# /opt/cdh-5.3.6/hadoop-2.5.0-cdh5.3.6/bin/hdfs dfs -put hive-select/ /user/root/oozie-apps
3、运行oozie job
##
[root@hadoop-senior oozie-4.0.0-cdh5.3.6]# export OOZIE_URL=http://hadoop-senior.ibeifeng.com:11000/oozie/
[root@hadoop-senior oozie-4.0.0-cdh5.3.6]# bin/oozie job -config oozie-apps/hive-select/job.properties -run