oozie案例——自定义coordinator

1.统一时区和同步系统时间
(1)切换本机时区并同步时间

#切换时区
sudo rm -rf /etc/localtime
sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

#同步时间前需要先停掉本机的ntpd服务
sudo service ntpd status
sudo service ntpd stop

#同步时间
sudo ntpdate 0.asia.pool.ntp.org

(2)修改oozie-site.xml中时区

<!--在文件最后添加-->
<property>
<name>oozie.processing.timezone</name>
<value>GMT+0800</value>
</property>

(3)修改oozie-server/webapps/oozie/oozie-console.js时区

function getTimeZone() {
  Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
  return Ext.state.Manager.get("TimezoneId","GMT+0800");
}

(4)重启oozied服务

bin/oozied.sh stop
bin/oozied.sh start

 

2. 相关运行命令

#运行一个应用:
bin/oozie job -oozie http://hadoop-1:11000/oozie -config examples/apps/map-reduce/job.properties -run

#杀掉一个job
bin/oozie job -oozie http://hadoop-1:11000/oozie  -kill 0000001-160702224410648-oozie-beif-W

#查看job的日志信息
bin/oozie job -oozie http://hadoop-1:11000/oozie -log 0000001-160702224410648-oozie-beif-W

#查看job的信息
bin/oozie job -oozie http://hadoop-1:11000/oozie -info 0000001-160702224410648-oozie-beif-W

 

3. 定义job.properties

nameNode=hdfs://hadoop-1:9000
jobTracker=hadoop-1:8032
queueName=default
ShellRoot=cron

oozie.coord.application.path=${nameNode}/user/${user.name}/${ShellRoot}
start=2016-07-03T18:08+0800
end=2016-07-10T01:00+0800
workflowAppUri=${nameNode}/user/${user.name}/${ShellRoot}
EXEC=free.sh

 

4. 定义workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-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/hadoop/free-shell/${EXEC}#${EXEC}</file>
        </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>

 

5. 定义coordinator.xml

<coordinator-app name="cron-coord" frequency="*/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>

 

6. free.sh定义shell脚本

#!/bin/bash

/usr/bin/free -m >> /tmp/free.log
/bin/date >> /tmp/free.log

 

posted @ 2016-07-07 14:41  咱们屯里的人  阅读(687)  评论(0编辑  收藏  举报