轻松记录在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-- -
(二)启动Hadoop项目
1,hadoop plugin 2.7.3链接: http://pan.baidu.com/s/1i5yRyuh密码: ms91下载
2 )解压缩上述jar包插件,放入eclipse中的plugins中,然后重新启动eclipse
2、将dfs库加载到eclipse中,选择Windows工具栏-------showview的图:
2,打开资源并单击window---- perspective------ open perspective选择资源:
3、配置连接端口,单击eclipse下的地图资源位置,然后单击“添加”。 其中,端口编号按照hdfs-site.xml和core-site.xml填写。
4、上传输入文件:使用hdfs dfs -put /home/file1 /data,可以通过eclipse查看,如下所示。 ()确认各设备的防火墙已关闭,出现异常时暂时不用关闭。 从后面跑,例子都没有了。 啊,啊) )
(三)、测试WordCount程序
1、点击新建项目------------mapreduce。 图:
2 )在项目中放置本地hadoop文件,并在圆中写本地hadoop的路径:
3,创建新的mappert类,并编写以下代码:
打包word;
import java.io.IOException;
import Java.util.string tokenizer;
importorg.Apache.Hadoop.conf.configuration;
importorg.Apache.Hadoop.fs.path;
importorg.Apache.Hadoop.io.int writable;
importorg.Apache.Hadoop.io.text;
importorg.Apache.Hadoop.MapReduce.job;
importorg.Apache.Hadoop.MapReduce.mapper;
importorg.Apache.Hadoop.MapReduce.reducer;
importorg.Apache.Hadoop.MapReduce.lib.input.fileinputformat;
importorg.Apache.Hadoop.MapReduce.lib.output.fileoutputformat;
importorg.Apache.Hadoop.util.genericoptionsparser;
公共类映射器{
publicstaticclasstokenizermapper
扩展映射器{
私有金融工具可写性=newintwritable (1;
私有文本word=new text (;
公共void map (对象密钥,文本值,上下文上下文
) throws IOException,InterruptedException {
stringtokenizeritr=new string tokenizer (value.tostring ) );
while(ITR.hasmoretokens () ) )。
word.set(ITR.NextToken ) );
context.write(word,one );
}
}
}
公共静态类防毒墙群件版
扩展渲染器{
私密性writableresult=newintwritable (;
public void reduce (文本密钥,可交织值,
上下文上下文
) throws IOException,InterruptedException {
int sum=0;
for(intwritableval:values ) {
sum =val.get (;
}
result.set(sum;
context.write(key,result;
}
}
publicstaticvoidmain (字符串[ ] args ) throws Exception { )。
configuration conf=new configuration (;
string [ ] other args=newgenericoptionsparser (conf,args ).getRemainingArgs );
if(OtherArgs.Length!=2) {
system.err.println (other args.length );
system.err.println (usage : word count );
系统. exit (2;
}
作业作业=new job (conf,' word count ' );
job.setjarbyclass(mapper.class;
job.setmapperclass (tokenizer mapper.class;
job.setcomjxdhxcerclass (intsum reducer.class;
job.setreducerclass (intsum reducer.class;
job.setoutputkeyclass (text.class );
job.setoutputvalueclass (int writable.class;
fileinputformat.addinputpath (job,newpath ) otherArgs[0] );
fileoutputformat.setoutputpath (作业,新路径) otherArgs[1] );
system.out.print('ok ';
system.exit (job.wait for completion ) true? 0 : 1;
}
}
2---- runas---------- runconfigurations----------设置输入和输出文件参数
3,点击run查看结果
文件内容: