Oozie

Oozie的功能模塊

workflow
由多個工做單元組成
工做單元之間有依賴關係
MR1->MR2->MR3->result
hadoop jar:提交1個MR
oozie:監控當前工做單元狀態,完成以後自動提交下一個工做單元
scheduler
crontab:是linux簡單調度腳本
定時調度工做單元
模塊:
1) workflow:定義工做流程;順序執行流程節點,支持fork(分支多個節點),join(合併多個節點爲一個)html

2) Coordinator:協調器,調度工做流程,只能定義一個週期;定時觸發workflow前端

3) Bundle:綁定多個定時任務;綁定多個Coordinator java

workflow經常使用節點:node

1) 工做單元-對應->動做節點Action Nodes
2) 指明工做流走向->控制節點Control Flow Nodesmysql

部署Hadoop(CDH版本的)

apache版本的oozie須要編譯(即用maven導入相應的jar包)
Namenode:core-site.xml
hdfs:9000->8020爲了區別以前的hadooplinux

core-site.xmlweb

    <!-- 指定HDFS中NameNode的地址 -->
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://hadoop101:8020</value>
    </property>
    <!-- 指定Hadoop運行時產生文件的存儲目錄 -->
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/opt/module/cdh/hadoop-2.5.0-cdh5.3.6</value>
    </property>
    <!-- Oozie Server的Hostname -->
    <property>
        <name>hadoop.proxyuser.kris.hosts</name>
        <value>*</value>
    </property>

    <!-- 容許被Oozie代理的用戶組 -->
    <property>
        <name>hadoop.proxyuser.kris.groups</name>
        <value>*</value>
    </property>
View Code

hadoop代理用戶
有可能沒有權限,讓代理去作可有可無的事
kris被代理,user1代理;oozie用到了hadoop的代理機制sql

kris可以代理用戶的節點
kris可以代理的用戶組
即kris可以代理全部節點上的全部用戶

hdfs-site.xmlshell

    <!-- 數據的副本數量 -->
    <property>
        <name>dfs.replication</name>
        <value>3</value>
    </property>
    <!-- 指定Hadoop輔助名稱節點主機配置 -->
    <property>
          <name>dfs.namenode.secondary.http-address</name>
          <value>hadoop103:50090</value>
    </property>
View Code

yarn-site.xml數據庫

    <!-- Reducer獲取數據的方式 -->
    <property>
            <name>yarn.nodemanager.aux-services</name>
            <value>mapreduce_shuffle</value>
    </property>

    <!-- 指定YARN的ResourceManager的地址 -->
    <property>
        <name>yarn.resourcemanager.hostname</name>
        <value>hadoop102</value>
    </property>
    <!-- 任務歷史服務 -->
    <property> 
        <name>yarn.log.server.url</name> 
        <value>http://hadoop101:19888/jobhistory/logs/</value> 
    </property>
View Code

更名爲mapred-site.xml

    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
    <!-- 配置 MapReduce JobHistory Server 地址 ,默認端口10020 -->
    <property>
        <name>mapreduce.jobhistory.address</name>
        <value>hadoop101:10020</value>
    </property>

    <!-- 配置 MapReduce JobHistory Server web ui 地址, 默認端口19888 -->
    <property>
        <name>mapreduce.jobhistory.webapp.address</name>
        <value>hadoop101:19888</value>
    </property>    
View Code

oozie是經過歷史服務器進行監控工做單元
服務地址端口10020,web頁面的端口是19888

slaves

hadoop101
hadoop102
hadoop103
View Code

啓動hadoop集羣:
[kris@hadoop101 hadoop-2.5.0-cdh5.3.6]$bin/hdfs namenode -format ##若是出現reformat就點擊N
[kris@hadoop101 hadoop-2.5.0-cdh5.3.6]$sbin/start-dfs.sh
[kris@hadoop102 hadoop-2.5.0-cdh5.3.6]$sbin/start-yarn.sh
[kris@hadoop101 hadoop-2.5.0-cdh5.3.6]$sbin/mr-jobhistory-daemon.sh start historyserver

部署Oozie

1. 解壓Oozie   [kris@hadoop101 software]$ tar -zxvf /opt/software/oozie-4.0.0-cdh5.3.6.tar.gz -C /opt/module 2. 在oozie根目錄下解壓oozie-hadooplibs-4.0.0-cdh5.3.6.tar.gz;由於它上級目錄與這個目錄同樣,它就會直接把hadooplibs解壓到根目錄;   [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ tar -zxvf oozie-hadooplibs-4.0.0-cdh5.3.6.tar.gz -C ../
    也能夠: tar -zxf oozie-hadooplibs-4.0.0-cdh5.3.6.tar.gz 
           mv hadooplibs/ ../
  完成後Oozie目錄下會出現hadooplibs目錄。 3. 在Oozie目錄下建立libext目錄   [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ mkdir libext/ 4. 拷貝依賴的Jar包;jar包、mysql驅動類、js框架放到libext目錄下;   1)將hadooplibs裏面的jar包,拷貝到libext目錄下:   [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ cp -ra hadooplibs/hadooplib-2.5.0-cdh5.3.6.oozie-4.0.0-cdh5.3.6/* libext/   2)拷貝Mysql驅動包到libext目錄下:   [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ cp -a /opt/software/mysql-connector-java-5.1.27/mysql-connector-java-5.1.27-bin.jar ./libext/   3)將ext-2.2.zip拷貝到libext/目錄下   ext是一個js框架,用於展現oozie前端頁面:   [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ cp -a /opt/software/ext-2.2.zip libext/
5. 修改Oozie配置文件 oozie-site.xml 屬性:oozie.service.JPAService.jdbc.driver 屬性值:com.mysql.jdbc.Driver 解釋:JDBC的驅動 屬性:oozie.service.JPAService.jdbc.url 屬性值:jdbc:mysql://hadoop101:3306/oozie 解釋:oozie所需的數據庫地址 屬性:oozie.service.JPAService.jdbc.username 屬性值:root 解釋:數據庫用戶名 屬性:oozie.service.JPAService.jdbc.password 屬性值:123456 解釋:數據庫密碼 屬性:oozie.service.HadoopAccessorService.hadoop.configurations 屬性值:*=/opt/module/cdh/hadoop-2.5.0-cdh5.3.6/etc/hadoop 解釋:讓Oozie引用Hadoop的配置文件 6. 在Mysql中建立Oozie的數據庫 進入Mysql並建立oozie數據庫: $ mysql -uroot -p123456 mysql> create database oozie; 七、初始化Oozie 1)上傳Oozie目錄下的yarn.tar.gz文件到HDFS: oozie會自動解壓上傳到hdfs [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozie-setup.sh sharelib create -fs hdfs://hadoop101:8020 -locallib oozie-sharelib-4.0.0-cdh5.3.6-yarn.tar.gz 執行成功以後,去50070檢查對應目錄有沒有文件生成。 2)建立oozie.sql文件 ;它會生成一個.sql文件,若是不指定它會在tmp那個目錄建立.sql文件 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/ooziedb.sh create -sqlfile oozie.sql -run setting CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m" 3)打包項目,生成war包 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozie-setup.sh prepare-war setting CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m"
New Oozie WAR file with added 'ExtJS library, JARs' at /opt/module/oozie-4.0.0-cdh5.3.6/oozie-server/webapps/oozie.war
4) Oozie的啓動與關閉 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozied.sh start [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozied.sh stop

訪問Oozie的Web頁面

http://hadoop101:11000/oozie/

若是沒有oozied.sh 起來,把oozied.pid文件給刪掉,從新起下; [kris@hadoop101 temp]$ pwd /opt/module/oozie-4.0.0-cdh5.3.6/oozie-server/temp [kris@hadoop101 temp]$ ll 總用量 8 drwxrwxr-x. 3 kris kris 4096 3月 2 10:52 oozie-kris4439005802986311795.dir -rw-rw-r--. 1 kris kris 5 3月 2 10:52 oozie.pid -rwxr-xr-x. 1 kris kris 0 11月 14 2014 safeToDelete.tmp

 

Oozie的使用

Oozie調度shell腳本

1)建立工做目錄 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ mkdir -p oozie-apps/shell 2)在oozie-apps/shell目錄下建立兩個文件——job.properties和workflow.xml文件 [kris@hadoop101 shell]$ touch workflow.xml [kris@hadoop101 shell]$ touch job.properties 3)編輯job.properties和workflow.xml文件

job.properties

#HDFS地址
nameNode=hdfs://hadoop101:8020
#ResourceManager地址
jobTracker=hadoop102:8032
#隊列名稱
queueName=default
examplesRoot=oozie-apps
oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/shell
View Code

workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf">
<!--開始節點-->
<start to="shell-node"/>
<!--動做節點-->
<action name="shell-node">
    <!--shell動做-->
    <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>/opt/module/d</argument>
        <capture-output/>
    </shell>
    <ok to="end"/>
    <error to="fail"/>
</action>
<!--kill節點-->
<kill name="fail">
    <message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<!--結束節點-->
<end name="end"/>
</workflow-app>
View Code

 job-tracker是hadoop1.x 中ResourceManager

oozie.coord.application.path:${nameNode}/user/${user.name}/${examplesRoot}/shell 這個路徑是這兩個配置文件要上傳到HDFS上的路徑

              hdfs://hadoop101:8020/user/kris/oozie-apps/shell

[kris@hadoop101 shell]$ ll 總用量 8 -rw-rw-r--. 1 kris kris 226 3月 2 18:36 job.properties -rw-rw-r--. 1 kris kris 900 3月 2 18:37 workflow.xml  [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ /opt/module/cdh/hadoop-2.5.0-cdh5.3.6/bin/hadoop fs -put oozie-apps/ /user/kris 19/03/02 18:41:08 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozie job -oozie http://hadoop101:11000/oozie -config oozie-apps/shell/job.properties -run job: 0000000-190302183330904-oozie-kris-W

DAG有向無環圖,沒有造成死循環
  start

  ↓
  action → kill

  ↓
  end

顏色是綠色才表明成功,不然就是出錯了;

殺死某個任務
[kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozie job -oozie http://hadoop101:11000/oozie -kill 0000000-190302183330904-oozie-kris-W

 

Oozie邏輯調度執行多個Job| 兩個工做單元

job.properties

nameNode=hdfs://hadoop101:8020
jobTracker=hadoop102:8032
queueName=default
examplesRoot=oozie-apps
oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/shells
View Code

workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf">
    <start to="p1-shell-node"/>
    <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>/opt/module/d1</argument>
            <capture-output/>
        </shell>
        <ok to="p2-shell-node"/>
        <error to="fail"/>
    </action>

    <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>/opt/module/d2</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>
View Code

 

上傳任務配置 [kris@hadoop101 hadoop-2.5.0-cdh5.3.6]$ /opt/module/cdh/hadoop-2.5.0-cdh5.3.6/bin/hadoop fs -put oozie-apps/shells/ /user/kris/oozie-apps19/03/02 19:06:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 執行任務 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozie job -oozie http://hadoop101:11000/oozie -config oozie-apps/shells/job.properties -run job: 0000001-190302183330904-oozie-kris-W

Oozie調用有分支的任務| 4個工做單元

fock和join的用法見官網:http://oozie.apache.org/docs/4.0.0/WorkflowFunctionalSpec.html#a3.1.5_Fork_and_Join_Control_Nodes 

             ---to-->p2-shell-node 

p1-shell-node --to-->forking                                 ---它倆 --join---to -->p4-shell-node

              ---to-->p3-shell-node

 

job.properties

nameNode=hdfs://hadoop101:8020
jobTracker=hadoop102:8032
queueName=default
examplesRoot=oozie-apps
oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/xshell
View Code

workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf">
    <start to="p1-shell-node"/>
    <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>/opt/module/d1</argument>
            <capture-output/>
        </shell>
        <ok to="forking"/>
        <error to="fail"/>
    </action>

    <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>/opt/module/d2</argument>
            <capture-output/>
        </shell>
        <ok to="joining"/>
        <error to="fail"/>
    </action>
    
    <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>/opt/module/d3</argument>
            <capture-output/>
        </shell>
        <ok to="joining"/>
        <error to="fail"/>
    </action>
    <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>/opt/module/d4</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>
View Code
上傳 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ /opt/module/cdh/hadoop-2.5.0-cdh5.3.6/bin/hadoop fs -put oozie-apps/xshell/ /user/kris/oozie-apps 19/03/03 14:18:33 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 執行任務 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozie job -oozie http://hadoop101:11000/oozie -config oozie-apps/xshell/job.properties -run job: 0000011-190303122200913-oozie-kris-W

 

Oozie調度MapReduce任務

oozie.examples.tar.gz包:即全部的案例:

[kris@hadoop101 apps]$ ll 總用量 88 drwxr-xr-x. 3 kris kris 4096 3月 2 19:19 aggregator drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 bundle drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 cron ##新的 drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 cron-schedule ##配置定時的,適合linux drwxr-xr-x. 3 kris kris 4096 3月 2 19:19 custom-main drwxr-xr-x. 3 kris kris 4096 3月 2 19:19 datelist-java-main drwxr-xr-x. 3 kris kris 4096 3月 2 19:19 demo drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 distcp drwxr-xr-x. 3 kris kris 4096 3月 2 19:19 hadoop-el drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 hcatalog drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 hive drwxr-xr-x. 3 kris kris 4096 3月 2 19:19 java-main #java類 drwxr-xr-x. 3 kris kris 4096 3月 2 19:19 map-reduce # drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 no-op drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 pig drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 shell # drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 sla drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 sqoop # drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 sqoop-freeform drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 ssh drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 streaming drwxr-xr-x. 2 kris kris 4096 3月 2 19:19 subwf [kris@hadoop101 apps]$ pwd /opt/module/oozie-4.0.0-cdh5.3.6/examples/apps
[kris@hadoop101 map-reduce]$ ll 總用量 20 -rw-r--r--. 1 kris kris 1012 7月 29 2015 job.properties -rw-r--r--. 1 kris kris 1028 7月 29 2015 job-with-config-class.properties #帶有配置類的;以前寫的那三個mapreduce類,Driver是輸入輸出路徑以及k,v格式類型;roozie調用MR時有兩種配置:
一種是專門寫一個配置類,oozie提供好了接口到時去繼承它就能夠,實現裏邊的方法;
另一種是直接在workflow.xml文件中配置;咱們採用第二種方式; drwxrwxr
-x. 2 kris kris 4096 3月 2 19:19 lib #放jar包; -rw-r--r--. 1 kris kris 2274 7月 29 2015 workflow-with-config-class.xml -rw-r--r--. 1 kris kris 2559 7月 29 2015 workflow.xml

 

1) 拷貝官方模板到oozie-apps [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ cp -r /opt/module/oozie-4.0.0-cdh5.3.6/examples/apps/map-reduce/ oozie-apps/ [kris@hadoop101 hadoop-2.5.0-cdh5.3.6]$ bin/hadoop fs -mkdir /input 19/03/02 19:34:02 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 2) 測試一下wordcount在yarn中的運行 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ /opt/module/cdh/hadoop-2.5.0-cdh5.3.6/bin/yarn jar /opt/module/cdh/hadoop-2.5.0-cdh5.3.6/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.0-cdh5.3.6.jar wordcount /input/ /output/ 19/03/02 19:34:32 INFO mapreduce.Job: map 0% reduce 100% 19/03/02 19:34:33 INFO mapreduce.Job: Job job_1551522372459_0005 completed successfully 19/03/02 19:34:33 INFO mapreduce.Job: Counters: 38 ########下面是另一種:
  建立輸入文件wordcount.txt [kris@hadoop101 hadoop
-2.5.0-cdh5.3.6]$ vim wordcount.txt java java java kafka kafka oozie   把它上傳到hdfs上 [kris@hadoop101 hadoop-2.5.0-cdh5.3.6]$ bin/hadoop fs -put wordcount.txt /   執行下官方提供的wordcount的jar包 [kris@hadoop101 hadoop-2.5.0-cdh5.3.6]$ bin/yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.0-cdh5.3.6.jar wordcount /wordcount.txt /output
  把官方案例的wordcount的jar包放在lib下面 [kris@hadoop101 lib]$ ll 總用量
28 -rw-r--r--. 1 kris kris 24707 3月 3 14:49 oozie-examples-4.0.0-cdh5.3.6.jar [kris@hadoop101 lib]$ rm -rf oozie-examples-4.0.0-cdh5.3.6.jar [kris@hadoop101 lib]$ cp /opt/module/cdh/hadoop-2.5.0-cdh5.3.6/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.0-cdh5.3.6.jar ./ [kris@hadoop101 lib]$ ll 總用量 272 -rw-r--r--. 1 kris kris 275958 3月 3 14:54 hadoop-mapreduce-examples-2.5.0-cdh5.3.6.jar [kris@hadoop101 lib]$

 

3) 配置map-reduce任務的job.properties以及workflow.xml

 

job.properties

nameNode=hdfs://hadoop101:8020
jobTracker=hadoop102:8032
queueName=default
examplesRoot=oozie-apps

oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/map-reduce/workflow.xml
outputDir=map-reduce
View Code

workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.2" name="map-reduce-wf">
    <start to="mr-node"/>
    <action name="mr-node">
        <map-reduce>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <prepare>
                <delete path="${nameNode}/output/"/>
            </prepare>
            <configuration>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queueName}</value>
                </property>
                <!-- 配置調度MR任務時,使用新的API -->
                <property>
                    <name>mapred.mapper.new-api</name>
                    <value>true</value>
                </property>

                <property>
                    <name>mapred.reducer.new-api</name>
                    <value>true</value>
                </property>

                <!-- 指定Job Key輸出類型 -->
                <property>
                    <name>mapreduce.job.output.key.class</name>
                    <value>org.apache.hadoop.io.Text</value>
                </property>

                <!-- 指定Job Value輸出類型 -->
                <property>
                    <name>mapreduce.job.output.value.class</name>
                    <value>org.apache.hadoop.io.IntWritable</value>
                </property>

                <!-- 指定輸入路徑 -->
                <property>
                    <name>mapred.input.dir</name>
                    <value>/wordcount.txt</value>
                </property>

                <!-- 指定輸出路徑 -->
                <property>
                    <name>mapred.output.dir</name>
                    <value>/output/</value>
                </property>

                <!-- 指定Map類 -->
                <property>
                    <name>mapreduce.job.map.class</name>
                    <value>org.apache.hadoop.examples.WordCount$TokenizerMapper</value>
                </property>

                <!-- 指定Reduce類 -->
                <property>
                    <name>mapreduce.job.reduce.class</name>
                    <value>org.apache.hadoop.examples.WordCount$IntSumReducer</value>
                </property>
            </configuration>
        </map-reduce>
        <ok to="end"/>
        <error to="fail"/>
    </action>
    <kill name="fail">
        <message>Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end"/>
</workflow-app>
View Code

 <delete path="${nameNode}/output/"/> ##跑在mapreduce中輸入路徑不能存在;即把output輸入文件給刪掉

#mapred是不對的,老版的;能夠去官網有新舊的對比;也能夠直接看wordcount的源碼看設置的什麼屬性

若是map端輸出的k v和最終輸出的k v類型是同樣的,配置一個就能夠了

#mapreduce的個數不指定,讓它本身決定;看它的源碼反編譯,jar包反編譯就能夠得出它的value

                <property>
                    <name>mapred.map.tasks</name> ##能夠不指定
                    <value>1</value>
                </property>
 5) 上傳配置好的文件夾到HDFS [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ /opt/module/cdh/hadoop-2.5.0-cdh5.3.6/bin/hdfs dfs -put oozie-apps/map-reduce/ /user/kris/oozie-apps 6) 執行任務 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozie job -oozie http://hadoop101:11000/oozie -config oozie-apps/map-reduce/job.properties -run job: 0000000-190302224616759-oozie-kris-W

 

 

Oozie定時任務/循環任務

目標:Coordinator週期性調度任務

分步實現:

1)  配置Linux時區以及時間服務器

2)  檢查系統當前時區:

# date -R

 

[kris@hadoop101 hadoop-2.5.0-cdh5.3.6]$ date -R Sun, 03 Mar 2019 12:58:37 +0800 [kris@hadoop102 module]$ date -R Sun, 03 Mar 2019 12:58:02 +0800 [kris@hadoop103 ~]$ date -R Sun, 03 Mar 2019 12:58:56 +0800

 

 配置oozie-site.xml文件; 注:該屬性去oozie-default.xml中找到便可 [kris@hadoop101 conf]$ vim oozie-site.xml ;將默認的UTC改爲GMT+0800 <property> <name>oozie.processing.timezone</name> <value>GMT+0800</value> <description> 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. </description> </property> 修改js框架中的關於時間設置的代碼 function getTimeZone() { Ext.state.Manager.setProvider(new Ext.state.CookieProvider()); return Ext.state.Manager.get("TimezoneId","GMT+0800"); } 重啓oozie服務,並重啓瀏覽器(必定要注意清除緩存) [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozied.sh stop [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozied.sh start 拷貝官方模板配置定時任務\ [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ cp -r examples/apps/cron oozie-apps/ 修改模板job.properties和coordinator.xml以及workflow.xml

 job.properties

nameNode=hdfs://hadoop101:8020
jobTracker=hadoop102:8032
queueName=default
examplesRoot=oozie-apps

oozie.coord.application.path=${nameNode}/user/${user.name}/${examplesRoot}/cron
#start:必須設置爲將來時間,不然任務失敗
start=2019-03-03T12:33+0800
end=2019-03-03T12:53+0800
workflowAppUri=${nameNode}/user/${user.name}/${examplesRoot}/cron
EXEC=p1.sh
View Code

coordinator.xml

<coordinator-app name="cron-coord" frequency="${coord:minutes(5)}" start="${start}" end="${end}" timezone="GMT+0800" xmlns="uri:oozie:coordinator:0.2">
<action>
    <workflow>
        <app-path>${workflowAppUri}</app-path>
        <configuration>
            <property>
                <name>jobTracker</name>
                <value>${jobTracker}</value>
            </property>
            <property>
                <name>nameNode</name>
                <value>${nameNode}</value>
            </property>
            <property>
                <name>queueName</name>
                <value>${queueName}</value>
            </property>
        </configuration>
    </workflow>
</action>
</coordinator-app>
View Code

workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.5" name="one-op-wf">
<start to="shell-node"/>
  <action name="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>${EXEC}</exec>
          <file>/user/kris/oozie-apps/cron/${EXEC}#${EXEC}</file>
          <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>
View Code

其中 #${EXEC}是給起別名; 須要自定義配置的:frequency start end timezone;定時調度的workflow:路徑hdfs上的

workflowAppUri 這個路徑是放workflow.xml文件和job.properties的HDFS上的路徑

<!--要執行的腳本的寫法-->

<exec>p1.sh</exec>
  <file>/opt/module/oozie-apps/cron/p1.sh</file> #hdfs上的路徑
<capture-output/>
p1.sh也能夠本身建立lib目錄下就不需寫路徑了

yarn經過container收集日誌;能夠查看它的log日誌

[kris@hadoop101 cron]$ vim p1.sh #這裏要寫絕對路徑 #!/bin/bash date >> /opt/module/p1.sh 上傳配置 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ /opt/module/cdh/hadoop-2.5.0-cdh5.3.6/bin/hadoop fs -put oozie-apps/cron/ /user/kris/oozie-apps 啓動任務 [kris@hadoop101 oozie-4.0.0-cdh5.3.6]$ bin/oozie job -oozie http://hadoop101:11000/oozie -config oozie-apps/cron/job.properties -run
job: 0000002-190303122200913-oozie-kris-C 能夠看到 [kris@hadoop102 module]$ cat p1.sh 2019年 03月 03日 星期日 12:32:14 CST 2019年 03月 03日 星期日 12:33:09 CST 2019年 03月 03日 星期日 12:37:07 CST

 

hive的配置

[kris@hadoop101 hive]$ ll 總用量 12 -rw-r--r--. 1 kris kris 1000 7月 29 2015 job.properties -rw-r--r--. 1 kris kris 939 7月 29 2015 script.q -rw-r--r--. 1 kris kris 2003 7月 29 2015 workflow.xml [kris@hadoop101 hive]$ pwd /opt/module/oozie-4.0.0-cdh5.3.6/examples/apps/hive
[kris@hadoop101 hive]$ vim script.q 
CREATE EXTERNAL TABLE test (a INT) STORED AS TEXTFILE LOCATION '${INPUT}';
INSERT OVERWRITE DIRECTORY '${OUTPUT}' SELECT * FROM test;
[kris@hadoop101 hive]$ vim workflow.xml
<script>script.q</script>...
相關文章
相關標籤/搜索