linuxsir首页 LinuxSir.Org | Linux、BSD、Solaris、Unix | 开源传万世,因有我参与欢迎您!
网站首页 | 设为首页 | 加入收藏
您所在的位置:主页 > Limux发行版SuSE >

CentOS下安装Eclipse测试Hadoop

时间:2018-01-01  来源:未知  作者:admin666

简单记录在CentOS下安装Eclipse测试Hadoop的过程。

(一),安装eclipse

   1,下载eclipse,点这里

   2,将文件上传到Centos7,可以用WinSCP

   3,解压并安装eclipse    

    [root@Master opt]# tar zxvf '/home/s/eclipse-jee-neon-1a-linux-gtk-x86_64.tar.gz' -C/opt  ---------------> 建立文件:[root@Master opt]# mkdir /usr/bin/eclipse     ------------------》添加链接,即快捷方式:[root@Master opt]# ln -s /opt/eclipse/eclipse /usr/bin/eclipse -----------》点击eclipse,即可启动了


(二),建立Hadoop项目

    1,下载hadoop plugin 2.7.3   链接:http://pan.baidu.com/s/1i5yRyuh 密码:ms91

    2,解压上述jar包插件,放到eclipse中plugins中,并重启eclipse

    2, 在eclipse中加载dfs库,点击Windows 工具栏-------->选择show view如图:

            

    2,打开resource  点击Window ----->Perspective----------->open Perspective  选择resource:

    3,配置连接端口,点击eclipse下放的MapResource Location,点击添加:其中port号按照hdfs-site.xml 和core-site.xml来填写。

    4,上传输入文件:使用hdfs dfs -put /home/file1  /data 即可在eclipse中看到如下:(要确保各个机器的防火墙都关闭,出现异常可以暂时不用关,后面跑下例子就全没了,呵呵)

 


  (三),测试WordCount程序

   1,新建项目:点击new ------------》project ----------->Map Reduce,如图:

   2,给项目配置本地的hadoop文件,圆圈处写本地hadoop的路径:

    

   3,新建个mappert类,写如下代码:

package word;

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 mapper {

public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{

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<Text,IntWritable,Text,IntWritable> {
private IntWritable result = new IntWritable();

public void reduce(Text key, Iterable<IntWritable> 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(otherArgs.length);
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "word count");
job.setJarByClass(mapper.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.out.print("ok");
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}

2,点击run as ------------>RunConfigurations ---------->设置input和output文件参数

  

3,点击run,查看结果

  

  文件的内容:

    

Hadoop项目之基于CentOS7的Cloudera 5.10.1(CDH)的安装部署  http://www.linuxidc.com/Linux/2017-04/143095.htm

Hadoop2.7.2集群搭建详解(高可用)  http://www.linuxidc.com/Linux/2017-03/142052.htm

使用Ambari来部署Hadoop集群(搭建内网HDP源)  http://www.linuxidc.com/Linux/2017-03/142136.htm

Ubuntu 14.04下Hadoop集群安装  http://www.linuxidc.com/Linux/2017-02/140783.htm

CentOS 6.7安装Hadoop 2.7.2  http://www.linuxidc.com/Linux/2017-08/146232.htm

Ubuntu 16.04上构建分布式Hadoop-2.7.3集群  http://www.linuxidc.com/Linux/2017-07/145503.htm

CentOS 7.3下Hadoop2.8分布式集群安装与测试  http://www.linuxidc.com/Linux/2017-09/146864.htm

CentOS 7 下 Hadoop 2.6.4 分布式集群环境搭建  http://www.linuxidc.com/Linux/2017-06/144932.htm

Hadoop2.7.3+Spark2.1.0完全分布式集群搭建过程  http://www.linuxidc.com/Linux/2017-06/144926.htm

更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13

友情链接