当前位置:网站首页>【云小课】EI第47课 MRS离线数据分析-通过Flink作业处理OBS数据
【云小课】EI第47课 MRS离线数据分析-通过Flink作业处理OBS数据
2022-07-06 11:50:00 【华为云】
MRS支持在大数据存储容量大、计算资源需要弹性扩展的场景下,用户将数据存储在OBS服务中,使用MRS集群仅做数据计算处理的存算分离模式。
Flink是一个批处理和流处理结合的统一计算框架,其核心是一个提供了数据分发以及并行化计算的流数据处理引擎。它的最大亮点是流处理,是业界最顶级的开源流处理引擎。
本文将向您介绍如何在MRS集群中运行Flink作业来处理OBS中存储的数据。

在本示例中,我们使用MRS集群内置的Flink WordCount作业程序,来分析OBS文件系统中保存的源数据,以统计源数据中的单词出现次数。
当然您也可以获取MRS服务样例代码工程,参考Flink开发指南开发其他Flink流作业程序。
本案例基本操作流程如下所示:

创建MRS集群
本文以购买MRS 3.1.0版本的集群为例,集群未开启Kerberos认证。
在本示例中,由于我们要分析处理OBS文件系统中的数据,因此在集群的高级配置参数中要为MRS集群绑定IAM权限委托,使得集群内组件能够对接OBS并具有对应文件系统目录的操作权限。
您可以直接选择系统默认的“MRS_ECS_DEFAULT_AGENCY”,也可以自行创建其他具有OBS文件系统操作权限的自定义委托。

例如客户端安装目录为“/opt/client”。
准备测试数据
在创建Flink作业进行数据分析前,我们需要在提前准备待分析的测试数据,并将该数据上传至OBS文件系统中。
本地创建一个“mrs_flink_test.txt”文件,例如文件内容如下:
This is a test demo for MRS Flink. Flink is a unified computing framework that supports both batch processing and stream processing. It provides a stream data processing engine that supports data distribution and parallel computing.
在云服务列表中选择“存储 > 对象存储服务”,登录OBS管理控制台。
单击“并行文件系统”,创建一个并行文件系统,并上传测试数据文件。
例如创建的文件系统名称为“mrs-demo-data”,单击系统名称,在“文件”页面中,新建一个文件夹“flink”,上传测试数据至该目录中。
则本示例的测试数据完整路径为“obs://mrs-demo-data/flink/mrs_flink_test.txt”。
上传数据分析应用程序。
使用管理台界面直接提交作业时,将已开发好的Flink应用程序jar文件也可以上传至OBS文件系统中,或者MRS集群内的HDFS文件系统中。
本示例中我们使用MRS集群内置的Flink WordCount样例程序,可从MRS集群的客户端安装目录中获取,即“/opt/client/Flink/flink/examples/batch/WordCount.jar”。
将“WordCount.jar”上传至“mrs-demo-data/program”目录下。
创建并运行Flink作业
方式1:在控制台界面在线提交作业。
登录MRS管理控制台,单击MRS集群名称,进入集群详情页面。
在集群详情页的“概览”页签,单击“IAM用户同步”右侧的“单击同步”进行IAM用户同步。
- 单击,进入 页签。
- 单击 “添加”,添加一个Flink作业。
作业类型:Flink
作业名称:自定义,例如flink_obs_test。
执行程序路径:本示例使用Flink客户端的WordCount程序为例。
运行程序参数:使用默认值。
执行程序参数:设置应用程序的输入参数,“input”为待分析的测试数据,“output”为结果输出文件。
例如本示例中,我们设置为“--input obs://mrs-demo-data/flink/mrs_flink_test.txt --output obs://mrs-demo-data/flink/output”。
- 服务配置参数:使用默认值即可,如需手动配置作业相关参数,可参考 运行Flink作业。
- 确认作业配置信息后,单击 “确定”,完成作业的新增,并等待运行完成。
方式2:通过集群客户端提交作业。
- 使用 root用户登录集群客户端节点,进入客户端安装目录。
su - ommcd /opt/clientsource bigdata_env
执行以下命令验证集群是否可以访问OBS。
hdfs dfs -ls obs://mrs-demo-data/flink
提交Flink作业,指定源文件数据进行消费。
flink run -m yarn-cluster /opt/client/Flink/flink/examples/batch/WordCount.jar --input obs://mrs-demo-data/flink/mrs_flink_test.txt --output obs://mrs-demo/data/flink/output2
执行后结果类似如下:
...Cluster started: Yarn cluster with application id application_1654672374562_0011Job has been submitted with JobID a89b561de5d0298cb2ba01fbc30338bcProgram execution finishedJob with JobID a89b561de5d0298cb2ba01fbc30338bc has finished.Job Runtime: 1200 ms
查看作业执行结果
作业提交成功后,登录MRS集群的FusionInsight Manager界面,选择“集群 > 服务 > Yarn”。
单击“ResourceManager WebUI”后的链接进入Yarn Web UI界面,在Applications页面查看当前Yarn作业的详细运行情况及运行日志。
等待作业运行完成后,在OBS文件系统中指定的结果输出文件中可查看数据分析输出的结果。
下载“output”文件到本地并打开,可查看输出的分析结果。
a 3and 2batch 1both 1computing 2data 2demo 1distribution 1engine 1flink 2for 1framework 1is 2it 1mrs 1parallel 1processing 3provides 1stream 2supports 2test 1that 2this 1unified 1
使用集群客户端命令行提交作业时,若不指定输出目录,在作业运行界面也可直接查看数据分析结果。
Job with JobID xxx has finished.Job Runtime: xxx msAccumulator Results:- e6209f96ffa423974f8c7043821814e9 (java.util.ArrayList) [31 elements](a,3)(and,2)(batch,1)(both,1)(computing,2)(data,2)(demo,1)(distribution,1)(engine,1)(flink,2)(for,1)(framework,1)(is,2)(it,1)(mrs,1)(parallel,1)(processing,3)(provides,1)(stream,2)(supports,2)(test,1)(that,2)(this,1)(unified,1)
边栏推荐
- 冒烟测试怎么做
- Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
- Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
- MySQL must know and learn
- MySQL information schema learning (II) -- InnoDB table
- Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
- Spark foundation -scala
- Swagger2 reports an error illegal DefaultValue null for parameter type integer
- 利用 clip-path 绘制不规则的图形
- 信息系统项目管理师---第八章 项目质量管理
猜你喜欢
深入分析,Android面试真题解析火爆全网
Using clip path to draw irregular graphics
企业精益管理体系介绍
MySQL information schema learning (I) -- general table
Druid database connection pool details
MySQL information schema learning (II) -- InnoDB table
Application of clock wheel in RPC
JDBC details
思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
Learning and Exploration - Seamless rotation map
随机推荐
利用 clip-path 绘制不规则的图形
学习探索-无缝轮播图
121. The best time to buy and sell stocks
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
LeetCode_ Gray code_ Medium_ 89. Gray code
Example of applying fonts to flutter
1805. 字符串中不同整数的数目
IC设计流程中需要使用到的文件
《数字经济全景白皮书》保险数字化篇 重磅发布
[玩转Linux] [Docker] MySQL安装和配置
CF960G - Bandit Blues(第一类斯特林数+OGF)
蓝桥杯 微生物增殖 C语言
Analysis of rainwater connection
颜色(color)转换为三刺激值(r/g/b)(干股)
时钟轮在 RPC 中的应用
zabbix 代理服务器 与 zabbix-snmp 监控
手把手教你学会js的原型与原型链,猴子都能看懂的教程
Low CPU load and high loadavg processing method
Alibaba data source Druid visual monitoring configuration
Swagger2 reports an error illegal DefaultValue null for parameter type integer