Hadoop2.2.0單節點安裝及測試

Hadoop2.2.0單節點安裝及測試

作者:雨水, 日期:2013-10-24, CSDN博客:http://blog.csdn.net/gobitan

摘要:本文記錄了Hadoop單節點安裝過程,並做了基本配置,啓動運行和測試了一個單詞統計例子。

 

一:環境準備:基於Windows下的VMware Player4.0.3中的ubuntu12.04-64server.

  1. 下載免費的VMware Player並安裝好;
  2. 下載 免費的Ubuntu 12.04 server版並在VMware中安裝好;

二:基礎安裝:

  1. 執行如下命令升級部分軟件和把ssh安裝好:

  (1) sudo apt-get update;

  (2) sudo apt-get upgrade;

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

  1. 有兩種方法可以安裝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.6http://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環境變量中即可。

  1. 創建hadoop用戶。

(1)   sudo addgroup hadoop

(2)   sudo adduser --ingroup hadoop hduser

  1. 建立SSH信任關係,登錄localhost就不需要密碼

$ cd /home/hduser

$ ssh-keygen -t rsa -P ""    #直接回車

$cat .ssh/id_rsa.pub >>.ssh/authorized_keys

        注:可通過ssh localhost命令驗證。

三:正式安裝:

注:以下操作以hduser登錄進行操作。

  1. 下載hadoop2.2版本。地址:http://apache.dataguru.cn/hadoop/common/hadoop-2.2.0/hadoop-2.2.0.tar.gz
  2.  執行tar zxf hadoop-2.2.0.tar.gz解壓至當前目錄/home/hduser目錄下。
  3. mv hadoop-2.2.0 hadoop

四:配置hadoop:

  1. 編輯/home/hduser/hadoop/etc/hadoop/hadoop-env.sh

替換exportJAVA_HOME=${JAVA_HOME}爲如下:

exportJAVA_HOME=/usr/lib/jvm/java-6-oracle

  1. 編輯/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/創建它,否則後面運行會報錯。

  1. 編輯/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>

  1. 編輯/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

 

九:參考資料

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章