設置Hadoop環境 王耀聰 陳威宇 Jazz@nchc.org.tw waue@nchc.org.tw 2008. 03 . 30-31
Hadoop 單機設定與啟動 step 1. 設定登入免密碼 step 2. 安裝java step 3. 下載安裝Hadoop step 4.1 設定 hadoop-env.sh export JAVA_HOME=/usr/lib/jvm/java-6-sun step 4.2 設定 hadoop-site.xml 設定Namenode-> hdfs://localhost:9000 設定Jobtracker -> localhost:9001 step 5.1 格式化HDFS bin/hadoop namenode -format step 5.2 啟動Hadoop bin/start-all.sh step 6. 完成!檢查運作狀態 Job admin http://localhost:50030/ HDFS http://localhost:50070/
Hadoop 單機環境示意圖 Node 1 Localhost Namenode JobTracker Datanode conf / hadoop.site.xml: Localhost fs.default.name -> hdfs://localhost:9000 mapred.job.tracker -> localhost:9001 Namenode localhost:50070 JobTracker localhost:50030 conf/slaves: Datanode Tasktracker localhost
Hadoop 叢集設定與啟動 step 4.2 設定 hadoop-site.xml step 4.3 設定slaves 檔 step 2. 安裝java step 3. 下載安裝Hadoop step 4.1 設定 hadoop-env.sh export JAVA_HOME=/usr/lib/jvm/java-6-sun step 4.2 設定 hadoop-site.xml 設定Namenode-> hdfs://x.x.x.1:9000 設定Jobtracker -> x.x.x.2:9001 step 4.3 設定slaves 檔 step 4.4 將叢集內的電腦Hadoop都做一樣的配置 step 5.1 格式化HDFS bin/hadoop namenode -format step 5.2 啟動Hadoop nodeN執行: bin/start-dfs.sh ; nodeJ執行: bin/start-mapred.sh step 6. 完成!檢查運作狀態 Job admin http://x.x.x.2:50030/ HDFS http://x.x.x.1:50070/
情況一 Node 1 Node 2 x.x.x.1 x.x.x.2 Namenode JobTracker Datanode conf / hadoop.site.xml: x.x.x.1 x.x.x.2 http://x.x.x.1:50070 fs.default.name -> hdfs://x.x.x.1:9000 mapred.job.tracker -> x.x.x.2:9001 Namenode JobTracker http://x.x.x.2:50030 conf/slaves: Datanode Tasktracker Datanode Tasktracker x.x.x.1 x.x.x.2
情況二 Node 1 Node 2 x.x.x.1 Namenode JobTracker x.x.x.2 Datanode conf / hadoop.site.xml: x.x.x.1 http://x.x.x.1:50070 fs.default.name -> hdfs://x.x.x.1:9000 mapred.job.tracker -> x.x.x.1:9001 Namenode http://x.x.x.1:50030 JobTracker Node 2 x.x.x.2 conf/slaves: Datanode Tasktracker Datanode Tasktracker x.x.x.1 x.x.x.2
情況三 … Node 1 Node 2 Node N Namenode JobTracker x.x.x.2 x.x.x.n conf / hadoop.site.xml: Node 1 x.x.x.1 fs.default.name -> hdfs://x.x.x.1:9000 mapred.job.tracker -> x.x.x.1:9001 http://x.x.x.1:50070 Namenode JobTracker http://x.x.x.1:50030 Node 2 Node N conf/slaves: x.x.x.2 x.x.x.n x.x.x.2 ….. x.x.x.n Datanode Tasktracker Datanode Tasktracker …
情況四 conf / hadoop.site.xml: mapred.job.tracker -> x.x.x.2:9001 fs.default.name -> hdfs://x.x.x.1:9000 http://x.x.x.2:50030 http://x.x.x.1:50070 conf/slaves: x.x.x.3 ……. x.x.x.n
設定檔:hadoop-env.sh 設定Linux系統執行Hadoop的環境參數 export xxx=kkk # string… 將kkk這個值匯入到xxx參數中 # string… 註解,通常用來描述下一行的動作內容 # The java implementation to use. Required. export JAVA_HOME=/usr/lib/jvm/java-6-sun export HADOOP_HOME=/opt/hadoop export HADOOP_LOG_DIR=$HADOOP_HOME/logs export HADOOP_SLAVES=$HADOOP_HOME/conf/slaves ……….
設定檔: hadoop.site.xml <property> <name> mapred.map.tasks</name> <value> 1</value> <description> define mapred.map tasks to be number of slave hosts </description> </property> <name> mapred.reduce.tasks</name> <description> define mapred.reduce tasks to be number of slave hosts </description> <name> dfs.replication</name> <value> 3</value> </configuration> <configuration> <property> <name> fs.default.name</name> <value> hdfs://localhost:9000/</value> <description> … </description> </property> <name> mapred.job.tracker</name> <value> hdfs://localhost:9001/</value> <description>… </description> <name> hadoop.tmp.dir </name> <value> /tmp/hadoop/hadoop-${user.name} </value> <description> </description>
設定檔: hadoop.default.xml 沒在hadoop.site.xml設定的話就會用此檔案的值 更多的介紹參數:http://hadoop.apache.org/core/docs/current/cluster_setup.html#Configuring+the+Hadoop+Daemons
設定檔: slaves 被此檔紀錄到的節點就會至少有兩個身份: datanode & tasktracker 一行一個hostname 或 ip 192.168.1.1 …. 192.168.1.100 Pc101 Pc152
重要執行程序 格式化 開始與結束 $ bin/hadoop namenode -format $ bin/start-all.sh $ bin/start-dfs.sh $ bin/start-mapred.sh $ bin/stop-all.sh $ bin/stop-dfs.sh $ bin/stop-mapred.sh
重要指令程序 使用hadoop檔案系統指令 使用hadoop運算功能 $ bin/hadoop fs –Instruction bin/hadoop jar XXX.jar Main_Function …