Hadoop學習01_Single Node Setup

目的

本文的目的主要是爲了說明如何單點配置hadoop,從而能使用單個節點進行Hadoop MapReduce 和Hadoop Distributed File System (HDFS)運算。 html

先決條件

平臺支持

  • GNU/Linux 做爲開發和生產環境. Hadoop 已經在 GNU/Linux 上驗證了 2000 個節點的集羣.
  • Win32  也能夠做爲開發環境. 分佈式操做不能再 Win32上進行很好的測試, 因此不能做爲生產環境。

必要的軟件

不管在Linux 仍是在 Windows都須要以下軟件: node

  1. JavaTM 1.6.x, 最好使用Sun的,必定要安裝.
  2. ssh 必定要安裝而且 sshd 必定要處於運行狀態,從而使Hadoop scripts能夠管理遠程Hadoop實例(Hadoop daemons).

另外 Windows 環境還須要安裝以下軟件: web

  1. Cygwin - 爲以上安裝的軟件提供shell腳本支持.

安裝軟件

若是你的集羣沒有安裝必要的軟件,請安裝他們. shell

Ubuntu Linux 的一個例子: express

$ sudo apt-get install ssh
$ sudo apt-get install rsync
在 Windows上, 若是在你安裝cygwin的時候你沒有安裝必要的軟件, 開啓cygwin安裝軟件選擇以下文件夾:


  • openssh - the Net category

下載

從這裏下載一個穩定版本 stable release . apache

準備開始配置Hadoop

解壓下載的Hadoop distribution文件. 編輯 conf/hadoop-env.sh 定義 JAVA_HOME 到你的安裝目錄. ssh

嘗試使用以下命令: 分佈式

$ bin/hadoop
將展現出對於使用 hadoop script 有用的文檔信息.


如今你能夠開始如下三種中的一種你的開啓你的 Hadoop cluster : oop

  • 單機模式(Local (Standalone) Mode)
  • 僞分佈式模式(Pseudo-Distributed Mode)
  • 全分佈式模式(Fully-Distributed Mode)

單機模式操做

在默認狀況下會以非分佈式模式(non-distributed mode)做爲一個Java進程運行.這樣作的好處是有利於調試..

The following example copies the unpacked conf directory to use as input and then finds and displays every match of the given regular expression. Output is written to the given output directory. 學習

$ mkdir input
$ cp conf/*.xml input
$ bin/hadoop jar hadoop-examples-*.jar grep input output 'dfs[a-z.]+'
$ cat output/*

僞分佈式模式操做

Hadoop也能夠運行一個單點,每一個Hadoop 實例(daemon) 以一個獨立的Java進程運行,從而使Hadoop以僞分佈式模式運行。

配置以下

使用以下配置:

conf/core-site.xml:

<configuration>
     <property>
         <name>fs.default.name</name>
         <value>hdfs://localhost:9000</value>
     </property>
</configuration>


conf/hdfs-site.xml:

<configuration>
     <property>
         <name>dfs.replication</name>
         <value>1</value>
     </property>
</configuration>


conf/mapred-site.xml:

<configuration>
     <property>
         <name>mapred.job.tracker</name>
         <value>localhost:9001</value>
     </property>
</configuration>

設置無密碼 ssh

檢查您能夠經過 ssh登陸 localhost 不適用密碼:

$ ssh localhost


If you cannot ssh to localhost without a passphrase, execute the following commands:
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys


運行

格式化一個分佈式文件系統:

$ bin/hadoop namenode -format
運行hadoop daemons:
$ bin/start-all.sh


hadoop daemon 把日誌輸出在 ${HADOOP_LOG_DIR} 指定的目錄下 (默認在 ${HADOOP_HOME}/logs).

瀏覽NameNode和JobTracker的web接口,默認狀況下在:

拷貝文件到分佈式系統:

$ bin/hadoop fs -put conf input


運行提供的例子:

$ bin/hadoop jar hadoop-examples-*.jar grep input output 'dfs[a-z.]+'


檢查輸出的文件:

拷貝輸出的文件到本地文件系統,而且檢查他們:

$ bin/hadoop fs -get output output
$ cat output/*
或者,你也能夠這麼作,

瀏覽分佈式系統上輸出的文件:

$ bin/hadoop fs -cat output/*
當你完成工做以後,使用以下命令中止daemons:
$ bin/stop-all.sh
以上是本人我的爲了學習hadoop,對官方的文檔的翻譯,若有差錯,請你們指正!謝謝。

官網該篇的地址是:http://hadoop.apache.org/docs/stable/single_node_setup.html

相關文章
相關標籤/搜索