阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Hadoop2.2.0版本多节点集群安装及测试

138次阅读
没有评论

共计 10645 个字符,预计需要花费 27 分钟才能阅读完成。

摘要:本文记录了 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

 

一:环境准备:

下载免费的 VMware Player 并安装好;
下载 免费的 Ubuntu 12.04 server 版并在 VMware 中安装好;
二:基础安装:

执行如下命令升级部分软件和把 ssh 安装好
  (1)sudo apt-get update;

  (2)sudo apt-get upgrade;

  (3)sudo apt-get install openssh-server;

安装 Oracle JDK
通过 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

创建 hadoop 用户
(1)  sudo addgroup hadoop

(2)  sudo adduser –ingroup hadoop hduser

编辑 /etc/sudoers 编辑文件,在 root ALL=(ALL)ALL 行下添加 hduser ALL=(ALL)ALL。如果不添加这行,hduser 将不能执行 sudo 操作。

注:以下操作均用 hduser 用户登录后操作。

 

三:公共安装:

注:以下操作以 hduser 登录进行操作。

下载 Hadoop2.2.0 版本
(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

配置 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。

配置 /home/hduser/hadoop/etc/hadoop/mapred-site.xml
(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>

配置 /home/hduser/hadoop/etc/hadoop/hdfs-site.xml
在 <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>

四:整体安装

将上面安装和配置好的虚拟机拷贝两份,即 Hadoop2 和 Hadoop3。
分别修改三台虚拟机的 /etc/hostname 中的内容改为相应的主机名,即
hadoop1 的 hostname 为 hadoop1,其他类推。

修改完成后需要重启,并通过命令 hostname 确认已经生效。

分别检查并修改三台虚拟机的 /etc/hosts 中的内容,确保包含如下配置:
192.168.128.130 hadoop1

192.168.128.131 hadoop2

192.168.128.132 hadoop3

为三台虚拟机之间建立 SSH 信任以便是实现无需密码登陆。
(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 来测试。

分别修改各台机子的 $HADOOP_HOME/etc/hadoop/slaves,这里 $HADOOP_HOME 为你的 hadoop 安装目录。Slaves 的内容如下:
hadoop2

hadoop3

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2013-10/92070p2.htm

相关阅读

Hadoop 2.0 安装向导 (0.23.x) http://www.linuxidc.com/Linux/2012-05/61463.htm

Hadoop 1.2.1 单节点安装 (Single Node Setup) 步骤 http://www.linuxidc.com/Linux/2013-08/89377.htm

在 CentOS 上安装 Hadoop http://www.linuxidc.com/Linux/2013-08/88600.htm

Ubuntu 12.04 安装 Hadoop http://www.linuxidc.com/Linux/2013-08/88187.htm

CentOS 6.3 x86_64 安装与配置 Hadoop-1.0 http://www.linuxidc.com/Linux/2013-07/87959.htm

Hadoop 入门 –Hadoop2 伪分布式安装 http://www.linuxidc.com/Linux/2013-06/86403.htm

Hadoop2.2.0 单节点安装及测试  http://www.linuxidc.com/Linux/2013-10/91911.htm

五:运行 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

摘要:本文记录了 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

 

一:环境准备:

下载免费的 VMware Player 并安装好;
下载 免费的 Ubuntu 12.04 server 版并在 VMware 中安装好;
二:基础安装:

执行如下命令升级部分软件和把 ssh 安装好
  (1)sudo apt-get update;

  (2)sudo apt-get upgrade;

  (3)sudo apt-get install openssh-server;

安装 Oracle JDK
通过 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

创建 hadoop 用户
(1)  sudo addgroup hadoop

(2)  sudo adduser –ingroup hadoop hduser

编辑 /etc/sudoers 编辑文件,在 root ALL=(ALL)ALL 行下添加 hduser ALL=(ALL)ALL。如果不添加这行,hduser 将不能执行 sudo 操作。

注:以下操作均用 hduser 用户登录后操作。

 

三:公共安装:

注:以下操作以 hduser 登录进行操作。

下载 Hadoop2.2.0 版本
(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

配置 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。

配置 /home/hduser/hadoop/etc/hadoop/mapred-site.xml
(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>

配置 /home/hduser/hadoop/etc/hadoop/hdfs-site.xml
在 <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>

四:整体安装

将上面安装和配置好的虚拟机拷贝两份,即 Hadoop2 和 Hadoop3。
分别修改三台虚拟机的 /etc/hostname 中的内容改为相应的主机名,即
hadoop1 的 hostname 为 hadoop1,其他类推。

修改完成后需要重启,并通过命令 hostname 确认已经生效。

分别检查并修改三台虚拟机的 /etc/hosts 中的内容,确保包含如下配置:
192.168.128.130 hadoop1

192.168.128.131 hadoop2

192.168.128.132 hadoop3

为三台虚拟机之间建立 SSH 信任以便是实现无需密码登陆。
(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 来测试。

分别修改各台机子的 $HADOOP_HOME/etc/hadoop/slaves,这里 $HADOOP_HOME 为你的 hadoop 安装目录。Slaves 的内容如下:
hadoop2

hadoop3

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2013-10/92070p2.htm

相关阅读

Hadoop 2.0 安装向导 (0.23.x) http://www.linuxidc.com/Linux/2012-05/61463.htm

Hadoop 1.2.1 单节点安装 (Single Node Setup) 步骤 http://www.linuxidc.com/Linux/2013-08/89377.htm

在 CentOS 上安装 Hadoop http://www.linuxidc.com/Linux/2013-08/88600.htm

Ubuntu 12.04 安装 Hadoop http://www.linuxidc.com/Linux/2013-08/88187.htm

CentOS 6.3 x86_64 安装与配置 Hadoop-1.0 http://www.linuxidc.com/Linux/2013-07/87959.htm

Hadoop 入门 –Hadoop2 伪分布式安装 http://www.linuxidc.com/Linux/2013-06/86403.htm

Hadoop2.2.0 单节点安装及测试  http://www.linuxidc.com/Linux/2013-10/91911.htm

六:查看 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

九:集群安装与单机安装的区别分析

core-site.xml 中配置的 fs.default.name 值的 IP 地址必须为 Master 节点,本文为 Hadoop1 节点;
hdfs-site.xml 中配置的 dfs.replication 值需要与实际的 DataNode 节点数一致,本文为 2;
mapred-site.xml 中配置的 mapred.job.tracker 值的 IP 地址必须为 Master 节点,本文为 Hadoop1 节点;
slaves 文件必须配置上实际的 slaves 节点,本文为 hadoop2 和 hadoop3;
每个主机的 /etc/hostname 和 /etc/hostname 必须做相应的配置以方便集群内部相互识别;
必须在集群内部用 ssh 建立起信任。

以上安装过程中还是出现了一些问题,但基本都通过 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 地址。

更多 Hadoop 相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计10645字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中