MapReduce和Yarn

MapReduce

配置文件

<!--mapred-site.xml.xml-->
<property>
    <!--用于执行MapReduce作业的运行时框架。默认为local,可以是:local,yarn,classic -->
	<name>mapreduce.framework.name</name>
	<value>yarn</value>
</property>
</property>
<property>
    <!--执行map操作使用的内存,默认为1024M-->
    <name>mapreduce.map.memory.mb</name>
    <value>1024</value>
</property>
<property>
     <!--执行map操作使用的cpu核数,默认为1核-->
    <name>mapreduce.map.cpu.vcores</name>
    <value>mapreduce_shuffle</value>
</property>
<property>
     <!--执行reduce操作使用的内存,默认为1024M-->
    <name>mapreduce.reduce.memory.mb</name>
    <value>1024</value>
</property>
<property>
    <!--执行reduce操作使用的cpu核数,默认为1核-->
    <name>mapreduce.reduce.cpu.vcores</name>
    <value>1</value>
</property>
<property>
    <!--MR AppMaster需要的内存量。默认为1536M,因此在yarm-site.xml中yarn.nodemanager.resource.memory-mb配置至少为1536-->
    <name>yarn.app.mapreduce.am.resource.mb</name>
    <value>1536</value>
</property>
<property>
    <!--MR AppMaster需要的虚拟CPU核心数量。。默认为1个-->
    <name>yarn.app.mapreduce.am.resource.cpu-vcores</name>
    <value>1</value>
</property>

MR客户端

public class ClientMR{
    
    public static void main(String[] args){
        Configuration conf = new Configuration();
        //hdfs的地址
        conf.set("fs.defaultFS", "hdfs://linux11:9000/");
        //在yarn的调度平台上运行,如果不写,默认为本地调试模式(windows)
        conf.set("mapreduce.framework.name", "yarn");
        Job job = Job.getInstance(conf);

        job.setJarByClass(ClientMR.class);
//        job.setJar();
        //设置mapclass
        job.setMapperClass(MapTask.class);
        //设置reduceclass
        job.setReducerClass(ReduceTask.class);
		//map输出的key类型
        job.setMapOutputKeyClass(Text.class);
        //map输出的value类型
        job.setMapOutputValueClass(IntWritable.class);
		//设置最终输出的key类型
        job.setOutputKeyClass(Text.class);
        //设置最终输出的value类型
        job.setOutputValueClass(IntWritable.class);
        //输入路径(数据存在的路径)
        FileInputFormat.setInputPaths(job, new Path("/input/datas.txt"));
        //处理完的数据输出路径
         Path outputPath = new Path("/wordcount/out/");
        if (fs.exists(outputPath)) fs.delete(outputPath, true);
        FileOutputFormat.setOutputPath(job, outputPath);
        /*提交*/
        job.waitForCompletion(true);
    }
}

Yarn

配置文件

<!--yarn-site.xml-->
<property>
    <!--yarn resourcemanager所在的主机-->
    <name>yarn.resourcemanager.hostname</name>
    <value>linux11</value>
</property>
<property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
</property>
<property>
    <!--nodemanager的最小内存-->
    <name>yarn.nodemanager.resource.memory-mb</name>
    <value>2048</value>
</property>

启动

  • 配置hadoop-8.3.2/etc/hadoop/yarn-site.xml,参考上面配置文件
  • cd hadoop-8.3.2/sbin
  • ./start-yarn.sh
  • 验证地址:http://linux01:8088