编写mapreduce测试时,可以使用本地线程模拟方式来运行Hadoop是否能运行
Configuration conf = new Configuration();
//本地使用线程模拟Hadoop集群
conf.set("mapreduce.framework.name","local");
//设置本地的文件系统方式
conf.set("fs.defaultFS","file:///");
Job job = Job.getInstance(conf);
//使用这种方式的设置jar通常不能在本地跑,要把jar放到集群中去,这样可以在任何路径上运行
job.setJarByClass(JobRun.class);
//设置本地的数据路径
FileInputFormat.setInputPaths(job,new Path("/home/xujun/input/"));
FileOutputFormat.setOutputPath(job,new Path("/home/xujun/output/"));
//通过这种方式,可以非常方便的使用mapreduce对数据进行运行测试,调试
使用IDEA编写在本地远程调试编写好的mapreduce代码
Configuration conf = new Configuration();
//本地提交到集群上运行代码
conf.set("mapreduce.framework.name","yarn");
conf.set("yarn.resourcemanager.hostname","hadoop01");
conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
//如果是集群跑,就需要设置默认的文件系统是hdfs
conf.set("fs.defaultFS","hdfs://192.168.10.71:9000/");
//设置hadoop运行身份,这样可以绕过系统权限检查
System.setProperty("HADOOP_USER_NAME", "hadoop");
Job job = Job.getInstance(conf);
//使用这种方式的设置jar通常不能在本地跑,要把jar放到集群中去,这样可以在任何路径上运行
//这种方式适合把程序达成jar包,放到集群中去。
//job.setJarByClass(JobRun.class);
//在本地运行,需要使用固定路径,这样才能保证导入jar包,自己定义导出的jar的位置
job.setJar("/wc.jar");
FileInputFormat.setInputPaths(job,new Path("hdfs://Hadoop01:9000/wordcount/input/"));
FileOutputFormat.setOutputPath(job,new Path("hadoop01:9000/wordcount/output/"));