爲了解決Federation配置的問題(訪問集羣的時候咱們要記住每一個NameNode所在節點的名稱)
ViewFS配置(在master節點配置):oop
- 配置前先關閉集羣
- 一、配置core-site.xml:
將本來的文件: <configuration > <property> <name>fs.defaultFS</name> <value>hdfs://master:9999</value> <description>表示HDFS的基本路徑</description> </property> </configuration> 改爲: <configuration xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="mountTable.xml"/> <property> <name>fs.default.name</name> <value>viewfs://my-cluster</value> </property> </configuration> 其他的<property></property>內容保持不變(能夠選擇註釋)
- 二、增長mountTable.xml:
<configuration> <property> <name>fs.viewfs.mounttable.my-cluster.link./user</name> <value>hdfs://master:9999/user</value> </property> <property> <name>fs.viewfs.mounttable.my-cluster.link./tmp</name> <value>hdfs://master:9999/tmp</value> </property> <property> <name>fs.viewfs.mounttable.my-cluster.link./projects/foo</name> <value>hdfs://slave1:9999/projects/foo</value> </property> <property> <name>fs.viewfs.mounttable.my-cluster.link./projects/bar</name> <value>hdfs://slave1:9999/projects/bar</value> </property> </configuration>
- 三、將core-site.xml mountTable.xml同步到slave一、slave2上
scp core-site.xml mountTable.xml hadoop-twq@slave1:~/bigdata/hadoop-2.7.5/etc/hadoop/
scp core-site.xml mountTable.xml hadoop-twq@slave2:~/bigdata/hadoop-2.7.5/etc/hadoop/
- 四、啓動集羣
- 五、在master、slave1上執行
hadoop fs -ls /
發現看到的數據都同樣,如此一來,不管是在master、slave1仍是slave2上執行hadoop fs -ls viewfs://my-cluster/
這個基本路徑後看到數據都同樣,這樣用戶就不用記住NameNode安裝在那裏,方便了用戶 - 六、經過執行
hadoop fs -ls viewfs://my-cluster/
咱們看到的結果是同樣的,這是呈現給用戶的,而實際上,咱們看到的結果在第二步mountTable.xml文件中配置獲得的,經過這個配置咱們能夠知道,結果中呈現的viewfs://my-cluster/user
這個目錄由master的這個NameNode來管理的,viewfs://my-cluster/tmp
這個目錄也是由master的這個NameNode來管理的,而viewfs://my-cluster/projects
這個目錄是由slave1這個NameNode來管理的。