阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS下安装Eclipse测试Hadoop

158次阅读
没有评论

共计 3874 个字符,预计需要花费 10 分钟才能阅读完成。

简单记录在 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 如图:

CentOS 下安装 Eclipse 测试 Hadoop

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

CentOS 下安装 Eclipse 测试 Hadoop

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

CentOS 下安装 Eclipse 测试 Hadoop

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

 CentOS 下安装 Eclipse 测试 Hadoop


(三),测试 WordCount 程序

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

CentOS 下安装 Eclipse 测试 Hadoop

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

CentOS 下安装 Eclipse 测试 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 文件参数

CentOS 下安装 Eclipse 测试 Hadoop

3,点击 run, 查看结果

CentOS 下安装 Eclipse 测试 Hadoop

文件的内容:

CentOS 下安装 Eclipse 测试 Hadoop

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

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-12/149907.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计3874字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中