java api 来运行mapreduce程序
1 首先需要搭建一个hadoop集群。
2 配置环境变量
export CLASSPATH=$($HADOOP_HOME/bin/hadoop classpath):$CLASSPATH
[root@master workspace]# $HADOOP_HOME/bin/hadoop classpath
/root/software/hadoop/hadoop-2.6.1/etc/hadoop:
/root/software/hadoop/hadoop-2.6.1/share/hadoop/common/lib/*:
/root/software/hadoop/hadoop-2.6.1/share/hadoop/common/*:
/root/software/hadoop/hadoop-2.6.1/share/hadoop/hdfs:
/root/software/hadoop/hadoop-2.6.1/share/hadoop/hdfs/lib/*:
/root/software/hadoop/hadoop-2.6.1/share/hadoop/hdfs/*:
/root/software/hadoop/hadoop-2.6.1/share/hadoop/yarn/lib/*:
/root/software/hadoop/hadoop-2.6.1/share/hadoop/yarn/*:
/root/software/hadoop/hadoop-2.6.1/share/hadoop/mapreduce/lib/*:
/root/software/hadoop/hadoop-2.6.1/share/hadoop/mapreduce/*:
/root/software/hadoop/hadoop-2.6.1/contrib/capacity-scheduler/*.jar
3 代码
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