Hadoop2.2.0版本多节点集群安装及测试
Hadoop2.2.0版本多节点集群安装及测试
作者:雨水, 日期:2013-10-28, CSDN博客:http://blog.csdn.net/gobitan
摘要:本文记录了Hadoop2.2.0版本多节点集群安装过程,并做了基本配置,启动运行和测试了一个单词统计例子。
环境说明:
基于Windows下的VMware Player4.0.3中的ubuntu12.04-64server安装,先把基础软件安装到一个虚拟机中,然后拷贝两份再配置下即可。三台机器的分工如下:
Hadoop1(Master): NameNode/ResouceManager
Hadoop2(Slave):DataNode/NodeManager
Hadoop3(Slave): DataNode/NodeManager
假定三台虚拟机的IP地址如下,后面会用到。
Hadoop1:192.168.128.130
Hadoop2:192.168.128.131
Hadoop3:192.168.128.132
一:环境准备:
二:基础安装:
(1)sudo apt-get update;
(2)sudo apt-get upgrade;
(3)sudo apt-get install openssh-server;
通过webupd8team自动安装,执行命令如下:
(1) sudo apt-get install python-software-properties
(2) sudo add-apt-repository ppa:webupd8team/java
(3) sudo apt-get update
(4) sudo apt-get install oracle-java6-installer
(1) sudo addgroup hadoop
(2) sudo adduser --ingroup hadoop hduser
编辑/etc/sudoers编辑文件,在root ALL=(ALL)ALL行下添加hduser ALL=(ALL)ALL。如果不添加这行,hduser将不能执行sudo操作。
注:以下操作均用hduser用户登录后操作。
三:公共安装:
注:以下操作以hduser登录进行操作。
(1) cd /home/hduser
(2) $ wgethttp://apache.dataguru.cn/hadoop/common/hadoop-2.2.0/hadoop-2.2.0.tar.gz
(3) $ tar zxf hadoop-2.2.0.tar.gz
(4) $ mv hadoop-2.2.0 hadoop
(1) 配置/home/hduser/hadoop/etc/hadoop/hadoop-env.sh
替换exportJAVA_HOME=${JAVA_HOME}为如下:
export JAVA_HOME=/usr/lib/jvm/java-6-oracle
(2) 配置/home/hduser/hadoop/etc/hadoop/core-site.xml,
在<configuration>中添加如下:
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hduser/hadoop/tmp/hadoop-${user.name}</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://192.168.128.130:8010</value>
<description>The name of the default file system. A URI whose
schemeand authority determine the FileSystem implementation. The
uri'sscheme determines the config property (fs.SCHEME.impl) naming
theFileSystem implementation class. Theuri's authority is used to
determine the host, port, etc. for a filesystem.</description>
</property>
注意:以下两点务必确保正确,否则后面会出错。
a. 需执行mkdird home/hduser/hadoop/tmp创建这个临时目录;
b. 这个fd.default.name值的IP地址为NameNode的地址,即Hadoop1。
(1) mv /home/hduser/hadoop/etc/hadoop/mapred-site.xml.template/home/hduser/hadoop/etc/hadoop/mapred-site.xml
(2) 在<configuration>中添加如下:
<property>
<name>mapred.job.tracker</name>
<value>192.168.128.130:54311</value>
<description>The host and port that theMapReduce job tracker runs
at. If "local", thenjobs are runin-process as a single map
and reducetask.
</description>
</property>
在<configuration>中添加如下:
<property>
<name>dfs.replication</name>
<value>2</value>
<description>Default block replication.
Theactual number of replications can be specified when the file is created.
Thedefault is used if replication is not specified in create time.
</description>
</property>
四:整体安装
hadoop1的hostname为hadoop1,其他类推。
修改完成后需要重启,并通过命令hostname确认已经生效。
192.168.128.130 hadoop1
192.168.128.131 hadoop2
192.168.128.132 hadoop3
(1) 将以下命令分别在三台机子上做一遍:
$echo"" > .ssh/authorized_keys
$ssh-keygen-t rsa -P ""
$cat.ssh/id_rsa.pub >>.ssh/authorized_keys
(2) 分别将各台机子上的.ssh/id_rsa.pub的内容追加到其他两台的.ssh/authorized_keys中,这样三台机子相互访问就不需要输入密码了。可通过ssh hadoop1来测试。
hadoop2
hadoop3
五:运行Hadoop
注:所有的运行只需要在hadoop1的master节点即可。系统会自动登录到其他两台去启动相应的节点。
在初次运行Hadoop的时候需要初始化Hadoop文件系统,命令如下:
$cd /home/hduser/hadoop/bin
$./hdfs namenode -format
如果执行成功,你会在日志中(倒数几行)找到如下成功的提示信息:
common.Storage: Storage directory /home/hduser/hadoop/tmp/hadoop-hduser/dfs/namehas been successfully formatted.
运行命令如下:
$cd home/hduser/hadoop/sbin/
$./start-dfs.sh
$./start-yarn.sh
启动完之后可分别用jps命令查看各个机子的进程是否正常,如下:
hduser@hadoop1:~/hadoop$jps
1777 ResourceManager
1464 NameNode
1618 SecondaryNameNode
hduser@hadoop2:~$ jps
1264 DataNode
1344 NodeManager
hduser@hadoop3:~$ jps
1289 NodeManager
1209 DataNode
还可以通过bin/hdfs dfsadmin -report查看dfs是否正常,相应如下:
hduser@hadoop1:~/hadoop$ bin/hdfs dfsadmin -report
Configured Capacity:40668069888 (37.88 GB)
Present Capacity:34336370688 (31.98 GB)
DFS Remaining:34334142464 (31.98 GB)
DFS Used: 2228224(2.13 MB)
DFS Used%: 0.01%
Under replicatedblocks: 0
Blocks with corruptreplicas: 0
Missing blocks: 0
-------------------------------------------------
Datanodes available:2 (2 total, 0 dead)
Live datanodes:
Name:192.168.128.131:50010 (hadoop2)
Hostname: hadoop2
Decommission Status: Normal
Configured Capacity:20334034944 (18.94 GB)
DFS Used: 1114112(1.06 MB)
Non DFS Used:3165851648 (2.95 GB)
DFS Remaining:17167069184 (15.99 GB)
DFS Used%: 0.01%
DFS Remaining%:84.43%
Last contact: MonOct 28 19:12:16 PDT 2013
Name:192.168.128.132:50010 (hadoop3)
Hostname: hadoop3
Decommission Status: Normal
Configured Capacity:20334034944 (18.94 GB)
DFS Used: 1114112(1.06 MB)
Non DFS Used:3165847552 (2.95 GB)
DFS Remaining:17167073280 (15.99 GB)
DFS Used%: 0.01%
DFS Remaining%:84.43%
Last contact: MonOct 28 19:12:16 PDT 2013
六:查看Hadoop资源管理器
http://192.168.128.130:8088/,将其中的192.168.128.130替换为你的Hadoop1的IP地址。
七:测试Hadoop
cd /home/hduser
$wget http://www.gutenberg.org/cache/epub/20417/pg20417.txt
$cd hadoop
$ bin/hdfs dfs -mkdir /tmp
$ bin/hdfs dfs -copyFromLocal /home/hduser/pg20417.txt /tmp
bin/hdfs dfs -ls /tmp
$bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-2.2.0.jarwordcount /tmp/ /tmp-output
如果一切正常的话,会输入相应的结果,可以从屏幕输出看到。
八:停止Hadoop
若停止hadoop,依次运行如下命令:
$./stop-yarn.sh
$./stop-dfs.sh
九:集群安装与单机安装的区别分析
以上安装过程中还是出现了一些问题,但基本都通过baidu和google解决了。有个错误花费了较多时间,这里记录下,以供参考。
错误现象:13/10/2807:19:03 WARN hdfs.DFSClient: DataStreamer Exception org.apache.hadoop.ipc.RemoteException(java.io.IOException):File /tmp/pg20417.txt._COPYING_ could only be replicated to 0 nodes instead ofminReplication (=1). There are 0datanode(s) running and no node(s) are excluded in this operation.
发生地方:执行bin/hdfs dfs -copyFromLocal /home/hduser/pg20417.txt /tmp时
原因定位:后来经过反复查看,是因为fs.default.name的值中的IP地址配置成 localhost了,导致系统找不到hdfs.是在datanode的日志中发现这个错误的,日志如下:
2013-10-28 07:33:55,963 WARNorg.apache.hadoop.hdfs.server.datanode.DataNode: Problem connecting to server:localhost/127.0.0.1:8010
解决办法:将fs.default.name中的IP地址改为192.168.128.130,即你的master节点的IP地址。
十:参考资料