viewfs的特點
可以使用類似linux系統的掛載表,映射集群和hdfs文件系統的路徑。例如:將/user/ 映射到集群cluster-1,將/data映射到cluster-2.在實際操作中,只需要直接使用hdfs dfs -ls /data 訪問的就是集群cluster-2中目錄。
增加Nfly系統,可以鏈接一個目錄到多個目錄,實現同時寫入多個文件系統。例如配置如下,當執行命令: hadoop fs -touchz viewfs://global/ads/z1 會在以下的目錄中分別創建一個z1文件
<property>
<name>fs.viewfs.mounttable.global.linkNfly../ads</name>
<value>hdfs://datacenter-east/ads, s3a://models-us-west/ads, hdfs://datacenter-west/ads</value>
</property>
Nfly系統支持就近讀取的網絡架構。客戶端會從以上三個地址網絡架構最近的uri讀取數據,類似機架感知策略。
配置viewfs
viewfs有兩種配置方式,一種是直接在core-site.xml文件中配置,一種是在額外的文件中配置。
在core-stie.xml文件中參考以下配置
<property>
<name>fs.defaultFS</name>
<value>viewfs://mycluster</value>
</property>
<-- 配置單個目錄單個掛載點 -->
<property>
<name>fs.viewfs.mounttable.ClusterX.link./data</name>
<value>hdfs://mycluster-01:8020/data</value>
</property>
<-- 配置單個目錄多個掛載點 -->
<property>
<name>fs.viewfs.mounttable.global.linkNfly.minReplication=3,readMostRecent=true,repairOnRead=false./ads</name>
<value>hdfs://mycluster-east/ads,s3a://models-us-west/ads,hdfs://mycluster-west/ads</value>
</property>
<-- 如果想配置默認根目錄,使用如下配置 -->
<property>
<name>fs.viewfs.mounttable.mycluster.linkMergeSlash</name>
<value>hdfs://mycluster-01:8020/</value>
</property>
- 在額外的配置文件中配置
修改core-site.xml如下,新建mountTable.xml,將以上配置配置在此文件中
<configuration xmlns:xi="//www.w3.org/2001/XInclude">
<xi:include href="mountTable.xml" />
</configuration>