hadoop2.7.3在集群中配置多个namenode(federation cluster)

http://blog.csdn.net/wild46cat/article/details/53423472


hadoop2.7.3在集群中配置多个namenode(federation cluster)

首先需要说明的是,在集群中配置多个namenode和在集群中使用secondaryNamenode是完完全全的两码事。具体是如何区分的,我之后会在写一篇haoop官方当中的译文,同时解释一下这两者的区别。在这里先简单的说一下。secondaryNamenode的作用是给namenode分担压力的,会定时的帮助namenode做一些处理。而配置多个namenode的相当于配置了一个联邦集群,每个anmenode之间都不会进行通信,各自管理各自的命名空间。

好,下面上货。
当然,完成本篇配置的前提:
1、已经能够配置单个namenode的hadoop集群。
2、haoop集群最好是完全分布式的(伪分布式没有测试,但是单点估计是不行。)

一、硬件环境:
host1 192.168.1.221
host2 192.168.1.222
host3 192.168.1.223

二、配置文件
其中,host1用作namenode,host2用作namenode,host3用作datanode。
配置文件(每个主机上的相同):hdfs-site.xml
[html] view plain copy
 print?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3. <configuration>  
  4.   
  5.     <property>  
  6.         <name>dfs.namenode.name.dir</name>  
  7.         <value>file:/home/hadoop/dfs/name</value>  
  8.     </property>  
  9.     <property>  
  10.         <name>dfs.datanode.data.dir</name>  
  11.         <value>file:/home/hadoop/dfs/data</value>  
  12.     </property>  
  13.     <property>  
  14.         <name>dfs.replication</name>  
  15.         <value>2</value>  
  16.     </property>  
  17.     <property>  
  18.     <name>dfs.webhdfs.enabled</name>  
  19.     <value>true</value>  
  20.     </property>  
  21.     <property>  
  22.     <name>dfs.datanode.max.transfer.threads</name>  
  23.     <value>4096</value>  
  24.     </property>  
  25.   
  26.     <property>  
  27.         <name>dfs.federation.nameservices</name>  
  28.         <value>host1,host2</value>  
  29.     </property>  
  30.   
  31.     <property>  
  32.         <name>dfs.namenode.rpc-address.host1</name>  
  33.         <value>host1:9000</value>  
  34.     </property>  
  35.     <property>  
  36.         <name>dfs.namenode.http-address.host1</name>  
  37.         <value>host1:50070</value>  
  38.     </property>  
  39.     <property>  
  40.         <name>dfs.namenode.secondary.http-address.host1</name>  
  41.         <value>host1:9001</value>  
  42.     </property>  
  43.       
  44.     <property>  
  45.         <name>dfs.namenode.rpc-address.host2</name>  
  46.         <value>host2:9000</value>  
  47.     </property>  
  48.     <property>  
  49.         <name>dfs.namenode.http-address.host2</name>  
  50.         <value>host2:50070</value>  
  51.     </property>  
  52.     <property>  
  53.         <name>dfs.namenode.secondary.http-address.host2</name>  
  54.         <value>host2:9001</value>  
  55.     </property>  
  56. </configuration>  


host1上的配置文件:core-site.xml
[html] view plain copy
 print?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3.   
  4. <configuration>  
  5. <property>  
  6.         <name>fs.defaultFS</name>  
  7.         <value>hdfs://host1:9000</value>  
  8.     </property>  
  9.     <property>  
  10.         <name>hadoop.tmp.dir</name>  
  11.         <value>file:/home/hadoop/tmp</value>  
  12.     </property>  
  13.     <property>  
  14.         <name>io.file.buffer.size</name>  
  15.         <value>131702</value>  
  16.     </property>  
  17. </configuration>  


host2上的配置文件:core-site.xml
[html] view plain copy
 print?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3.   
  4. <configuration>  
  5. <property>  
  6.         <name>fs.defaultFS</name>  
  7.         <value>hdfs://host2:9000</value>  
  8.     </property>  
  9.     <property>  
  10.         <name>hadoop.tmp.dir</name>  
  11.         <value>file:/home/hadoop/tmp</value>  
  12.     </property>  
  13.     <property>  
  14.         <name>io.file.buffer.size</name>  
  15.         <value>131702</value>  
  16.     </property>  
  17. </configuration>  


host3上的配置文件:core-site.xml(需要说明一下,这里的df.defaultFS配置成任意一个就可以了)
[html] view plain copy
 print?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3.   
  4. <configuration>  
  5. <property>  
  6.         <name>fs.defaultFS</name>  
  7.         <value>hdfs://host1:9000</value>  
  8.     </property>  
  9.     <property>  
  10.         <name>hadoop.tmp.dir</name>  
  11.         <value>file:/home/hadoop/tmp</value>  
  12.     </property>  
  13.     <property>  
  14.         <name>io.file.buffer.size</name>  
  15.         <value>131702</value>  
  16.     </property>  
  17. </configuration>  

注意,host3作为datanode没有使用core-site.xml中的配置,而host1和host2在进行文件读取的时候,都会先读取本地的core-site.xml这个配置文件。
三、测试截图

下面是一个简单的测试,用来显示和证明这两个namenode是分开的分别拥有自己的命名空间的。
首先是启动hadoop:
hadoop2.7.3在集群中配置多个namenode(federation cluster)

启动后,从web中看两个namenode的情况:
hadoop2.7.3在集群中配置多个namenode(federation cluster)
hadoop2.7.3在集群中配置多个namenode(federation cluster)
在host1中创建一个目录。
hadoop2.7.3在集群中配置多个namenode(federation cluster)
host1中的文件夹:
hadoop2.7.3在集群中配置多个namenode(federation cluster)

在host2中创建一个目录。
hadoop2.7.3在集群中配置多个namenode(federation cluster)
host2中的文件夹:
hadoop2.7.3在集群中配置多个namenode(federation cluster)

这样说明了两个namenode是分离的,分别保存着自己的文件块对应表。