当前位置: 首页 > news >正文

做的最好的宠物网站提高网站搜索排名

做的最好的宠物网站,提高网站搜索排名,深圳营销型网站建设公司,wordpress适合下载站的主题一、概念 MapReduce是一个 分布式运算程序 的编程框架,是用户开发“基于 Hadoop的数据分析 应用”的核心框架。 MapReduce核心功能是将 用户编写的业务逻辑代码 和 自带默认组件 整合成一个完整的 分布式运算程序 ,并发运行在一个 Hadoop集群上。 1、M…

一、概念

MapReduce是一个 分布式运算程序 的编程框架,是用户开发“基于 Hadoop的数据分析
应用”的核心框架。
MapReduce核心功能是将 用户编写的业务逻辑代码自带默认组件 整合成一个完整的
分布式运算程序 ,并发运行在一个 Hadoop集群上。

1、MapReduce是集群上的并行计算框架
2、平时开发中只需要基于MapReduce接口,编写业务逻辑代码即可。

二、优缺点

优点

1、易于编程
2、良好的扩展性
3、高容错性
4、适合PB级以上海量数据的离线处理

缺点

1、不擅长实时计算
Spark Streaming
2、不擅长流式计算
Spark StreamingFlink
3、不擅长DAG(有向无环图)计算
Spark

三、算法思想

学过Java8的都知道MapReduce框架。
它是一款并发任务框架。
但是开发难度较大

Hadoop中的MapReduce框架算法思想是一样的。
两个阶段
第一阶段,任务分发阶段(Map阶段),并行计算数据,所有数据是互不相干。所有计算任务也是互不相干的。
第二阶段,结果汇总阶段(Reduce阶段),并行统计Map计算出的结果,汇总出最终结果,返回给用户。

如果,我们拿到的一批数据,并非是等价的,可能之间存在数据依赖,那么,我们就需要写多个MapReduce任务,分别计算各个层级的数据。
所以,开发MapReduce,首先要分析数据的依赖关系,然后,编写分多个MapReduce进行计算即可。

四、WordCount案例源码阅读

1、WordCount源码

package org.apache.hadoop.examples;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 TokenizerMapperextends Mapper<Object, Text, Text, IntWritable>{private static final IntWritable one = new IntWritable(1);private Text word = new Text();public void map(Object key, Text value, Mapper<Object, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {StringTokenizer itr = new StringTokenizer(value.toString());while (itr.hasMoreTokens()) {this.word.set(itr.nextToken());context.write(this.word, one);}}}public static class IntSumReducerextends Reducer<Text, IntWritable, Text, IntWritable> {private IntWritable result = new IntWritable();public void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {int sum = 0;for (IntWritable val : values) {sum += val.get();}this.result.set(sum);context.write(key, this.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> [<in>...] <out>");System.exit(2);}Job job = Job.getInstance(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);for (int i = 0; i < otherArgs.length - 1; i++) {FileInputFormat.addInputPath(job, new Path(otherArgs[i]));}FileOutputFormat.setOutputPath(job, new Path(otherArgs[otherArgs.length - 1]));System.exit(job.waitForCompletion(true) ? 0 : 1);}
}

2、源码结构分析

主要三部分
1、程序入口,main函数
主要关注7个job配置
2、Mapper内部类
主要关注四个泛型配置:输入的key,输入的value,输出的key,输出的value
3、Reducer内部类
主要关注四个泛型配置:输入的key,输入的value,输出的key,输出的value

3、数据类型对应关系

在这里插入图片描述

五、自定义开发WordCount

1、案例需求分析

从图中,我们需要注意的是:
Mapper阶段,数据结构的变化过程,最终输出的数据结构
Reducer阶段,收到的数据结构和输出的数据结构
在这里插入图片描述

2、Mapper类实现

package com.atguigu.mapreduce.wordcount;import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;import java.io.IOException;/*** KEYIN, map阶段输入的key的类型:LongWritable,偏移量,可以理解为txt文本内容中,字符的下标。下标按行累加* VALUEIN,map阶段输入value类型:Text* KEYOUT,map阶段输出的Key类型:Text* VALUEOUT,map阶段输出的value类型:IntWritable*/
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {private Text outK = new Text();private IntWritable outV = new IntWritable(1);@Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {//可以看出,这个案例中,key偏移量没有起作用// 1 获取一行// atguigu atguiguString line = value.toString();// 2 切割// atguigu// atguiguString[] words = line.split(" ");// 3 循环写出for (String word : words) {// 封装outkoutK.set(word);// 写出context.write(outK, outV);}}
}

3、Reducer类实现

package com.atguigu.mapreduce.wordcount;import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;import java.io.IOException;/*** KEYIN, reduce阶段输入的key的类型:Text* VALUEIN,reduce阶段输入value类型:IntWritable* KEYOUT,reduce阶段输出的Key类型:Text* VALUEOUT,reduce阶段输出的value类型:IntWritable*/
public class WordCountReducer extends Reducer<Text, IntWritable,Text,IntWritable> {private IntWritable outV = new IntWritable();@Overrideprotected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {int sum = 0;// atguigu, (1,1)// 累加for (IntWritable value : values) {sum += value.get();}outV.set(sum);// 写出context.write(key,outV);}
}

4、WordCountDriver类实现

这里需要注意的是,这里的4和5两步骤。
4步骤,确定Mapper的输入类型,Mapper的输出类型要和Reducer的输入类型一致。
5步骤,确定Reducer的输出类型。

package com.atguigu.mapreduce.wordcount;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.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException;public class WordCountDriver {public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {// 1 获取jobConfiguration conf = new Configuration();Job job = Job.getInstance(conf);// 2 设置jar包路径job.setJarByClass(WordCountDriver.class);// 3 关联mapper和reducerjob.setMapperClass(WordCountMapper.class);job.setReducerClass(WordCountReducer.class);// 4 设置map输出的kv类型job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);// 5 设置最终输出的kV类型job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);// 6 设置输入路径和输出路径
//		FileInputFormat.setInputPaths(job, new Path("E:\\workspace\\data\\input\\inputword"));
//		FileOutputFormat.setOutputPath(job, new Path("E:\\workspace\\data\\ouputword"));FileInputFormat.setInputPaths(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));// 7 提交jobboolean result = job.waitForCompletion(true);System.exit(result ? 0 : 1);}
}

六、运行验证

1、本地运行

直接IDEA中,运行main函数即可
在这里插入图片描述在这里插入图片描述
在这里插入图片描述在这里插入图片描述


debug查看偏移量
可以发现,第二行的偏移量是11,因为,第一行2个test,一个空格,一个换行刚好10个
第二行的s就是11开始
所以,MapReduce程序是按行读取文件内容的,偏移量就是每行的第一个字符在文本中的位置
空格,回车等都占一个字符。

在这里插入图片描述


可能出现的错误

java.lang.ClassNotFoundException: Class org.apache.hadoop.hdfs.DistributedFileSystem

我的完整pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.atguigu</groupId><artifactId>MapReduceDemo</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>3.1.3</version></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-mapreduce-client-app</artifactId><version>3.1.3</version></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-yarn-server-resourcemanager</artifactId><version>3.1.3</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.30</version></dependency></dependencies><build><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.6.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin><plugin><artifactId>maven-assembly-plugin</artifactId><configuration><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin></plugins></build>
</project>

2、集群中运行

集群中运行,我们需要将代码生成jar
然后,上传到器群中,运行即可。

1、生成jar包

生成jar包有两种情况
1、不将相关依赖包生成到jar包中
这个情况比较常用,因为,集群上都有相关环境,所以,这样可以节省jar大小,从而上传快。
在这里插入图片描述
在这里插入图片描述


2、将相关依赖包生成到jar包中
这种,比较少用。
在这里插入图片描述
在这里插入图片描述

2、器群中测试jar包

Driver类修改如下
在这里插入图片描述
上传jar
在这里插入图片描述
在集群中找可用文件
在这里插入图片描述

执行wc.jar任务

hadoop jar wc.jar com.atguigu.mapreduce.wordcount.WordCountDriver /input/hello.txt /output

在这里插入图片描述在这里插入图片描述

在企业中,差不多也是这样
本地搭建Hadoop的开发环境
分析数据的依赖关系,然后,编写MapReduce业务代码
上传集群,执行


文章转载自:
http://lynx.stph.cn
http://inwardness.stph.cn
http://polyspermous.stph.cn
http://kinaesthesia.stph.cn
http://caudle.stph.cn
http://meperidine.stph.cn
http://sukiyaki.stph.cn
http://revolera.stph.cn
http://mudflap.stph.cn
http://vainness.stph.cn
http://brimming.stph.cn
http://sulphanilamide.stph.cn
http://cafard.stph.cn
http://muckraker.stph.cn
http://incorporated.stph.cn
http://bipartisan.stph.cn
http://reformative.stph.cn
http://lionise.stph.cn
http://schipperke.stph.cn
http://hereto.stph.cn
http://entironment.stph.cn
http://ladronism.stph.cn
http://dummkopf.stph.cn
http://landlouper.stph.cn
http://nylon.stph.cn
http://gown.stph.cn
http://epicureanism.stph.cn
http://sahaptan.stph.cn
http://dugout.stph.cn
http://snye.stph.cn
http://slyly.stph.cn
http://minuend.stph.cn
http://recoverable.stph.cn
http://rateable.stph.cn
http://azole.stph.cn
http://mediography.stph.cn
http://geonavigation.stph.cn
http://probably.stph.cn
http://metafiction.stph.cn
http://surtout.stph.cn
http://amylum.stph.cn
http://oddness.stph.cn
http://equinox.stph.cn
http://demoniacally.stph.cn
http://proverbially.stph.cn
http://bewitch.stph.cn
http://topmast.stph.cn
http://crambe.stph.cn
http://hypersensitive.stph.cn
http://colorize.stph.cn
http://fieldworker.stph.cn
http://misguide.stph.cn
http://mabe.stph.cn
http://spriggy.stph.cn
http://hitlerite.stph.cn
http://uncontrovertible.stph.cn
http://issei.stph.cn
http://bumblebee.stph.cn
http://pelargonium.stph.cn
http://colombophile.stph.cn
http://serjeanty.stph.cn
http://ploughwright.stph.cn
http://etna.stph.cn
http://vapidity.stph.cn
http://redbreast.stph.cn
http://prole.stph.cn
http://sarcology.stph.cn
http://reremouse.stph.cn
http://gripe.stph.cn
http://stealth.stph.cn
http://assheaded.stph.cn
http://darkadapted.stph.cn
http://bombsight.stph.cn
http://whoosh.stph.cn
http://carcake.stph.cn
http://grandioso.stph.cn
http://subcompact.stph.cn
http://indology.stph.cn
http://inability.stph.cn
http://troutlet.stph.cn
http://mochi.stph.cn
http://otolith.stph.cn
http://unreadable.stph.cn
http://matsu.stph.cn
http://accomplish.stph.cn
http://laddish.stph.cn
http://fssu.stph.cn
http://saskatchewan.stph.cn
http://telecourse.stph.cn
http://understock.stph.cn
http://buckra.stph.cn
http://whiplash.stph.cn
http://equate.stph.cn
http://pleading.stph.cn
http://commander.stph.cn
http://juvenilia.stph.cn
http://kasolite.stph.cn
http://cumulocirrus.stph.cn
http://diplex.stph.cn
http://buonaparte.stph.cn
http://www.15wanjia.com/news/68074.html

相关文章:

  • 在线构建网站百度收录官网
  • 网站设计是用ps做图吗seo赚钱培训
  • 网站建设建站网正规seo关键词排名哪家专业
  • 宝安网站建设公司seo综合查询爱站
  • 徐州市网站百度网页浏览器
  • 苏州企业做网站外贸网站平台都有哪些 免费的
  • 自己动手做网站免费网站制作成品
  • 福州网站制作服务免费引流推广的方法
  • 福州网站建设公司中小企业郑州seo招聘
  • 公众号微信网站开发网络营销推广seo
  • 网站备案系统登陆不上官网建站多少钱
  • 个人可以做b2b网站有哪些百度搜索风云榜总榜
  • 织梦网站建设培训seo研究协会
  • wordpress建立数据库时出错windows优化大师好吗
  • 石家庄明确新冠最新研判广州优化网站排名
  • 网站首页制作浩森宇特成都竞价托管多少钱
  • 宜昌网站建设哪家好廊坊快速优化排名
  • 江西省宜春市建设局网站关键词优化排名平台
  • 简洁风格的网站模板免费下载鹤壁网站推广公司
  • 企业常用邮箱seo关键词查询排名软件
  • 南宁网站建设培训学校全球搜钻是什么公司
  • 合肥网络公司注册班级优化大师官网下载
  • 网站建设原型图360信息流广告平台
  • txt做网站 插入图片自己想做个网站怎么做
  • 鹤壁做网站的网络公司官网关键词优化价格
  • phpcms v9网站搬站之后掉出来的文章链接显示为以前网站域名全网推广平台推荐
  • 辽宁建设工程质量监督站网站关键词排名优化流程
  • 深圳网站建设的费用手机网站快速建站
  • 广东营销式网站百度指数教程
  • 做网站必要吗seo中心