版本信息
阿里云 E-MapReduce 在 2.0.0 及之后的版本中提供了对 Oozie 的支持,如果需要在集群中使用 Oozie,请确认集群的版本不低于 2.0.0。
准备工作
在集群建立出来之后,需要打通 ssh 隧道,详细步骤请参考:
https://help.aliyun.com/document_detail/28187.html
这里以 MAC 环境为例,使用 Chrome 浏览器实现端口转发(假设集群 master 节点公网 IP 为 xx.xx.xx.xx):
登录到 master 节点。[backcolor=transparent]ssh root@xx[backcolor=transparent].[backcolor=transparent]xx[backcolor=transparent].[backcolor=transparent]xx[backcolor=transparent].[backcolor=transparent]xx
输入密码。
查看本机的 id_rsa.pub 内容(注意在本机执行,不要在远程的 master 节点上执行)。
- [backcolor=transparent]cat [backcolor=transparent]~[backcolor=transparent]/.ssh/[backcolor=transparent]id_rsa[backcolor=transparent].[backcolor=transparent]pub
将本机的 id_rsa.pub 内容写入到远程 master 节点的 ~/.ssh/authorized_keys 中(在远端 master 节点上执行)。
- [backcolor=transparent]mkdir [backcolor=transparent]~[backcolor=transparent]/.ssh/
- [backcolor=transparent]vim [backcolor=transparent]~[backcolor=transparent]/.ssh/[backcolor=transparent]authorized_keys
然后将步骤 2 中看到的内容粘贴进来,现在应该可以直接使用 ssh
root@xx.xx.xx.xx 免密登录 master 节点了。
在本机执行以下命令进行端口转发。
- [backcolor=transparent]ssh [backcolor=transparent]-[backcolor=transparent]i [backcolor=transparent]~[backcolor=transparent]/.ssh/[backcolor=transparent]id_rsa [backcolor=transparent]-[backcolor=transparent]ND [backcolor=transparent]8157[backcolor=transparent] root@xx[backcolor=transparent].[backcolor=transparent]xx[backcolor=transparent].[backcolor=transparent]xx[backcolor=transparent].[backcolor=transparent]xx
启动 Chrome(在本机新开 terminal 执行)。
- [backcolor=transparent]/Applications/[backcolor=transparent]Google[backcolor=transparent]\ [backcolor=transparent]Chrome[backcolor=transparent].[backcolor=transparent]app[backcolor=transparent]/[backcolor=transparent]Contents[backcolor=transparent]/[backcolor=transparent]MacOS[backcolor=transparent]/[backcolor=transparent]Google[backcolor=transparent]\ [backcolor=transparent]Chrome[backcolor=transparent] [backcolor=transparent]--[backcolor=transparent]proxy[backcolor=transparent]-[backcolor=transparent]server[backcolor=transparent]=[backcolor=transparent]"socks5://localhost:8157"[backcolor=transparent] [backcolor=transparent]--[backcolor=transparent]host[backcolor=transparent]-[backcolor=transparent]resolver[backcolor=transparent]-[backcolor=transparent]rules[backcolor=transparent]=[backcolor=transparent]"MAP * 0.0.0.0 , EXCLUDE localhost"[backcolor=transparent] [backcolor=transparent]--[backcolor=transparent]user[backcolor=transparent]-[backcolor=transparent]data[backcolor=transparent]-[backcolor=transparent]dir[backcolor=transparent]=/[backcolor=transparent]tmp
访问 Oozie UI 页面
在进行端口转发的 Chrome 浏览器中访问:xx.xx.xx.xx:11000/oozie,localhost:11000/oozie 或者内网 ip:11000/oozie。
提交workflow作业
运行 Oozie 需要先安装 Oozie 的sharelib:
https://oozie.apache.org/docs/4.2.0/WorkflowFunctionalSpec.html#ShareLib
在 E-MapReduce 集群中,默认给 Oozie 用户安装了 sharelib,即如果使用 Oozie 用户来提交 workflow 作业,则不需要再进行 sharelib 的安装。
由于开启 HA的集群和没有开启 HA 的集群,访问 NameNode 和 ResourceManager 的方式不同,在提交 oozie workflow job 的时候,job.properties 文件中需要指定不同的 NameNode 和 JobTracker (ResourceManager)。具体如下:
非 HA 集群
-
[backcolor=transparent]
nameNode[backcolor=transparent]
=[backcolor=transparent]
hdfs[backcolor=transparent]
:[backcolor=transparent]
//emr-header-1:9000
- [backcolor=transparent]jobTracker[backcolor=transparent]=[backcolor=transparent]emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent]:[backcolor=transparent]8032
HA 集群
-
[backcolor=transparent]
nameNode[backcolor=transparent]
=[backcolor=transparent]
hdfs[backcolor=transparent]
:[backcolor=transparent]
//emr-cluster
- [backcolor=transparent]jobTracker[backcolor=transparent]=[backcolor=transparent]rm1[backcolor=transparent],[backcolor=transparent]rm2
下面操作示例中,已经针对是否是 HA 集群配置好了,即样例代码不需要任何修改即可以直接运行。关于 workflow 文件的具体格式,请参考 Oozie 官方文档:
https://oozie.apache.org/docs/4.2.0/。
在非 HA 集群上提交 workflow 作业
登录集群的主 master 节点。[backcolor=transparent]ssh root@master[backcolor=transparent]公网[backcolor=transparent]Ip
下载示例代码。
- [backcolor=transparent][[backcolor=transparent]root@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] [backcolor=transparent]~]#[backcolor=transparent] su oozie
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] root[backcolor=transparent]][backcolor=transparent]$ cd [backcolor=transparent]/[backcolor=transparent]tmp
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] tmp[backcolor=transparent]][backcolor=transparent]$ wget http[backcolor=transparent]:[backcolor=transparent]//emr-sample-projects.oss-cn-hangzhou.aliyuncs.com/oozie-examples/oozie-examples.zip
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] tmp[backcolor=transparent]][backcolor=transparent]$ unzip oozie[backcolor=transparent]-[backcolor=transparent]examples[backcolor=transparent].[backcolor=transparent]zip
将 Oozie workflow 代码同步到 hdfs 上。
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] tmp[backcolor=transparent]][backcolor=transparent]$ hadoop fs [backcolor=transparent]-[backcolor=transparent]copyFromLocal examples[backcolor=transparent]/ /[backcolor=transparent]user[backcolor=transparent]/[backcolor=transparent]oozie[backcolor=transparent]/[backcolor=transparent]examples
提交 Oozie workflow 样例作业。
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] tmp[backcolor=transparent]][backcolor=transparent]$ $OOZIE_HOME[backcolor=transparent]/[backcolor=transparent]bin[backcolor=transparent]/[backcolor=transparent]oozie job [backcolor=transparent]-[backcolor=transparent]config examples[backcolor=transparent]/[backcolor=transparent]apps[backcolor=transparent]/[backcolor=transparent]map[backcolor=transparent]-[backcolor=transparent]reduce[backcolor=transparent]/[backcolor=transparent]job[backcolor=transparent].[backcolor=transparent]properties [backcolor=transparent]-[backcolor=transparent]run
执行成功之后,会返回一个 jobId,类似:
- [backcolor=transparent]job[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]0000000[backcolor=transparent]-[backcolor=transparent]160627195651086[backcolor=transparent]-[backcolor=transparent]oozie[backcolor=transparent]-[backcolor=transparent]oozi[backcolor=transparent]-[backcolor=transparent]W
访问 Oozie UI 页面,可以看到刚刚提交的 Oozie workflow job。
在 HA 集群上提交 workflow 作业
登录 HA 集群的主 master 节点。[backcolor=transparent]ssh root@[backcolor=transparent]主[backcolor=transparent]master[backcolor=transparent]公网[backcolor=transparent]Ip
可以通过是否能访问 Oozie UI 来判断哪个 master 节点是当前的主 master 节点, Oozie server 服务默认是启动在主 master 节点 xx.xx.xx.xx:11000/oozie。
下载 HA 集群的示例代码。
- [backcolor=transparent][[backcolor=transparent]root@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] [backcolor=transparent]~]#[backcolor=transparent] su oozie
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] root[backcolor=transparent]][backcolor=transparent]$ cd [backcolor=transparent]/[backcolor=transparent]tmp
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] tmp[backcolor=transparent]][backcolor=transparent]$ wget http[backcolor=transparent]:[backcolor=transparent]//emr-sample-projects.oss-cn-hangzhou.aliyuncs.com/oozie-examples/oozie-examples-ha.zip
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] tmp[backcolor=transparent]][backcolor=transparent]$ unzip oozie[backcolor=transparent]-[backcolor=transparent]examples[backcolor=transparent]-[backcolor=transparent]ha[backcolor=transparent].[backcolor=transparent]zip
将 Oozie workflow 代码同步到 hdfs 上。
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] tmp[backcolor=transparent]][backcolor=transparent]$ hadoop fs [backcolor=transparent]-[backcolor=transparent]copyFromLocal examples[backcolor=transparent]/ /[backcolor=transparent]user[backcolor=transparent]/[backcolor=transparent]oozie[backcolor=transparent]/[backcolor=transparent]examples
提交 Oozie workflow 样例作业。
- [backcolor=transparent][[backcolor=transparent]oozie@emr[backcolor=transparent]-[backcolor=transparent]header[backcolor=transparent]-[backcolor=transparent]1[backcolor=transparent] tmp[backcolor=transparent]][backcolor=transparent]$ $OOZIE_HOME[backcolor=transparent]/[backcolor=transparent]bin[backcolor=transparent]/[backcolor=transparent]oozie job [backcolor=transparent]-[backcolor=transparent]config examples[backcolor=transparent]/[backcolor=transparent]apps[backcolor=transparent]/[backcolor=transparent]map[backcolor=transparent]-[backcolor=transparent]reduce[backcolor=transparent]/[backcolor=transparent]job[backcolor=transparent].[backcolor=transparent]properties [backcolor=transparent]-[backcolor=transparent]run
执行成功之后,会返回一个 jobId,类似:
- [backcolor=transparent]job[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]0000000[backcolor=transparent]-[backcolor=transparent]160627195651086[backcolor=transparent]-[backcolor=transparent]oozie[backcolor=transparent]-[backcolor=transparent]oozi[backcolor=transparent]-[backcolor=transparent]W
访问 Oozie UI 页面,可以看到刚刚提交的 Oozie workflow job。