您的位置:首页 > 运维架构

Hadoop2.2.0单节点安装及测试

2013-11-18 10:54 344 查看
Hadoop2.2.0单节点安装及测试
作者:雨水, 日期:2013-10-24, CSDN博客:http://blog.csdn.net/gobitan
摘要:本文记录了Hadoop单节点安装过程,并做了基本配置,启动运行和测试了一个单词统计例子。

一:环境准备:基于Windows下的VMware Player4.0.3中的ubuntu12.04-64server.

下载免费的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
方法二:手动安装JDK1.6
(1) 下载jdk1.6 http://www.oracle.com/technetwork/java/javase/downloads/jdk6u37-downloads-1859587.html,选择jdk-6u37-linux-x64.bin。
(2) 执行chmod +x jdk-6u37-linux-x64.bin增加可执行权限;
(3) ./ jdk-6u37-linux-x64.bin直接解压即可,建议放在/opt目录下。
(4) 然后将解压后的bin目录加入到PATH环境变量中即可。

创建hadoop用户。

(1) sudo addgroup hadoop
(2) sudo adduser --ingroup hadoop hduser

建立SSH信任关系,登录localhost就不需要密码

$ cd /home/hduser
$ ssh-keygen -t rsa -P "" #直接回车
$cat .ssh/id_rsa.pub >>.ssh/authorized_keys
注:可通过ssh localhost命令验证。
三:正式安装:
注:以下操作以hduser登录进行操作。

下载hadoop2.2版本。地址:http://apache.dataguru.cn/hadoop/common/hadoop-2.2.0/hadoop-2.2.0.tar.gz
执行tar zxf hadoop-2.2.0.tar.gz解压至当前目录/home/hduser目录下。
mv hadoop-2.2.0 hadoop

四:配置hadoop:

编辑/home/hduser/hadoop/etc/hadoop/hadoop-env.sh

替换exportJ***A_HOME=${J***A_HOME}为如下:
exportJ***A_HOME=/usr/lib/jvm/java-6-oracle

编辑/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 temporarydirectories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:8010</value>
<description>The name of the default file system. A URI whose
scheme and authority determine the FileSystem implementation. The
uri's scheme determines the config property (fs.SCHEME.impl) naming
the FileSystem implementation class. The uri's authority is used to
determine the host, port, etc. for a filesystem.</description>
</property>
备注:配置了/home/hduser/hadoop/tmp/这个目录,必须执行mkdir /home/hduser/hadoop/tmp/创建它,否则后面运行会报错。

编辑/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>localhost:54311</value>
<description>The host and port that the MapReduce job tracker runs
at. If "local", thenjobs are run in-process as a single map
and reduce task.
</description>
</property>
<property>
<name>mapred.map.tasks</name>
<value>10</value>
<description>As a rule of thumb, use 10x the number of slaves(i.e., number of tasktrackers).
</description>
</property>
<property>
<name>mapred.reduce.tasks</name>
<value>2</value>
<description>As a rule of thumb, use 2x the number of slaveprocessors (i.e., number of tasktrackers).
</description>
</property>

编辑/home/hduser/hadoop/etc/hadoop/hdfs-site.xml,在<configuration>中添加如下:

<property>
<name>dfs.replication</name>
<value>1</value>
<description>Default block replication.
The actual number of replications can be specified when the file iscreated.
The default is used if replication is not specified in create time.
</description>
</property>
五:运行Hadoop
在初次运行Hadoop的时候需要初始化Hadoop文件系统,命令如下:
$cd /home/hduser/hadoop/bin
$./hdfs namenode -format
如果执行成功,你会在日志中(倒数几行)找到如下成功的提示信息:
common.Storage: Storage directory/home/hduser/hadoop/tmp/hadoop-hduser/dfs/name has been successfully formatted.
运行命令如下:
$cd /home/hduser/hadoop/sbin/
$./start-dfs.sh
注:该过程需要多次输入密码, 如果不想多次输入密码,可先用ssh建立信任。
hduser@ubuntu:~/hadoop/sbin$ jps
4266 SecondaryNameNode
4116 DataNode
4002 NameNode
注:用jps查看启动了三个进程。
$./start-yarn.sh
hduser@ubuntu:~/hadoop/sbin$ jps
4688 NodeManager
4266 SecondaryNameNode
4116 DataNode
4002 NameNode
4413 ResourceManager

六:查看Hadoop资源管理器
http://192.168.128.129:8088/,将其中的192.168.128.129替换为你的实际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.jar wordcount /tmp/ /tmp-output
如果一切正常的话,会输入相应的结果,可以从屏幕输出看到。

八:停止Hadoop
若停止hadoop,依次运行如下命令:
$./stop-yarn.sh
$./stop-dfs.sh

九:参考资料

https://sites.google.com/site/jianpengxu/tutorials/hadoop-setup
http://wenku.baidu.com/view/1681511a52d380eb62946df6.html

原文地址:点击打开链接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: