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

昆明网站制作在线网站建设概

昆明网站制作在线,网站建设概,外包公司能去吗,html5手机网站框架文章目录 一、源代码1. WordCountMapper类2. WordCountReducer类3. WordCountDriver类4. pom.xml 二、相关操作和配置1. 项目打包2. 带参测试3. 上传打包后的jar包和测试文档4. 增大虚拟内存5.启动集群6.在hdfs上创建输入文件夹和上传测试文档Hello.txt7. 利用jar包在hdfs实现文…

文章目录

    • 一、源代码
      • 1. WordCountMapper类
      • 2. WordCountReducer类
      • 3. WordCountDriver类
      • 4. pom.xml
    • 二、相关操作和配置
      • 1. 项目打包
      • 2. 带参测试
      • 3. 上传打包后的jar包和测试文档
      • 4. 增大虚拟内存
      • 5.启动集群
      • 6.在hdfs上创建输入文件夹和上传测试文档Hello.txt
      • 7. 利用jar包在hdfs实现文本计数
      • 8. 查看计算统计结果

一、源代码

1. WordCountMapper类

package org.example.wordcounttemplate;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;public class WordCountMapper extends Mapper<LongWritable, Text,Text, IntWritable> {//新建输出文本对象(输出的key类型)private Text text = new Text();//新建输出IntWritable对象(输出的value类型)private IntWritable intWritable = new IntWritable( 1);/*** 重写map方法* @param key 文本的索引* @param value 文本值* @param context 上下文对象* @throws IOException* @throws InterruptedException*/@Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {//获取拆分后的一行文本//mysql mysql value value valueString line = value.toString();//根据分隔符进行单词拆分String[] words = line.split( " ");//循环创建键值对for (String word : words){//输出key值设置text.set (word) ;//进行map输出//igeek igeek -> <igeek ,1> <igeek,1>context.write(text,intWritable);}}
}

2. WordCountReducer类

package org.example.wordcounttemplate;import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;import java.io.IOException;public class WordCountReducer extends Reducer<Text, IntWritable,Text, IntWritable> {//输出value对象private IntWritable valueOut = new IntWritable();/*** 重写reduce方法* @param key 单词值* @param values 单词出现的次数集合* @param context   上下文对象* @throws IOException* @throws InterruptedException*/@Overrideprotected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {//每个单词出现的次数int sum= 0;//<igeek,(1,1)>for (IntWritable value : values){//累计单词出现的数量sum += value.get();}//进行封装valueOut.set(sum);// reduce输出context.write(key, valueOut);}
}

3. WordCountDriver类

package org.example.wordcounttemplate;
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;/*** 充当mapreduce任务的客户端,用于提交任务*/public class WordCountDriver {public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
//        1.获取配置信息,获取job对象实例Configuration conf=new Configuration();Job job=Job.getInstance(conf);//        2.关联本Driver得jar路径job.setJarByClass(WordCountDriver.class);//        3.关联map和reducejob.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(args[0]));FileOutputFormat.setOutputPath(job,new Path(args[1]));//        7.提交jobboolean result=job.waitForCompletion(true);System.out.println(result?"任务提交成功":"任务提交失败");}}

4. pom.xml

重点是更改添加打包插件依赖

<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>

pom.xml文件内容如下:

<?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>org.example</groupId><artifactId>mapreduce_demo</artifactId><version>1.0-SNAPSHOT</version><name>mapreduce_demo</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client --><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>3.1.3</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>

二、相关操作和配置

1. 项目打包

在这里插入图片描述

2. 带参测试

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

在这里插入图片描述

在本地执行成功:

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

3. 上传打包后的jar包和测试文档

上传打包后的带依赖jar包(第二个)和测试文档Hello.txt 到linux系统及hdfs上

cd /opt/jar/
ll

jar包改名:

mv mapreduce_demo-1.0-SNAPSHOT-jar-with-dependencies.jar wordcount.jar
ll

在这里插入图片描述

在这里插入图片描述

 cd /opt/file/ll

在这里插入图片描述

4. 增大虚拟内存

进行MapReduce操作时,可能会报溢出虚拟内存的错误

beyond the 'VIRTUAL’memory limit.
Current usage: 32.7 MB of 1 GB physical memory used;
2.3 GB of 2.1 GB virtual memory used. Killing container.

在这里插入图片描述

解决:

在mapred-site.xml中添加如下内容

	<!-- 是否对容器强制执行虚拟内存限制 --><property><name>yarn.nodemanager.vmem-check-enabled</name><value>false</value><description>Whether virtual memory limits will be enforced for containers</description></property><!-- 为容器设置内存限制时虚拟内存与物理内存之间的比率 --><property><name>yarn.nodemanager.vmem-pmem-ratio</name><value>5</value><description>Ratio between virtual memory to physical memory when setting memory limits for containers</description></property>
cd /opt/softs/hadoop3.1.3/etc/hadoop/
vim mapred-site.xml

在这里插入图片描述

分发到另外两台服务器虚拟机

scp mapred-site.xml root@bigdata04:/opt/softs/hadoop3.1.3/etc/hadoop/scp mapred-site.xml root@bigdata05:/opt/softs/hadoop3.1.3/etc/hadoop/

5.启动集群

[root@bigdata03 hadoop]# start-dfs.sh
[root@bigdata05 ~]# start-yarn.sh

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

6.在hdfs上创建输入文件夹和上传测试文档Hello.txt

hadoop fs -ls /
hadoop fs -mkdir /inputhadoop fs -put Hello.txt  /input
hadoop fs -ls  /input

在这里插入图片描述

7. 利用jar包在hdfs实现文本计数

 cd /opt/jar/llhadoop jar wordcount.jar org.example.wordcounttemplate.WordCountDriver /input/Hello.txt /output  

注意:输出目录需不存在,让他执行命令时自行创建

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

8. 查看计算统计结果

hadoop fs -ls  /output
hadoop fs -cat  /output/part-r-00000

在这里插入图片描述

在这里插入图片描述

对照文章:
大数据作业4(含在本地实现wordcount案例)
https://blog.csdn.net/m0_48170265/article/details/130029532?spm=1001.2014.3001.5501

http://www.yayakq.cn/news/354724/

相关文章:

  • o2o网站建设技术湖北省建设局网站首页
  • 网站域名到期怎么续费php wordpress单本小说网站源码+采集
  • 素材搜集网站网站建设优劣势分析
  • 兰州快速seo整站优化招商页面 菜单 wordpress
  • 网站建设 三乐电子商务网站APP
  • 咖啡店网站模板邮箱注册网站
  • 揭阳网站制作收录网站源码
  • 哈尔滨学校网站建设关于室内设计的网站有哪些
  • 个人购物网站怎么备案跑步机 东莞网站建设
  • 做外贸一般去什么网站找客户如何做推广麦当劳的网站
  • c程序设计课程网站建设论文网站推广外链怎么做
  • 网站备案幕布照片自动点击器怎么用
  • 网站开发 入门教程网站管理与建设试题
  • 蓝色风格网站软文营销的概念
  • 硬件开发语言有哪些做网站推广用优化还是竞价
  • 企业网站建设流程赣州人才网暑假工
  • 西安长安区网站优化地址福建泉州网站建设公司哪家好
  • 温州建设网站制作南京哪公司建设网站
  • 在线解压网站怎么做网站播放器
  • html5 网站logodede英文网站
  • 做网站的介绍免费货源在线永久
  • 网站品质企业网站域名注册
  • ui最好的网站作业帮小程序入口
  • 阳区城市规划建设局网站关键词上首页的有效方法
  • 网站建设和seo的工作好不好心悦会员免做卡网站
  • 徐州做企业网站旅游网站开发的目的和意义
  • 南宁网站关键词推广点赞排行 wordpress 主题
  • 网站制作字体电商网站的开发形式
  • 网站建设公司好哪家好谷歌优化和谷歌竞价的区别
  • 建立公司网站的申请网络营销专业咋样