oozie时间设置
配置oozie-site.xml文件,在oozie-default.xml中可找到。
<property><name>oozie.processing.timezone</name><value>GMT+0800</value><!-- <value>UTC</value> --><description>Oozie server timezone. Valid values are UTC and GMT(+/-)####, for example 'GMT+0530' would be Indiatimezone. All dates parsed and genered dates by Oozie Coordinator/Bundle will be done in the specifiedtimezone. The default value of 'UTC' should not be changed under normal circumtances. If for any reasonis changed, note that GMT(+/-)#### timezones do not observe DST changes.</description></property>
修改js框架中的关于时间设置的代码,位于oozie/oozie-server/webapps/oozie/oozie-console.js 17行。
function getTimeZone() {Ext.state.Manager.setProvider(new Ext.state.CookieProvider());// return Ext.state.Manager.get("TimezoneId","GMT");return Ext.state.Manager.get("TimezoneId","GMT+0800");}
重启oozie服务,并重启浏览器(清除缓存)。
$ bin/oozied.sh stop$ bin/oozied.sh start
参考
- 日期时间、频率和时间段表示 - [http://oozie.apache.org/docs/4.0.0/CoordinatorFunctionalSpec.html#a4._Datetime_Frequency_and_Time-Period_Representation](http://oozie.apache.org/docs/4.0.0/CoordinatorFunctionalSpec.html#a4._Datetime_Frequency_and_Time-Period_Representation)
按时间间隔循环调度shell脚本
拷贝官方模板配置定时任务。
本次实践示例,未同步linux时间,时区未改,以当前时间跟时区来设定任务。
本次实践示例,为对oozie做修改,oozie.processing.timezone为默认值UTC,js文件内容也没做修改。 ```bash $ cp -r examples/apps/cron oozie-apps/ $ ls oozie-apps/ cron input-data map-reduce shell shell-script shell-scripts $ ls oozie-apps/cron/ coordinator.xml job.properties workflow.xml
$ date —utc # 以UTC打印当前时间 Wed Apr 22 06:52:52 UTC 2020 $ date # 当前时区PDT,显示时间 GMT/UTC -0700 Tue Apr 21 23:52:53 PDT 2020 $ date -R # 以RFC 2822格式输出日期和时间 Tue, 21 Apr 2020 23:52:55 -0700
- GMT时间- 格林威治标准时间(Greenwich Mean Time,简称G.M.T)- UTC时间- 世界协调时间 (Coordinated Universal Time)- 又称世界标准时间、世界统一时间,以格林威治时间GMT为准- UTC和GMT时间是几乎等同的<br /><a name="qIy0Z"></a>## job.propertiesOozie在固定时区中处理协调器作业,该时区非DST(通常是UTC),这个时区被称为“Oozie processing timezone”,Oozie处理时区。<br />Oozie处理时区用于解析协调器作业的启动/结束时间、作业暂停时间和数据集的初始实例。而且,所有的协调器数据集的实例URI模板都被解析为Oozie处理时区中的一个datetime。<br />协调程序应用程序中使用的所有日期时间和协调程序应用程序的作业参数必须在Oozie处理时区中指定。如果Oozie处理时区是UTC,那么限定符就是`Z`。如果Oozie处理时区不是UTC,那么限定符必须是GMT offset `(+/-)####` 。<br />例如,UTC 中的日期时间是 `2012-08-12T00:00Z` ,GMT+5:30 中的日期时间是 `2012-08-12T05:30+0530` 。下例中,未作oozie处理时区的配置 `oozie.processing.timezone` 属性值为默认的 `UTC` ,那系统时间以UTC为参照系, `date -u` 显示当前时间 `Wed Apr 22 07:33:11 UTC 2020` ,那么 `start` 的值需要大于该值,且使用限定符 `Z` 。
nameNode=hdfs://192.168.32.130:8020 jobTracker=192.168.32.130:8032 queueName=default examplesRoot=oozie-apps
oozie.coord.application.path=${nameNode}/user/${user.name}/${examplesRoot}/cron
start 需设为未来时间,否则任务失败
Wed Apr 22 07:33:11 UTC 2020
start=2020-04-22T07:36Z end=2020-04-22T07:42Z
workflowAppUri=${nameNode}/user/${user.name}/${examplesRoot}/cron
EXEC=log.sh
<a name="x8V1r"></a>## log.sh```shell#!/bin/bashecho "Hello! It's time to run. [`date`]" >> `p=/tmp/oozie;[[ ! -d "${p}" ]] && mkdir -p ${p};echo ${p}/coordinator_wf.log`
coordinator.xml
- 修改执行频率,frequency=”${coord:minutes(5)}”
- 时区以
oozie-site.xml或oozie-default.xml的oozie.processing.timezone属性值为准。<coordinator-app name="cron-coord" frequency="${coord:minutes(5)}"start="${start}" end="${end}" timezone="UTC"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>
workflow.xml
<workflow-app xmlns="uri:oozie:workflow:0.5" name="one-op-wf"><start to="action1"/><action name="action1"><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>${EXEC}#${EXEC}</file></shell><ok to="end"/><error to="end"/></action><end name="end"/></workflow-app>
执行
$ ~/Documents/hadoop/bin/hadoop fs -put oozie-apps/cron oozie-apps/$ ~/Documents/hadoop/bin/hadoop fs -ls oozie-apps/cron/ # 当前时区为GMT-0700Found 3 items-rw-r--r-- 1 jack supergroup 1595 2020-04-21 23:56 oozie-apps/cron/coordinator.xml-rw-r--r-- 1 jack supergroup 1179 2020-04-21 23:56 oozie-apps/cron/job.properties-rw-r--r-- 1 jack supergroup 1449 2020-04-21 23:56 oozie-apps/cron/workflow.xml$ export OOZIE_URL="http://192.168.32.130:11000/oozie"$ bin/oozie job -config oozie-apps/cron/job.properties -runjob: 0000010-200420185350972-oozie-jack-C$ bin/oozie job -info 0000010-200420185350972-oozie-jack-CJob ID : 0000010-200420185350972-oozie-jack-C------------------------------------------------------------------------------------------------------------------------------------Job Name : cron-coordApp Path : hdfs://192.168.32.130:8020/user/jack/oozie-apps/cronStatus : RUNNINGStart Time : 2020-04-22 07:36 GMTEnd Time : 2020-04-22 07:42 GMTPause Time : -Concurrency : 1------------------------------------------------------------------------------------------------------------------------------------ID Status Ext ID Err Code Created Nominal Time0000010-200420185350972-oozie-jack-C@1 WAITING - - 2020-04-22 07:35 GMT 2020-04-22 07:36 GMT------------------------------------------------------------------------------------------------------------------------------------0000010-200420185350972-oozie-jack-C@2 WAITING - - 2020-04-22 07:35 GMT 2020-04-22 07:41 GMT------------------------------------------------------------------------------------------------------------------------------------$ cat /tmp/oozie/coordinator_wf.log # 输出结果为空$ cat /tmp/oozie/coordinator_wf.log # 执行结束,且成功Hello! It's time to run. [Wed Apr 22 00:36:20 PDT 2020]Hello! It's time to run. [Wed Apr 22 00:41:11 PDT 2020]
可以看到,自动设置了2个任务,按5分钟的时间间隔分割。
