1. hadoop的搭建
hadoop的搭建可參考文章 http://www.powerxing.com/install-hadoop/,文章比較完整且詳細(xì)的介紹了單機(jī)和偽分布的搭建。
2. mapreduce的學(xué)習(xí)
mapreduce程序的學(xué)習(xí),可參考官方的mapreduce tutorial。同樣附上鏈接http://hadoop.apache.org/docs/r2.8.3/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html
(由于我本地裝的是hadoop2.8所以參考的是2.8系列的,別的版本可以參考別的對(duì)應(yīng)版本下的指導(dǎo)文檔)
3. 調(diào)試遇到的問(wèn)題總結(jié):
在調(diào)試2中的wordcount的程序的時(shí)候,遇到了兩個(gè)問(wèn)題吧。
(1).? ?Output directory hdfs://localhost:9000/output2 already exists
執(zhí)行命令?./bin/hadoop jar wc.jar WordCount2 /input1 /output2
之后提示??Exception in thread "main" org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory hdfs://localhost:9000/output2 already exists
從報(bào)錯(cuò)信息可以看出輸出目錄output2已經(jīng)存在了。在hadoop執(zhí)行mapreduce的輸出路徑一定要先保證是不存在的,如果存在就會(huì)有這樣的問(wèn)題。刪除掉./bin/hadoop dfs -rm -r output2之后,就成功了。
(2).? ?Input path does not exist: hdfs://localhost:9000/input1
在執(zhí)行命令./bin/hadoop jar wc.jar WordCount2 /input1 /output2之后提示出了這樣的一個(gè)錯(cuò)誤。
使用./bin/hadoop dfs -ls查看確實(shí)存在了input1文件,那提示這樣的原因是什么呢?原來(lái)是命令的路徑前不用加 /,可能hdfs文件系統(tǒng)不需要加/吧。
所以命令改成?./bin/hadoop jar wc.jar WordCount2 input1 output2? 這樣再執(zhí)行后,成功。