eclipse怎么搭建hadoop環(huán)境

這篇文章主要講解了“eclipse怎么搭建hadoop環(huán)境”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“eclipse怎么搭建hadoop環(huán)境”吧!

這篇文章主要講解了“eclipse怎么搭建hadoop環(huán)境”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“eclipse怎么搭建hadoop環(huán)境”吧!

一、安裝Eclipse

員工經(jīng)過長期磨合與沉淀,具備了協(xié)作精神,得以通過團隊的力量開發(fā)出優(yōu)質(zhì)的產(chǎn)品。成都創(chuàng)新互聯(lián)公司堅持“專注、創(chuàng)新、易用”的產(chǎn)品理念,因為“專注所以專業(yè)、創(chuàng)新互聯(lián)網(wǎng)站所以易用所以簡單”。公司專注于為企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站建設、微信公眾號開發(fā)、電商網(wǎng)站開發(fā),微信小程序定制開發(fā),軟件定制網(wǎng)站開發(fā)等一站式互聯(lián)網(wǎng)企業(yè)服務。

    下載Eclipse,解壓安裝,例如安裝到/usr/local,即/usr/local/eclipse

    4.3.1版本下載地址:http://pan.baidu.com/s/1eQkpRgu

二、在eclipse上安裝hadoop插件

    1、下載hadoop插件

        下載地址:http://pan.baidu.com/s/1mgiHFok

     此zip文件包含了源碼,我們使用使用編譯好的jar即可,解壓后,release文件夾中的hadoop.eclipse-kepler-plugin-2.2.0.jar就是編譯好的插件。

   2、把插件放到eclipse/plugins目錄下

    3、重啟eclipse,配置Hadoop installation directory    

     如果插件安裝成功,打開Windows—Preferences后,在窗口左側(cè)會有Hadoop Map/Reduce選項,點擊此選項,在窗口右側(cè)設置Hadoop安裝路徑。

4、配置Map/Reduce Locations

     打開Windows—Open Perspective—Other

 選擇Map/Reduce,點擊OK

    在右下方看到如下圖所示

    

點擊Map/Reduce Location選項卡,點擊右邊小象圖標,打開Hadoop Location配置窗口:

    輸入Location Name,任意名稱即可.配置Map/Reduce Master和DFS Mastrer,Host和Port配置成與core-site.xml的設置一致即可。

    

點擊"Finish"按鈕,關(guān)閉窗口。

 點擊左側(cè)的DFSLocations—>myhadoop(上一步配置的location name),如能看到user,表示安裝成功

   


    如果如下圖所示表示安裝失敗,請檢查Hadoop是否啟動,以及eclipse配置是否正確。

三、新建WordCount項目

    File—>Project,選擇Map/Reduce Project,輸入項目名稱WordCount等。

    在WordCount項目里新建class,名稱為WordCount,代碼如下:

import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; public class WordCount { public static class TokenizerMapper extends Mapper{   private final static IntWritable one = new IntWritable(1);  private Text word = new Text();   public void map(Object key, Text value, Context context) throws IOException, InterruptedException {    StringTokenizer itr = new StringTokenizer(value.toString());      while (itr.hasMoreTokens()) {        word.set(itr.nextToken());        context.write(word, one);      }  }} public static class IntSumReducer extends Reducer {  private IntWritable result = new IntWritable();   public void reduce(Text key, Iterable values,Context context) throws IOException, InterruptedException {    int sum = 0;    for (IntWritable val : values) {      sum += val.get();    }    result.set(sum);    context.write(key, result);  }} public static void main(String[] args) throws Exception {  Configuration conf = new Configuration();  String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();  if (otherArgs.length != 2) {    System.err.println("Usage: wordcount  ");    System.exit(2);  }  Job job = new Job(conf, "word count");  job.setJarByClass(WordCount.class);  job.setMapperClass(TokenizerMapper.class);  job.setCombinerClass(IntSumReducer.class);  job.setReducerClass(IntSumReducer.class);  job.setOutputKeyClass(Text.class);  job.setOutputValueClass(IntWritable.class);  FileInputFormat.addInputPath(job, new Path(otherArgs[0]));  FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));  System.exit(job.waitForCompletion(true) ? 0 : 1);}}四、運行

    1、在HDFS上創(chuàng)建目錄input

        hadoop fs -mkdir input

    2、拷貝本地README.txt到HDFS的input里

         hadoop fs -copyFromLocal /usr/local/hadoop/README.txt input

    3、點擊WordCount.java,右鍵,點擊Run As—>Run Configurations,配置運行參數(shù),即輸入和輸出文件夾

hdfs://localhost:9000/user/hadoop/input hdfs://localhost:9000/user/hadoop/output

    

點擊Run按鈕,運行程序。

    4、運行完成后,查看運行結(jié)果        

        方法1:

        hadoop fs -ls output

        可以看到有兩個輸出結(jié)果,_SUCCESS和part-r-00000

        執(zhí)行hadoop fs -cat output/*
        

        方法2:

        展開DFS Locations,如下圖所示,雙擊打開part-r00000查看結(jié)果

本文題目:eclipse怎么搭建hadoop環(huán)境
文章路徑:http://muchs.cn/article6/seog.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設計、品牌網(wǎng)站制作、搜索引擎優(yōu)化、企業(yè)建站、網(wǎng)站建設、自適應網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名