eclipse搭建Hadoop(2.7.3)开发环境遇到的问题及应对办法

来源:互联网 发布:丧尸围城2优化补丁没用 编辑:程序博客网 时间:2024/05/18 00:16

开发环境:
eclipse Mars.2 Release (4.5.2)
Hadoop 2.7.3

添加hadoop-eclipse-plugin-2.7.3.jar到eclipse的plugins目录下。
hadoop-eclipse-plugin-2.7.3.jar 下载地址

连接伪分布式环境(centos6.5 + hadoop 2.7.3):
这里写图片描述
连接成功如下:
这里写图片描述

本地测试wordCount

package 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<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("Usage: wordcount <in> <out>");            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);    }}

运行,配置参数 run as -> run configurations -> Arguments
这里写图片描述

运行时报错:(null) entry in command string: null chmod 0700

解决方案如下:
将Linux 下Hadoop的配置文件 mapred-site.xml、core-site.xml、hdfs-site.xml、yarn-site.xml 文件放置在windows Hadoop的bin目录下,

配置 HADOOP_HOME环境变量
下载 winutils.exe,hadoop.dll 拷贝到%HADOOP_HOME%\bin目录 下,libwinutils.lib到c:\windows\system32目录
下载地址

重新运行,正常。刷新DFS Locations,看到输出目录如下:
这里写图片描述

增加日志输出,新建log4j.properties 文件

# Output pattern : date [thread] priority category - messagelog4j.rootLogger=DEBUG, Console##Appenders###Console Appenderlog4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.Threshold=DEBUGlog4j.appender.Console.layout=org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c][%F:%L] : %m%n#RollingFile Appender(Store application message, hourly rolling, threshold is INFO)log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.RollingFile.File=../logs/fileDocument.loglog4j.appender.RollingFile.Threshold=DEBUGlog4j.appender.RollingFile.Encoding=UTF-8log4j.appender.RollingFile.DatePattern=.yyyy-MM-dd-HHlog4j.appender.RollingFile.layout=org.apache.log4j.PatternLayoutlog4j.appender.RollingFile.layout.ConversionPattern=%d [%t] %-5p [%F:%L] : %m%n#TraceFile Appender (Store debug message, rolling with 10M, 5 files, threshold is DEBUG) log4j.appender.TraceFile=org.apache.log4j.RollingFileAppenderlog4j.appender.TraceFile.File=../logs/fileDocument_trace.loglog4j.appender.TraceFile.Threshold=DEBUGlog4j.appender.TraceFile.Encoding=UTF-8log4j.appender.TraceFile.MaxBackupIndex=5 log4j.appender.TraceFile.layout=org.apache.log4j.PatternLayoutlog4j.appender.TraceFile.layout.ConversionPattern=%d %X{traceId} [%F:%L] : -%m%n#RollingFile Appender(Store application error message, daily rolling, threshold is ERROR)log4j.appender.ErrorRollingFile=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.ErrorRollingFile.File=../logs/fileDocument.loglog4j.appender.ErrorRollingFile.Threshold=ERRORlog4j.appender.ErrorRollingFile.Encoding=UTF-8log4j.appender.ErrorRollingFile.DatePattern=.yyyy-MM-ddlog4j.appender.ErrorRollingFile.layout=org.apache.log4j.PatternLayoutlog4j.appender.ErrorRollingFile.layout.ConversionPattern=%d [%t] %-5p [%F:%L] : %m%n##Loggers##log4j.logger.com.mybatis = DEBUGlog4j.logger.java.sql.Connection = DEBUGlog4j.logger.java.sql.Statement = DEBUGlog4j.logger.java.sql.PreparedStatement = DEBUG#Project defalult level with TraceFile appenderlog4j.logger.com.asiainfo=DEBUG,RollingFile,ErrorRollingFile,TraceFilelog4j.logger.org.springframework.aop.framework=errorlog4j.logger.org.springframework.beans.factory=errorlog4j.logger.org.apache.struts2=errorlog4j.logger.org.springframework.context.annotation=errorlog4j.logger.org.springframework.core.io=errorlog4j.logger.com.opensymphony.xwork2=errorlog4j.logger.org.springframework.aop.aspectj=errorlog4j.logger.freemarker=errorlog4j.logger.net.sf.json.JSONObject=errorlog4j.logger.org.directwebremoting=error
阅读全文
0 0
原创粉丝点击