CentOS under install Eclipse test Hadoop

Source: Internet
Author: User
Tags hdfs dfs

(i), install eclipse

1, download eclipse, click here

2, upload the file to Centos7, you can use WINSCP

3. Unzip and install eclipse

[Email protected] opt]# tar zxvf '/home/s/eclipse-jee-neon-1a-linux-gtk-x86_64.tar.gz '-c/opt---------------> Build file: [[email protected] opt]# mkdir/usr/bin/eclipse------------------Add link, shortcut: [[email protected] opt]# ln-s/opt /eclipse/eclipse/usr/bin/eclipse-----------"Click Eclipse to launch the

(ii) Creation of Hadoop projects

1, download Hadoop plugin 2.7.3 link: http://pan.baidu.com/s/1i5yRyuh Password: ms91

2, unzip the jar package plug-in, put it into Eclipse plugins, and restart Eclipse

2. Load the DFS library in eclipse, click on the Windows toolbar--------> select Show view

            

2. Open Resource Click Window----->perspective----------->open Perspective Select resource:

3. Configure the connection port, click Mapresource Location under Eclipse, click Add: Where port number is filled in by Hdfs-site.xml and Core-site.xml.

4. Upload the input file: use HDFs Dfs-put/home/file1/data to see the following in eclipse: (to ensure that each machine's firewall is closed, the exception can be temporarily off, run the following example is all gone, hehe)

(iii) test the WordCount procedure

1, New project: Click New------------Project----------->map Reduce,

2, configure the local Hadoop file for the project, and write the path to the local Hadoop at the circle:

    

3, create a new Mappert class, write the following code:

    

 1 package word; 2 3 Import java.io.IOException; 4 Import Java.util.StringTokenizer; 5 6 Import Org.apache.hadoop.conf.Configuration; 7 Import Org.apache.hadoop.fs.Path; 8 Import org.apache.hadoop.io.IntWritable; 9 Import org.apache.hadoop.io.text;10 Import org.apache.hadoop.mapreduce.job;11 Import ORG.APACHE.HADOOP.MAPREDUCE.MAPPER;12 Import org.apache.hadoop.mapreduce.reducer;13 Import ORG.APACHE.HADOOP.MAPREDUCE.LIB.INPUT.FILEINPUTFORMAT;14 Import ORG.APACHE.HADOOP.MAPREDUCE.LIB.OUTPUT.FILEOUTPUTFORMAT;15 Import org.apache.hadoop.util.genericoptionsparser;16 public class Mapper {Tokenizermapper extends Mapper<object, text, text, intwritable> {The private final static intwritable one = new intwritable (1), and the. Text Word = new text (); public void Map (O Bject key, Text value, Context context26) throws IOException, interruptedexception {stringtokenizer ITR = new Stringto Kenizer (Value.tostring ()); while (Itr.hasmoretokens ()) {WORD.set (Itr.nexttoken ()); Context.write (Word, one),}32}33}34 public static class Intsumreducer extends reducer& Lt text,intwritable,text,intwritable> {PNS Private intwritable result = new intwritable (); , iterable<intwritable> values, context41) throws IOException, interruptedexception {int sum = 0;43 F or (intwritable val:values) {Sum of $ + = Val.get ();}46 result.set (sum); Context.write (key, result);}49}50 Wuyi Publ IC static void Main (string[] args) throws Exception {string[configuration conf = new Configuration (); = new Genericoptionsparser (conf, args). Getremainingargs (); if (otherargs.length! = 2) {System.err.println ( Otherargs.length), System.err.println ("Usage:wordcount <in> <out>"), System.exit (2),}60 job Job = New Job (conf, "word count"); Job.setjarbyclass (Mapper.class); Job.setmapperclass (Tokenizermapper.class); 63 Job.setcombinerclass (Intsumreducer.class);B.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.out.print ("OK"); System.exit (Job.waitforcompletion (true)? 0:1); 71}72}

2. Click Run as------------>runconfigurations----------> Set input and output file parameters

  

3, click Run to view the results

  

The contents of the file:

    

CentOS under install Eclipse test Hadoop

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.