现在的位置: 首页 > 综合 > 正文

Apache Hadoop2.0 安装部署说明

2013年10月09日 ⁄ 综合 ⁄ 共 7042字 ⁄ 字号 评论关闭

Apache Hadoop 2.0 安装部署

1. 环境说明

        Hadoop的版本选用的hadoop-2.0.2-alpha,此版本的hadoop增加了诸如Fedreation等许多新功能。是目前Apache Hadoop最新的版本。

        Apache-Hadoop下载地址:

        http://www.apache.org/dyn/closer.cgi/hadoop/common/

    所有节点都是部署在CentOS的操作系统之上。所有节点的防火墙应该均已关闭。

    集群中节点信息如下:2namenode2datanode1zookeeper集群,1NFS服务器,节点之间局域网连接,可以相互ping通,并且设置好SSH无密钥登录。因为机器数量有限,所以namenodedatanode配置在一台机器上,节点IP地址分布如下:

NodeType

IP

NameNode

10.28.169.121

NameNode

10.28.169.122

DataNode1

10.28.169.122

DataNode0

10.28.169.225

节点的jdk实现配置好,NFS事先挂载到两个namenode上。

2. 安装NFS

        NFSNetworkFile System的简写,即网络文件系统.网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS.
NFS允许一个系统在网络上与它人共享目录和文件。通过使用NFS,用户和程序可以象访问本地文件一样访问远端系统上的文件。本文档中涉及到的NFS版本是NFS4。要注意使用NFS共享目录的用户的id号和groupID号必须一致!否则是不能使用的。

    在Hadoop中,NFS用来在namenode之间共享元数据和镜像文件。

        NFS安装见:

http://www.cnblogs.com/qyddbear/archive/2012/06/05/2536840.html

3. 安装zookeeper

         zookeeper也是hadoop开源项目中的一个子项目。在hadoop的应用中,zookeeper用来选举当前的activenamenode。本文档中zookeeper的版本是zookeeper3.4.3

         zookeeper安装见:

         http://blog.csdn.net/can007/article/details/7944072

4. 安装Hadoop

4.1 Hadoop2.0目录结构

    与以前的版本相比,Apache Hadoop2.0在架构上都有了很大的改变。目录结构以前的相比也有了很大的不同。以下是Hadoop2.0版本的目录结构:

其中:

1bin目录下是内层的调用脚本,在进行格式化namenode和格式化ZK等操作的时候,会用到这里的hadoop脚本或者hdfs脚本,要注意更改其中的关于jdk的目录设置和其他必要的设置;

2sbin目录下是外层的调用脚本,包括启动整个集群的start-dfs.sh脚本等都在此目录下;

3lib目录下是nativeso文件;

4libexec下是配置程序文件;

5etc的hadoop目录下是配置文件,和老版本的conf目录对应,比如core-site.xmlslaveshdfs-site.xml文件等都在此目录下;

6share目录下是存放的所有的jar包。

    在安装部署hadoop的时候,主要有两个配置文件需要修改,那就是hdfs-site.xmlcore-site.xml。下面就对着两个文件的修改进行说明。

4.2修改hdfs-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<property>
		<name>dfs.namenode.name.dir</name>
                <value>/data/hadoop2.0_nn_fsimage</value>
        </property>

	<property>
  		<name>dfs.namenode.edits.dir</name>
    		<value>/data/hadoop2.0_nn_edits</value>
  	</property>

	<property>
  		<name>dfs.datanode.data.dir</name>
		<value>/data/hadoop2.0_dn</value>
  	</property>

	<property>
  		<name>dfs.nameservices</name>
    		<value>goon</value>
  	</property>

	<property>
		<name>dfs.ha.namenodes.goon</name>
	  	<value>primaryNN,standbyNN</value>
	</property>

	<property>
		<name>dfs.namenode.rpc-address.goon.primaryNN</name>
	  	<value>sdc2:9000</value>
	</property>

	<property>
		<name>dfs.namenode.rpc-address.goon.standbyNN</name>
		<value>sdc1:9000</value>
	</property>

	<property>
	  	<name>dfs.namenode.http-address.goon.primaryNN</name>
    		<value>sdc2:50070</value>
  	</property>

	<property>
  		<name>dfs.namenode.http-address.goon.standbyNN</name>
	  	<value>sdc1:50070</value>
	</property>

	<property>
	  	<name>dfs.namenode.shared.edits.dir</name>
	  	<value>/data/hadoop2.0_shared</value>
	</property>

	<property>
    		<name>dfs.client.failover.proxy.provider.goon</name>
    		<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
	</property>
	
	<property>
	  	<name>dfs.ha.fencing.methods</name>
	  	<value>sshfence</value>
	</property>

	<property>
		<name>dfs.ha.fencing.ssh.private-key-files</name>
    		<value>/home/hadoop/.ssh/id_rsa</value>
	</property>

  	<property>
  		<name>dfs.ha.automatic-failover.enabled</name>
    		<value>true</value>
  	</property>

	<property>
  		<name>ha.zookeeper.quorum</name>
   		<value>10.28.169.225:2181</value>
	</property>
</configuration>

 

4.3 修改core-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<property>
    		<name>fs.defaultFS</name>
	    	<value>hdfs://goon</value> 
	</property>
</configuration>

 


 

4.4 修改mapred-site.xml文件

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<property>  
		<name>mapreduce.framework.name</name>  
		<value>yarn</value>  
	</property>    
	<property>  
		<name>mapred.system.dir</name>  
		<value>file:/data/hadoop2.0_mapred_sys</value>  
		<final>true</final>  
	</property>    
	<property>  
	<name>mapred.local.dir</name>  
		<value>file:/data/hadoop2.0_mapred_local</value>  
		<final>true</final>  
	</property>
</configuration>

 

4.5 修改yarn-site.xml文件

<?xml version="1.0"?>
<configuration>

	<property>
		<name>yarn.resourcemanager.address</name>
		<value>sdc2:18040</value>
		<description>The address of the applications manager interface in the RM.</description>
	</property>
	<property>
		<description>The address of the scheduler interface.</description>
		<name>yarn.resourcemanager.scheduler.address</name>
		<value>sdc2:18030</value>
	</property>
	<property>
		<description>The address of the RM web application.</description>
		<name>yarn.resourcemanager.webapp.address</name>
		<value>sdc2:18088</value>
	</property> 
	<property>
		<name>yarn.resourcemanager.resource-tracker.address</name>
		<value>sdc2:18025</value>
	</property>
	<property>
		<description>The address of the RM admin interface.</description>
		<name>yarn.resourcemanager.admin.address</name>
		<value>sdc2:18141</value>
	</property>
	<property>  
		<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>  
		<value>org.apache.hadoop.mapred.ShuffleHandler</value>  
	</property>
	<property>
		<name>yarn.nodemanager.aux-services</name>
		<value>mapreduce.shuffle</value>
	</property>
</configuration>

4.6 Namenode格式化

    在其中一个namenode中,执行如下命令进行namenode的格式化:
        bin/hadoop namenode –format –clusterid hadoop2.0
    格式化之后,要同步两个NameNode上的元数据。如果是新建的HDFS集群,按照dfs.namenode.name.dir 、dfs.namenode.edits.dir的配置把当前格式化的NameNode节点上的元数据目录复制到另一个NameNode,还应该确保共享存储目录下(dfs.namenode.shared.edits.dir )包含NameNode所有的元数据。此处的hadoop2.0是我们指定的clusterID。存储HDFS相关数据的目录结构如下(对应位置,见hdfs-site.xml文件):

 

4.7 ZK格式化

    格式化ZK使用如下命令:
        bin/hdfs zkfc -formatZK

4.8 HA

    使用如下命令启动整个集群:
        sbin/start-dfs.sh
    默认以HA 方式启动集群,若在hdfs.xml文件中的dfs.ha.automatic-failover.enabled配置true,则启动后系统会随机选举一个NameNode作为ActiveNameNode,另一个为StandbyNameNode;若在hdfs.xml文件中的dfs.ha.automatic-failover.enabled配置false,则启动后两个NameNode均为Standby状态,使用如下命令设置Active 节点 (手动方式)
        bin/hdfs haadmin -DFSHAadmin -transitionToActive primaryNN
    如果让sdc2 变为active sdc1变为standby,则
        bin/hdfs haadmin -DFSHAadmin –failover standbyNN primaryNN
    如果失败(is not ready to become active) 
        bin/hdfs haadmin -DFSHAadmin -failover --forceactive standbyNN primaryNN
    具体参照bin/hdfs haadmin命令。

也可以单独启动节点,命令如下:

hadoop-daemon.sh start/stop namenode 

hadoop-daemon.sh start/stop datanode

4.9 截图

    集群运行成功后,active namenodeweb界面截图:
 
    集群运行成功后,standby namenodeweb界面截图:
 
 
 



抱歉!评论已关闭.