• 6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略


    探索背景

    随着大数据应用的不断发展,数据仓库、数据湖的大数据实践层出不穷;无论是电信、金融、政府,各个行业的大数据热潮蓬勃发展。在过去的4-5年中,我们不断看到企业用户大数据膨胀问题日益加剧,大数据创新下数据存储成本呈现线性增长,使得企业对于大数据的应用开始变得谨慎、变向放缓了企业内部数据化转型的速度。

    核心的挑战:如何更加经济地构建数据湖存储体系。

    大数据存储引擎从2006年发布以来,百花齐放,计算侧MapReduce、Spark、Hive、Impala、Presto、Storm、Flink的问世不断突破应用领域,不过在大数据存储方面反而显得慎重与沉稳。在过去十多年,在Apache Hadoop生态被广泛提及的主要还是HDFS与Ozone。

    HDFS

    Hadoop HDFS 是一种分布式文件系统,旨在在商用硬件上运行以提高其普适性。它与现有的分布式文件系统有很多相似之处。但是,HDFS的特点也是鲜明的:具备高度容错性、旨在部署在低成本硬件、允许水平扩缩容。HDFS提供对应用程序数据访问的高吞吐量,适用于需要处理海量数据集的应用服务。

    Ozone

    Apache Ozone 是一种高度可扩展的分布式存储,适用于分析、大数据和云原生应用程序。Ozone 支持 S3 兼容对象 API 以及 Hadoop 兼容文件系统协议。它针对高效的对象存储和文件系统操作进行了优化。

    经济化数据存储策略,主要体现在两个关键特性上,只要实现了,其他的增强都会如虎添翼:

    1. 使用最合适的存储系统存储对应的数据分块;
    2. 数据存储策略对上层应用的侵入性越低越好;

    比如HDFS典型场景下使用3副本的策略,一方面是确保数据块的高可用性,同时多个副本也可以更好地保障数据局部性的要求,提高数据访问的吞吐量;为了更好地提供数据服务,硬件环境也会选用相对更好的磁盘;对于早期的大数据实践而言,标准统一的软硬件选择可以提高对新技术栈的推动,但是随着数据的不断积累,很多数据的访问频率呈现指数级下降,尤其是针对合规检查的冷数据,不仅仅占据了生产集群的大量空间,可能一年到头都没有被访问过一次。这是对资源的极大浪费。

    大数据发展的现阶段,精细化数据存储被提上了议程。需要一种分层的存储体系,在维系现有计算性能的同时,将温、冷数据实现对上层应用透明的自主迁移,控制数据存储与维护的成本。

    关键特性验证

    通过这篇文章,我们希望可以对经济化数据存储策略做一个初步探索,首先我们将先前提到的两个关键特性具象化,然后通过几组实验对技术可行性进行一个讨论。

    关键特性一:使用一套存储系统作为热数据系统;使用另一套存储系统作为冷数据系统;

    关键特性二:统一命名空间同时兼容多套存储系统,通过统一命名空间对上层应用提供数据访问服务;

    技术选择:

    1. 计算引擎: Hive (大部分企业用户使用SQL引擎作为数据开发工具)
    2. 存储引擎: HDFS/Ozone (业界常用的Apache生态存储)
    3. 数据编排引擎: Alluxio (第三方开源组件,兼容大部分Apache生态组件)

    Hive

    Apache Hive ™ 数据仓库软件有助于使用 SQL 读取、写入和管理驻留在分布式存储中的大型数据集。结构可以投影到已经存储的数据上。提供了一个命令行工具和 JDBC 驱动程序允许用户连接到 Hive。

    关于Alluxio

    “Alluxio数据编排系统”是全球首个分布式超大规模数据编排系统,孵化于加州大学伯克利分校AMP实验室。自项目开源以来,已有超过来自300多个组织机构的1200多位贡献者参与开发。Alluxio能够在跨集群、跨区域、跨国家的任何云中将数据更紧密地编排到接近数据分析和AI/ML应用程序的集群中,从而向上层应用提供内存级别的数据访问速度。

    作为大数据生态系统中的存储与计算分离技术标准,在阿里云、腾讯云、华为云、金山云等国内顶级云厂商服务中得到生产检验,是建设企业私有云的基石和核心技术。2021年成立后,先后荣登“中关村国际前沿科技创新大赛大数据与云计算领域TOP10”、“2021投资界数字科技VENTURE50”、“科创中国”开源创新榜等多项榜单。

    技术可行性研究,我们分两个阶段进行:

    阶段一:使用同一类型的存储系统HDFS,实现不同HDFS系统之间的冷热分层【模拟场景:使用新的HDFS3.0 EC或者用磁盘密集型的机器专门搭建冷数据HDFS】

    阶段二:使用不同类型的存储系统,使用HDFS作为热数据存储系统;使用Ozone作为冷数据存储系统 【模拟场景:HDFS负责热数据/Ozone负责冷数据】

    验证步骤

    部署架构

    软件版本:

    1. 计算引擎:Hive 2.3.9
    2. 存储引擎:Hadoop 2.10.1,Ozone 1.2.1,Alluxio 2.8
    3. 所有组件均为单机模式部署

    集群规划:

    主机组件
    ip-172-31-30-130.us-west-2.compute.internalHive、HDFS1
    ip-172-31-19-127.us-west-2.compute.internalHDFS2、Ozone
    ip-172-31-17-3.us-west-2.compute.internalAlluxio

    实验一:基于Alluxio实现跨HDFS的透明数据冷热分层

    ## Step 1: 在Hive 中创建库、分区表,默认数据存储在 HDFS_1 上

    1. create database test location "/user/hive/test.db";
    2. create external table test.test_part(value string) partitioned by (dt string);

    #创建库

    1. hive> create database test location '/user/hive/test.db';
    2. OK
    3. Time taken: 1.697 seconds
    4. hive>

    #创建表

    1. hive> create external table test.test_part(value string) partitioned by (dt string);
    2. OK
    3. Time taken: 0.607 seconds
    4. hive>

    ## Step 2: Alluxio Union URI 实现跨HDFS集群统一命名空间集成

    1. alluxio fs mount \
    2. --option alluxio-union.hdfs1.uri=hdfs://namenode_1:8020/user/hive/test.db/test_part \
    3. --option alluxio-union.hdfs2.uri=hdfs://namenode_2:8020/user/hive/test.db/test_part \
    4. --option alluxio-union.priority.read=hdfs1,hdfs2 \
    5. --option alluxio-union.collection.create=hdfs1 \
    6. /user/hive/test.db/test_part union://test_part/

    #以Alluxio Union URI 方式挂载测试目录

    1. [root@ip-172-31-17-3 ~]# alluxio fs mkdir /user/hive/test.db
    2. Successfully created directory /user/hive/test.db
    3. [root@ip-172-31-17-3 conf]# alluxio fs mount \
    4. > --option alluxio-union.hdfs1.uri=hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/test.db/test_part \
    5. > --option alluxio-union.hdfs2.uri=hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part \
    6. > --option alluxio-union.priority.read=hdfs1,hdfs2 \
    7. > --option alluxio-union.collection.create=hdfs1 \
    8. > /user/hive/test.db/test_part union://test_part/
    9. Mounted union://test_part/ at /user/hive/test.db/test_part
    10. [root@ip-172-31-17-3 ~]#

    ## Step 3: 修改 Hive 表路径为 Union URI 路径,屏蔽跨异构存储的技术细节

    alter table test.test_part set location "alluxio://alluxio:19998/user/hive/test.db/test_part"; 

    #修改Hive表格对应的路径

    1. hive> alter table test.test_part set location "alluxio://ip-172-31-17-3.us-west-2.compute.internal:19998/user/hive/test.db/test_part";
    2. OK
    3. Time taken: 0.143 seconds
    4. hive>

    ## Step 4: 模拟数据

    1. mkdir dt\=2022-06-0{1..6}
    2. echo 1abc > dt\=2022-06-01/000000_0
    3. echo 2def > dt\=2022-06-02/000000_0
    4. echo 3ghi > dt\=2022-06-03/000000_0
    5. echo 4jkl > dt\=2022-06-04/000000_0
    6. echo 5mno > dt\=2022-06-05/000000_0
    7. echo 6pqr > dt\=2022-06-06/000000_0
    8. hdfs dfs -put dt\=2022-06-0{1..3} hdfs://namenode_1:8020/user/hive/test.db/test_part
    9. hdfs dfs -put dt\=2022-06-0{4..6} hdfs://namenode_2:8020/user/hive/test.db/test_part

    1. [root@ip-172-31-17-3 ~]# mkdir dt\=2022-06-0{1..6}
    2. [root@ip-172-31-17-3 ~]# echo 1abc > dt\=2022-06-01/000000_0
    3. [root@ip-172-31-17-3 ~]# echo 2def > dt\=2022-06-02/000000_0
    4. [root@ip-172-31-17-3 ~]# echo 3ghi > dt\=2022-06-03/000000_0
    5. [root@ip-172-31-17-3 ~]# echo 4jkl > dt\=2022-06-04/000000_0
    6. [root@ip-172-31-17-3 ~]# echo 5mno > dt\=2022-06-05/000000_0
    7. [root@ip-172-31-17-3 ~]# echo 6pqr > dt\=2022-06-06/000000_0

    #将模拟数据分别存入hdfs1、hdfs2

    1. [root@ip-172-31-17-3 ~]# hdfs dfs -put dt\=2022-06-0{1..3} hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/test.db/test_part
    2. [root@ip-172-31-17-3 ~]# hdfs dfs -mkdir -p hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part
    3. [root@ip-172-31-17-3 ~]# hdfs dfs -put dt\=2022-06-0{4..6} hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part

    #查询hdfs1和hdfs2,确认数据存入完成

    1. [root@ip-172-31-17-3 ~]# hdfs dfs -ls hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/test.db/test_part
    2. Found 3 items
    3. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:09 hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-01
    4. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:09 hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-02
    5. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:09 hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-03
    6. [root@ip-172-31-17-3 ~]# hdfs dfs -ls hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part
    7. Found 3 items
    8. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:10 hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-04
    9. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:10 hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-05
    10. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:10 hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-06

    #通过查询alluxio Union URI 再次确认数据存入hdfs1和hdfs2,以及Union URI跨存储关联生效

    1. [root@ip-172-31-17-3 ~]# alluxio fs ls /user/hive/test.db/test_part
    2. drwxr-xr-x root hdfsadmingroup 1 PERSISTED 07-13-2022 08:09:19:243 DIR /user/hive/test.db/test_part/dt=2022-06-02
    3. drwxr-xr-x root hdfsadmingroup 1 PERSISTED 07-13-2022 08:09:19:219 DIR /user/hive/test.db/test_part/dt=2022-06-01
    4. drwxr-xr-x root hdfsadmingroup 1 PERSISTED 07-13-2022 08:10:49:740 DIR /user/hive/test.db/test_part/dt=2022-06-06
    5. drwxr-xr-x root hdfsadmingroup 1 PERSISTED 07-13-2022 08:10:49:721 DIR /user/hive/test.db/test_part/dt=2022-06-05
    6. drwxr-xr-x root hdfsadmingroup 1 PERSISTED 07-13-2022 08:10:49:698 DIR /user/hive/test.db/test_part/dt=2022-06-04
    7. drwxr-xr-x root hdfsadmingroup 1 PERSISTED 07-13-2022 08:09:19:263 DIR /user/hive/test.db/test_part/dt=2022-06-03
    8. [root@ip-172-31-17-3 ~]#

    ## Step 5: 刷新Hive表元数据

    MSCK REPAIR TABLE test.test_part;
    1. hive> MSCK REPAIR TABLE test.test_part;
    2. OK
    3. Partitions not in metastore: test_part:dt=2022-06-01 test_part:dt=2022-06-02 test_part:dt=2022-06-03 test_part:dt=2022-06-04 test_part:dt=2022-06-05 test_part:dt=2022-06-06
    4. Repair: Added partition to metastore test.test_part:dt=2022-06-01
    5. Repair: Added partition to metastore test.test_part:dt=2022-06-02
    6. Repair: Added partition to metastore test.test_part:dt=2022-06-03
    7. Repair: Added partition to metastore test.test_part:dt=2022-06-04
    8. Repair: Added partition to metastore test.test_part:dt=2022-06-05
    9. Repair: Added partition to metastore test.test_part:dt=2022-06-06
    10. Time taken: 1.677 seconds, Fetched: 7 row(s)

    #通过select方式观察到Hive元数据刷新后,alluxio union URI关联生效体现到Hive表中

    1. hive> select * from test.test_part;
    2. OK
    3. 1abc 2022-06-01
    4. 2def 2022-06-02
    5. 3ghi 2022-06-03
    6. 4jkl 2022-06-04
    7. 5mno 2022-06-05
    8. 6pqr 2022-06-06
    9. Time taken: 1.624 seconds, Fetched: 6 row(s)
    10. hive>

    ## Step 6: 配置冷热自动分层策略

    alluxio fs policy add /user/hive/test.db/test_part "ufsMigrate(olderThan(2m), UFS[hdfs1]:REMOVE, UFS[hdfs2]:STORE)" 

    #设置策略:冷数据(本例中按生成超过2分钟的数据)自动从热存储(hdfs1)迁移到冷存储(hdfs2)

    1. [root@ip-172-31-17-3 ~]# alluxio fs policy add /user/hive/test.db/test_part "ufsMigrate(olderThan(2m), UFS[hdfs1]:REMOVE, UFS[hdfs2]:STORE)"
    2. Policy ufsMigrate-/user/hive/test.db/test_part is added to /user/hive/test.db/test_part.

    #通过Alluxio命令行查看策略设置成功与否

    1. [root@ip-172-31-17-3 ~]# alluxio fs policy list
    2. id: 1657700423909
    3. name: "ufsMigrate-/user/hive/test.db/test_part"
    4. path: "/user/hive/test.db/test_part"
    5. created_at: 1657700423914
    6. scope: "RECURSIVE"
    7. condition: "olderThan(2m)"
    8. action: "DATA(UFS[hdfs1]:REMOVE, UFS[hdfs2]:STORE)"
    9. [root@ip-172-31-17-3 ~]#

    #策略生效后分别查看hdfs1和hdfs2,可以观察到hdfs1里面超过2分钟的数据都迁移到hdfs2中

    1. [root@ip-172-31-17-3 logs]# hdfs dfs -ls hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/test.db/test_part
    2. [root@ip-172-31-17-3 logs]# hdfs dfs -ls hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part
    3. Found 6 items
    4. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:26 hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-01
    5. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:26 hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-02
    6. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:26 hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-03
    7. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:10 hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-04
    8. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:10 hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-05
    9. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 08:10 hdfs://ip-172-31-19-127.us-west-2.compute.internal:8020/user/hive/test.db/test_part/dt=2022-06-06
    10. [root@ip-172-31-17-3 logs]#

    #策略生效,冷数据自动迁移过程中和完成后查Hive都得到如下预期查询结果:

    1. hive> select * from test.test_part;
    2. OK
    3. 1abc 2022-06-01
    4. 2def 2022-06-02
    5. 3ghi 2022-06-03
    6. 4jkl 2022-06-04
    7. 5mno 2022-06-05
    8. 6pqr 2022-06-06
    9. Time taken: 0.172 seconds, Fetched: 6 row(s)
    10. hive>

    最后,我们将实验一的两个步骤:(1)通过Alluxio的Union URI实现跨两个HDFS存储系统的Hive表的数据联邦,和(2)通过Alluxio实现跨两个HDFS存储系统的透明数据冷热分层,在图1和图2中分别以简化示意图的方式展示,便于更好的理解实验目标、过程和结果。

    图1:通过Alluxio的Union URI实现跨两个HDFS存储系统的Hive表的数据联邦的示意图

    图2:通过Alluxio实现跨两个HDFS存储系统的透明数据冷热分层示意图

    下一组实验只是将上一组实验设定中的两个HDFS存储系统更改成了两个异构存储系统HDFS(热存储)和Ozone(冷存储),从透明冷热分层功能层面效果是相同的。

    实验二:基于Alluxio实现跨异构存储(HDFS和Ozone)的透明数据冷热分层

    ## step 1 : hive 创建库、表

    1. create database hdfsToOzone location '/user/hive/hdfsToOzone.db';
    2. create external table hdfsToOzone.test(value string) partitioned by (dt string);

    #创建库

    1. hive> create database hdfsToOzone location '/user/hive/hdfsToOzone.db';
    2. OK
    3. Time taken: 0.055 seconds
    4. hive>

    #创建表

    1. hive> create external table hdfsToOzone.test(value string) partitioned by (dt string);
    2. OK
    3. Time taken: 0.1 seconds
    4. hive>

    ## step 2: Alluxio Union URI实现跨HDFS/Ozone集群统一命名空间集成

    1. alluxio fs mount \
    2. --option alluxio-union.hdfs.uri=hdfs://HDFS1:8020/user/hive/hdfsToOzone.db/test \
    3. --option alluxio-union.ozone.uri=o3fs://bucket.volume/hdfsToOzone.db/test \
    4. --option alluxio-union.priority.read=hdfs,ozone \
    5. --option alluxio-union.collection.create=hdfs \
    6. --option alluxio.underfs.hdfs.configuration=/mnt1/ozone-1.2.1/etc/hadoop/ozone-site.xml \
    7. /user/hive/hdfsToOzone.db/test union://HDFS_TO_OZONE/

    #在Ozone中使用命令行工具创建volume、bucket

    1. [root@ip-172-31-19-127 ~]# ozone sh volume create /v-alluxio
    2. [root@ip-172-31-19-127 ~]# ozone sh bucket create /v-alluxio/b-alluxio
    3. [root@ip-172-31-19-127 ~]# ozone fs -mkdir -p o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test
    4. [root@ip-172-31-19-127 ~]#

    #先在Alluxio中创建实验目录,然后以 Union URI 方式挂载目录

    1. [root@ip-172-31-17-3 ~]# alluxio fs mkdir /user/hive/hdfsToOzone.db
    2. Successfully created directory /user/hive/hdfsToOzone.db
    3. [root@ip-172-31-17-3 ~]# alluxio fs mount \
    4. > --option alluxio-union.hdfs.uri=hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/hdfsToOzone.db/test \
    5. > --option alluxio-union.ozone.uri=o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test \
    6. > --option alluxio-union.priority.read=hdfs,ozone \
    7. > --option alluxio-union.collection.create=hdfs \
    8. > --option alluxio.underfs.hdfs.configuration=/mnt1/ozone-1.2.1/etc/hadoop/ozone-site.xml \
    9. > /user/hive/hdfsToOzone.db/test union://HDFS_TO_OZONE/
    10. Mounted union://HDFS_TO_OZONE/ at /user/hive/hdfsToOzone.db/test
    11. [root@ip-172-31-17-3 ~]#

    ## step 3: 修改 Hive 表路径为 Union URI 路径,屏蔽跨异构存储的技术细节

    alter table hdfsToOzone.test set location "alluxio://alluxio:19998/user/hive/hdfsToOzone.db/test"; 

    #修改Hive表格对应的路径

    1. hive> alter table hdfsToOzone.test set location "alluxio://ip-172-31-17-3.us-west-2.compute.internal:19998/user/hive/hdfsToOzone.db/test";
    2. OK
    3. Time taken: 1.651 seconds
    4. hive>

    ## step 4: 模拟数据

    1. ozone fs -put dt\=2022-06-0{1..3} o3fs://b-alluxio.v-alluxio.ozone:9862/hdfsToOzone.db/test
    2. hdfs dfs -put dt\=2022-06-0{4..6} hdfs://HDFS1:8020/user/hive/hdfsToOzone.db/test

    #将数据存入ozone

    1. [root@ip-172-31-19-127 ~]# ozone fs -put dt\=2022-06-0{1..3} o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test
    2. 2022-07-13 10:00:38,920 [main] INFO impl.MetricsConfig: Loaded properties from hadoop-metrics2.properties
    3. 2022-07-13 10:00:38,981 [main] INFO impl.MetricsSystemImpl: Scheduled Metric snapshot period at 10 second(s).
    4. 2022-07-13 10:00:38,981 [main] INFO impl.MetricsSystemImpl: XceiverClientMetrics metrics system started
    5. 2022-07-13 10:00:39,198 [main] INFO metrics.MetricRegistries: Loaded MetricRegistries class org.apache.ratis.metrics.impl.MetricRegistriesImpl

    #通过命令行查询ozone,确认数据存入完成

    1. [root@ip-172-31-19-127 ~]# ozone fs -ls o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test
    2. Found 3 items
    3. drwxrwxrwx - root root 0 2022-07-13 10:00 o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test/dt=2022-06-01
    4. drwxrwxrwx - root root 0 2022-07-13 10:00 o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test/dt=2022-06-02
    5. drwxrwxrwx - root root 0 2022-07-13 10:00 o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test/dt=2022-06-03
    6. [root@ip-172-31-19-127 ~]#

    #将数据存入hdfs1,并通过命令行查询hdfs1,确认数据存入完成

    1. [root@ip-172-31-17-3 ~]# hdfs dfs -put dt\=2022-06-0{4..6} hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/hdfsToOzone.db/test
    2. [root@ip-172-31-17-3 ~]# hdfs dfs -ls hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/hdfsToOzone.db/test
    3. Found 3 items
    4. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 10:06 hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/hdfsToOzone.db/test/dt=2022-06-04
    5. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 10:06 hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/hdfsToOzone.db/test/dt=2022-06-05
    6. drwxr-xr-x - root hdfsadmingroup 0 2022-07-13 10:06 hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/hdfsToOzone.db/test/dt=2022-06-06
    7. [root@ip-172-31-17-3 ~]#

    #通过Alluxio命令行查询,再次确认数据存入hdfs1和ozone,以及Union URI跨存储关联生效

    1. [root@ip-172-31-17-3 ~]# alluxio fs ls /user/hive/hdfsToOzone.db/test
    2. drwxrwxrwx root root 0 PERSISTED 07-13-2022 10:00:40:670 DIR /user/hive/hdfsToOzone.db/test/dt=2022-06-02
    3. drwxrwxrwx root root 0 PERSISTED 07-13-2022 10:00:38:691 DIR /user/hive/hdfsToOzone.db/test/dt=2022-06-01
    4. drwxr-xr-x root hdfsadmingroup 0 PERSISTED 07-13-2022 10:06:29:206 DIR /user/hive/hdfsToOzone.db/test/dt=2022-06-06
    5. drwxr-xr-x root hdfsadmingroup 0 PERSISTED 07-13-2022 10:06:29:186 DIR /user/hive/hdfsToOzone.db/test/dt=2022-06-05
    6. drwxr-xr-x root hdfsadmingroup 0 PERSISTED 07-13-2022 10:06:29:161 DIR /user/hive/hdfsToOzone.db/test/dt=2022-06-04
    7. drwxrwxrwx root root 0 PERSISTED 07-13-2022 10:00:40:762 DIR /user/hive/hdfsToOzone.db/test/dt=2022-06-03
    8. [root@ip-172-31-17-3 ~]#

    ## step 5: 刷新Hive表元数据

    MSCK REPAIR TABLE hdfsToOzone.test;
    1. hive> MSCK REPAIR TABLE hdfsToOzone.test;
    2. OK
    3. Partitions not in metastore: test:dt=2022-06-01 test:dt=2022-06-02 test:dt=2022-06-03 test:dt=2022-06-04 test:dt=2022-06-05 test:dt=2022-06-06
    4. Repair: Added partition to metastore hdfsToOzone.test:dt=2022-06-01
    5. Repair: Added partition to metastore hdfsToOzone.test:dt=2022-06-02
    6. Repair: Added partition to metastore hdfsToOzone.test:dt=2022-06-03
    7. Repair: Added partition to metastore hdfsToOzone.test:dt=2022-06-04
    8. Repair: Added partition to metastore hdfsToOzone.test:dt=2022-06-05
    9. Repair: Added partition to metastore hdfsToOzone.test:dt=2022-06-06
    10. Time taken: 0.641 seconds, Fetched: 7 row(s)
    11. hive>

    #通过select方式观察到hive元数据刷新后,alluxio union URI关联生效体现到hive表中

    1. hive> select * from hdfsToOzone.test ;
    2. OK
    3. 1abc 2022-06-01
    4. 2def 2022-06-02
    5. 3ghi 2022-06-03
    6. 4jkl 2022-06-04
    7. 5mno 2022-06-05
    8. 6pqr 2022-06-06
    9. Time taken: 0.156 seconds, Fetched: 6 row(s)
    10. hive>

    ## step 6: 配置策略

    alluxio fs policy add /user/hive/hdfsToOzone.db/test" ufsMigrate(olderThan(2m), UFS[hdfs]:REMOVE, UFS[ozone]:STORE)" 

    #设置策略:冷数据(本例中按生成超过2分钟的数据)自动从热存储(hdfs1)迁移到冷存储(ozone)

    1. [root@ip-172-31-17-3 ~]# alluxio fs policy add /user/hive/hdfsToOzone.db/test/ "ufsMigrate(olderThan(2m), UFS[hdfs]:REMOVE, UFS[ozone]:STORE)"
    2. Policy ufsMigrate-/user/hive/hdfsToOzone.db/test is added to /user/hive/hdfsToOzone.db/test.

    #通过Alluxio命令行查看策略设置成功与否

    1. [root@ip-172-31-17-3 ~]# alluxio fs policy list
    2. id: 1657707130843
    3. name: "ufsMigrate-/user/hive/hdfsToOzone.db/test"
    4. path: "/user/hive/hdfsToOzone.db/test"
    5. created_at: 1657707130843
    6. scope: "RECURSIVE"
    7. condition: "olderThan(2m)"
    8. action: "DATA(UFS[hdfs]:REMOVE, UFS[ozone]:STORE)"
    9. [root@ip-172-31-17-3 ~]#

    #策略生效后分别查看hdfs1和ozone,可以观察到hdfs1里面超过2分钟的数据都迁移到ozone中

    1. [root@ip-172-31-17-3 ~]# ozone fs -ls o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test
    2. Found 6 items
    3. drwxrwxrwx - root root 0 2022-07-13 10:00 o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test/dt=2022-06-01
    4. drwxrwxrwx - root root 0 2022-07-13 10:00 o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test/dt=2022-06-02
    5. drwxrwxrwx - root root 0 2022-07-13 10:00 o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test/dt=2022-06-03
    6. drwxrwxrwx - root root 0 2022-07-13 10:21 o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test/dt=2022-06-04
    7. drwxrwxrwx - root root 0 2022-07-13 10:21 o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test/dt=2022-06-05
    8. drwxrwxrwx - root root 0 2022-07-13 10:21 o3fs://b-alluxio.v-alluxio/hdfsToOzone.db/test/dt=2022-06-06
    9. [root@ip-172-31-17-3 ~]# hdfs dfs -ls hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/user/hive/hdfsToOzone.db/test
    10. [root@ip-172-31-17-3 ~]#

    #策略生效,冷数据自动迁移过程中和完成后查hive都得到如下预期查询结果:

    1. hive> select * from hdfsToOzone.test ;
    2. OK
    3. 1abc 2022-06-01
    4. 2def 2022-06-02
    5. 3ghi 2022-06-03
    6. 4jkl 2022-06-04
    7. 5mno 2022-06-05
    8. 6pqr 2022-06-06
    9. Time taken: 0.144 seconds, Fetched: 6 row(s)
    10. hive>

    4. 实验小结

    可以看出,实验二的执行过程和效果展示和实验一几乎是如出一辙,除了冷数据存储系统从hdfs2切换成了一个异构存储系统Ozone。

    通过实验,我们充分验证了Alluxio数据编排是如何成功将上层应用 (比如基于Hive的数仓建设) 与底层数据持久化策略 (使用hdfs或者Ozone, 是否进行冷热分层等) 解耦合的。同时也体现了Alluxio对于异构存储系统的通用性和易用性。

    最后希望这篇文章对各位如何使用Alluxio经济化数据存储策略有所启迪。

    附录

    Alluxio集成Hive及HDFS的方式

    Alluxio 配置

    echo 'export ALLX_HOME=/mnt1/alluxio' >> ~/.bashrc
    echo 'export PATH=$PATH:$ALLX_HOME/bin' >> ~/.bashrc
    1. alluxio.master.hostname=ip-172-31-17-3.us-west-2.compute.internal
    2. alluxio.underfs.address=hdfs://ip-172-31-30-130.us-west-2.compute.internal:8020/alluxio
    3. alluxio.worker.tieredstore.level0.dirs.path=/alluxio/ramdisk
    4. alluxio.worker.memory.size=4G
    5. alluxio.worker.tieredstore.levels=1
    6. alluxio.worker.tieredstore.level0.alias=MEM
    7. alluxio.user.file.readtype.default=CACHE
    8. alluxio.user.file.writetype.default=ASYNC_THROUGH
    9. alluxio.security.login.impersonation.username=_HDFS_USER_
    10. alluxio.master.security.impersonation.yarn.groups=*
    11. alluxio.master.security.impersonation.hive.groups=*
    12. alluxio.user.metrics.collection.enabled=true
    13. alluxio.user.block.size.bytes.default=64MB
    14. ######## Explore ########
    15. alluxio.user.block.write.location.policy.class=alluxio.client.block.policy.DeterministicHashPolicy
    16. alluxio.user.ufs.block.read.location.policy=alluxio.client.block.policy.DeterministicHashPolicy
    17. alluxio.user.ufs.block.read.location.policy.deterministic.hash.shards=1
    18. alluxio.user.file.persist.on.rename=true
    19. alluxio.master.persistence.blacklist=.staging,_temporary,.tmp
    20. alluxio.user.file.passive.cache.enabled=false

    Hive 客户端core-site.xml

    cp /hadoop_home/etc/hadoop/core-site.xml /hive_home/conf

    ## 拷贝 jar分别到hadoop和hive home下的lib子目录中

    1. cp //client/alluxio-enterprise-2.8.0-1.0-client.jar /hadoop_home/share/lib
    2. cp //client/alluxio-enterprise-2.8.0-1.0-client.jar /hive_home/lib

    ## 配置alluxio文件系统

    1. vim /hive_home/conf/core-site.xml
    2. <property>
    3. <name>fs.alluxio.implname>
    4. <value>alluxio.hadoop.FileSystemvalue>
    5. property>
    6. <property>
    7. <name>alluxio.master.rpc.addressesname>
    8. <value>ip-172-31-17-3.us-west-2.compute.internal:19998value>
    9. property>

    HDFS授权

    ## 查看hdfs 超级用户

    1. vim /hadoop_home/etc/hadoop/hdfs-site.xml
    2. <property>
    3. <name>dfs.permissions.superusergroupname>
    4. <value>hdfsadmingroupvalue>
    5. property>

    ## 将用户 Alluxio 增加到supergroup

    1. groupadd hdfsadmingroup
    2. usermod -a -G hdfsadmingroup root

    ## 同步系统的权限信息到 HDFS

    su - hdfs -s /bin/bash -c "hdfs dfsadmin -refreshUserToGroupsMappings"

    ## 开启hdfs acl

    1. vim /hadoop_home/etc/hadoop/hdfs-site.xml
    2. <property>
    3. <name>dfs.permissions.enabledname>
    4. <value>truevalue>
    5. property>
    6. <property>
    7. <name>dfs.namenode.acls.enabledname>
    8. <value>truevalue>
    9. property>
    10. su - hdfs -s /bin/bash -c "hdfs dfs -setfacl -R -m user:root:rwx /"

    Ozone 部署

    配置文件

    1. wget https://dlcdn.apache.org/ozone/1.2.1/ozone-1.2.1.tar.gz
    2. echo 'export OZONE_HOME=/mnt1/ozone-1.2.1' >> ~/.bashrc
    3. echo 'export PATH=$PATH:$OZONE_HOME/bin:$OZONE_HOME/sbin' >> ~/.bashrc

    ##在ozone-site.xml中加入必要配置信息

    1. <configuration>
    2. <property>
    3. <name>ozone.om.addressname>
    4. <value>ip-172-31-19-127.us-west-2.compute.internal:9862value>
    5. property>
    6. <property>
    7. <name>ozone.metadata.dirsname>
    8. <value>/mnt/ozone-1.2.1/metadata/ozonevalue>
    9. property>
    10. <property>
    11. <name>ozone.scm.client.addressname>
    12. <value>ip-172-31-19-127.us-west-2.compute.internal:9860value>
    13. property>
    14. <property>
    15. <name>ozone.scm.namesname>
    16. <value>ip-172-31-19-127.us-west-2.compute.internalvalue>
    17. property>
    18. <property>
    19. <name>ozone.scm.datanode.id.dirname>
    20. <value>/mnt/ozone-1.2.1/metadata/ozone/nodevalue>
    21. property>
    22. <property>
    23. <name>ozone.om.db.dirsname>
    24. <value>/mnt/ozone-1.2.1/metadata/ozone/omdbvalue>
    25. property>
    26. <property>
    27. <name>ozone.scm.db.dirsname>
    28. <value>/mnt/ozone-1.2.1/metadata/ozone/scmdbvalue>
    29. property>
    30. <property>
    31. <name>hdds.datanode.dirname>
    32. <value>/mnt/ozone-1.2.1/datanode/datavalue>
    33. property>
    34. <property>
    35. <name>ozone.om.ratis.enablename>
    36. <value>falsevalue>
    37. property>
    38. <property>
    39. <name>ozone.om.http-addressname>
    40. <value>ip-172-31-19-127.us-west-2.compute.internal:9874value>
    41. property>
    42. <property>
    43. <name>ozone.s3g.domain.namename>
    44. <value>s3g.internalvalue>
    45. property>
    46. <property>
    47. <name>ozone.replicationname>
    48. <value>1value>
    49. property>
    50. configuration>

    初始化与启动(按照顺序)

    1. ozone scm --init
    2. ozone --daemon start scm
    3. ozone om --init
    4. ozone --daemon start om
    5. ozone --daemon start datanode
    6. ozone --daemon start s3g

    ozone使用操作

    #创建名称为v-alluxio的volume

    1. [root@ip-172-31-19-127 ~]# ozone sh volume create /v-alluxio
    2. [root@ip-172-31-19-127 ~]#

    #在v-alluxio下创建名为b-alluxio的bucket

    1. [root@ip-172-31-19-127 ~]# ozone sh bucket create /v-alluxio/b-alluxio
    2. [root@ip-172-31-19-127 ~]#

    #查看bucket的相关信息

    1. [root@ip-172-31-19-127 ~]# ozone sh bucket info /v-alluxio/b-alluxio
    2. {
    3. "metadata" : { },
    4. "volumeName" : "v-alluxio",
    5. "name" : "b-alluxio",
    6. "storageType" : "DISK",
    7. "versioning" : false,
    8. "usedBytes" : 30,
    9. "usedNamespace" : 6,
    10. "creationTime" : "2022-07-13T09:11:37.403Z",
    11. "modificationTime" : "2022-07-13T09:11:37.403Z",
    12. "quotaInBytes" : -1,
    13. "quotaInNamespace" : -1,
    14. "bucketLayout" : "LEGACY"
    15. }
    16. [root@ip-172-31-19-127 ~]#

    #创建key,并放入相应的内容

    1. [root@ip-172-31-19-127 ~]# touch Dockerfile
    2. [root@ip-172-31-19-127 ~]# ozone sh key put /v-alluxio/b-alluxio/Dockerfile Dockerfile
    3. [root@ip-172-31-19-127 ~]#

    #列出bucket下所有的key

    1. [root@ip-172-31-19-127 ~]# ozone sh key list /v-alluxio/b-alluxio/
    2. {
    3. "volumeName" : "v-alluxio",
    4. "bucketName" : "b-alluxio",
    5. "name" : "Dockerfile",
    6. "dataSize" : 0,
    7. "creationTime" : "2022-07-13T14:37:09.761Z",
    8. "modificationTime" : "2022-07-13T14:37:09.801Z",
    9. "replicationConfig" : {
    10. "replicationFactor" : "ONE",
    11. "requiredNodes" : 1,
    12. "replicationType" : "RATIS"
    13. },
    14. "replicationFactor" : 1,
    15. "replicationType" : "RATIS"
    16. }
    17. [root@ip-172-31-19-127 ~]#

    #查看key的相关信息

    1. [root@ip-172-31-19-127 ~]# ozone sh key info /v-alluxio/b-alluxio/Dockerfile
    2. {
    3. "volumeName" : "v-alluxio",
    4. "bucketName" : "b-alluxio",
    5. "name" : "Dockerfile",
    6. "dataSize" : 0,
    7. "creationTime" : "2022-07-13T14:37:09.761Z",
    8. "modificationTime" : "2022-07-13T14:37:09.801Z",
    9. "replicationConfig" : {
    10. "replicationFactor" : "ONE",
    11. "requiredNodes" : 1,
    12. "replicationType" : "RATIS"
    13. },
    14. "ozoneKeyLocations" : [ ],
    15. "metadata" : { },
    16. "replicationFactor" : 1,
    17. "replicationType" : "RATIS"
    18. }
    19. [root@ip-172-31-19-127 ~]#

    Alluxio 挂载 ozone

    #方式一

    1. [root@ip-172-31-17-3 ~]# alluxio fs mount /ozone o3fs://b-alluxio.v-alluxio.ip-172-31-19-127.us-west-2.compute.internal:9862/
    2. Mounted o3fs://b-alluxio.v-alluxio.ip-172-31-19-127.us-west-2.compute.internal:9862/ at /ozone
    3. [root@ip-172-31-17-3 ~]#

    #方式二(带option的mount)

    1. [root@ip-172-31-17-3 ~]# alluxio fs mount \
    2. > --option alluxio.underfs.hdfs.configuration=/mnt1/ozone-1.2.1/etc/hadoop/ozone-site.xml \
    3. > /ozone1 o3fs://b-alluxio.v-alluxio/
    4. Mounted o3fs://b-alluxio.v-alluxio/ at /ozone1
    5. [root@ip-172-31-17-3 ~]#

    #验证Ozone挂载是否成功

    1. [root@ip-172-31-17-3 ~]# alluxio fs ls /
    2. drwxrwxrwx root root 0 PERSISTED 01-01-1970 00:00:00:000 DIR /ozone1
    3. drwxrwxrwx root root 0 PERSISTED 01-01-1970 00:00:00:000 DIR /ozone
    4. [root@ip-172-31-17-3 ~]#
  • 相关阅读:
    Python脚本:让工作自动化起来
    深入剖析堆原理与堆排序
    git push 总是需要输入密码或者个人访问令牌personal access token解决方案
    稀疏数组举例详解(Java形式表示)
    JS(二)数据类型,流程控制
    【Vue】计算属性 监听属性 组件通信 动态组件 插槽 vue-cli脚手架
    项目开发——【流程图】软件工程程序流程图详解《如何正确绘制项目开发流程图》
    基于Vue+Express+ElementUI+MySQL的简单数据库应用
    【go-zero】go-zero 脚手架 simple-admin 第一章:通过goctls生成rpc整个项目 | go-zero整合 ENT数据库orm框架
    大数据毕业设计选题推荐-河长制大数据监测平台-Hadoop-Spark-Hive
  • 原文地址:https://blog.csdn.net/Alluxio/article/details/125889650