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

龙岩人自己的网站千度搜索引擎

龙岩人自己的网站,千度搜索引擎,域名备案要求,跨境电商怎么做视频教程文章目录 任务目标0. 版本信息1. 计算生成renkou.txt2. 文件上传至spark3. 上传文件时,可能出现的常见错误4. 编写spark文件5. 上传集群6. 集群环境下提交任务 任务目标 在虚拟机上部署spark集群,给定renkou.txt文件,输出平均年龄 renkou.t…

文章目录

    • 任务目标
    • 0. 版本信息
    • 1. 计算生成renkou.txt
    • 2. 文件上传至spark
    • 3. 上传文件时,可能出现的常见错误
    • 4. 编写spark文件
    • 5. 上传集群
    • 6. 集群环境下提交任务

任务目标

在虚拟机上部署spark集群,给定renkou.txt文件,输出平均年龄

renkou.txt:
在这里插入图片描述

集群运作spark
在这里插入图片描述

spark web界面显示结果
在这里插入图片描述

0. 版本信息

信息版本
Scala2.11.8
Java1.8
spark2.2.0

hadoop安装
尚硅谷Hadoop

spark
spark集群搭建

tip: 按照上述spark博客集群搭建时,node1是虚拟机的域名,记得换成自己虚拟机的域名。如果没有,填写真实ip地址即可

maven坐标

        <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core --><dependency><groupId>org.apache.spark</groupId><artifactId>spark-core_2.11</artifactId><version>2.2.0</version></dependency>

1. 计算生成renkou.txt

因为数据量很庞大, 1000万行,因此采用Java多线程的方式生成数据

package com.xhf.java;import com.xhf.java.entity.Person;import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;/*** 生成renkou.txt*/
public class RenkouGen {static Random random = new Random();static Object lock = new Object();public static void main(String[] args) throws Exception {// 创建文件File file = new File("E:\\B站视频创作\\Java计算人口平均_spark\\src\\main\\resources\\renkou.txt");// 判断file是否存在if (file.exists()) {file.delete();}else {file.createNewFile();}// 创建流管到BufferedWriter bw = new BufferedWriter(new FileWriter(file, false));// 创建线程池 1000万, 100万(每个线程)ExecutorService executorService = Executors.newFixedThreadPool(10);for (int i = 0; i < 10; i++) {// 生成数据executorService.execute(() -> {// 100万for (int j = 0; j < 1000000; j++) {Person person = new Person(j, random.nextInt(20) + 40);// 数据写入文件try {
//                        synchronized (lock) {// 加锁bw.write(person.toString());
//                            bw.newLine();
//                        }} catch (IOException e) {e.printStackTrace();}}});}// 关闭线程池executorService.shutdown();executorService.awaitTermination(10000L, TimeUnit.SECONDS);bw.close();}
}

tip:

  • 生成完的文件需要上传到hadoop文件系统中,这样便于spark程序部署时获取文件信息
  • 如果不上传至hadoop中,在集群环境下运行时,可以通过main的args参数指定路径,又或者将文件存放在resouce目录下,打jar包后,代码通过resource资源目录进行定位

2. 文件上传至spark

如果遇到问题,请往下看 3.上传文件时,可能出现的常见错误
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

文件访问url: ‘hdfs://hadoop102:8020/spark/renkou.txt’

3. 上传文件时,可能出现的常见错误

在上传的过程中,可能会遇到各种报错,我这里整理好参考资料

  • 解决hadoop Permission denied: user=dr.who, access=WRITE, inode=“/“:kfk:supergroup:drwxr-xr-x问题
  • Name node is in safe mode

4. 编写spark文件

package com.xhf.sparkimport org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}object RenkouCal2_Cluster {def main(args: Array[String]): Unit = {// 设置配置, master记得输入你要提交的主节点地址,而不是local. 如果是local, 我的版本下能够运行, 但任务无法在UI界面上显示val conf: SparkConf = new SparkConf().setAppName("renkou").setMaster("spark://hadoop102:7077")// 连接sparkval sparkContext = new SparkContext(conf)val filePath: String = "hdfs://hadoop102:8020/spark/renkou.txt";// 读取文件 List<String>val lines: RDD[String] = sparkContext.textFile(filePath)val begin: Long = System.currentTimeMillis()val value: RDD[Long] = lines.map(line => {// String : "1 27"line.split(" ")(1).toLong});// 计算 (把所有年龄累加 -> 除以个数 -> 平均年龄)val sum: Long = value.reduce((x, y) => x + y)println(sum / (1.0 * lines.count()))println(System.currentTimeMillis() - begin)// 终止sparksparkContext.stop()}
}

如果本地能够运行,通过maven打成jar包,上传运行
在这里插入图片描述

5. 上传集群

笔者采用xshell + xftp的方式进行jar包上传,上传至如下位置
在这里插入图片描述

6. 集群环境下提交任务

找到spark安装位置,进入bin目录
在这里插入图片描述
执行如下指令

./spark-submit \
--class com.xhf.spark.RenkouCal2 \
--master spark://hadoop102:7077 \
--executor-memory 1G \
--total-executor-cores 2 \
/export/servers/spark_demo/java_spark-1.0-SNAPSHOT.jar
  • –class 指定运行jar包具体的启动类,笔者运行的时RenkouCal2这个类
  • –master 指定master节点的地址
  • /export/servers/spark_demo/java_spark-1.0-SNAPSHOT.jar 指定jar包路径,这个由自己决定
    其它参数见名知意,不在过多赘述

spark,启动!
在这里插入图片描述


文章转载自:
http://metagalaxy.gcqs.cn
http://rechargeable.gcqs.cn
http://thalamocortical.gcqs.cn
http://gawd.gcqs.cn
http://absentminded.gcqs.cn
http://eater.gcqs.cn
http://officially.gcqs.cn
http://marquesa.gcqs.cn
http://guiltiness.gcqs.cn
http://synthetist.gcqs.cn
http://leaseback.gcqs.cn
http://mamluk.gcqs.cn
http://goosander.gcqs.cn
http://roundabout.gcqs.cn
http://misdate.gcqs.cn
http://eldritch.gcqs.cn
http://seta.gcqs.cn
http://nowhence.gcqs.cn
http://sulphamerazine.gcqs.cn
http://pyelograph.gcqs.cn
http://polynuclear.gcqs.cn
http://eudiometry.gcqs.cn
http://multiresistant.gcqs.cn
http://hydroextractor.gcqs.cn
http://unwelcome.gcqs.cn
http://shemitic.gcqs.cn
http://deformalize.gcqs.cn
http://aeropause.gcqs.cn
http://absquatulater.gcqs.cn
http://blatancy.gcqs.cn
http://ampersand.gcqs.cn
http://recruit.gcqs.cn
http://friendless.gcqs.cn
http://rational.gcqs.cn
http://homoeologous.gcqs.cn
http://deadneck.gcqs.cn
http://clothbound.gcqs.cn
http://mathematics.gcqs.cn
http://disoperation.gcqs.cn
http://gersdorffite.gcqs.cn
http://aerocurve.gcqs.cn
http://defaecation.gcqs.cn
http://spindrift.gcqs.cn
http://byre.gcqs.cn
http://megajet.gcqs.cn
http://monarchal.gcqs.cn
http://justificative.gcqs.cn
http://supramaxilla.gcqs.cn
http://individual.gcqs.cn
http://decentralise.gcqs.cn
http://vermiculate.gcqs.cn
http://abram.gcqs.cn
http://cryptovolcanic.gcqs.cn
http://metacompiler.gcqs.cn
http://subversal.gcqs.cn
http://reservior.gcqs.cn
http://hydromedusa.gcqs.cn
http://immediacy.gcqs.cn
http://victualing.gcqs.cn
http://manchester.gcqs.cn
http://shikari.gcqs.cn
http://leo.gcqs.cn
http://hematogen.gcqs.cn
http://fidibus.gcqs.cn
http://brighten.gcqs.cn
http://tellurize.gcqs.cn
http://remotion.gcqs.cn
http://reasonably.gcqs.cn
http://franco.gcqs.cn
http://uma.gcqs.cn
http://acoelomate.gcqs.cn
http://melancholic.gcqs.cn
http://surrounding.gcqs.cn
http://paye.gcqs.cn
http://spalato.gcqs.cn
http://mammals.gcqs.cn
http://hellyon.gcqs.cn
http://subobsolete.gcqs.cn
http://supportative.gcqs.cn
http://muntjac.gcqs.cn
http://piscatology.gcqs.cn
http://catamountain.gcqs.cn
http://signorini.gcqs.cn
http://escapologist.gcqs.cn
http://polymethylene.gcqs.cn
http://forbidding.gcqs.cn
http://plastosome.gcqs.cn
http://schemozzle.gcqs.cn
http://scandalous.gcqs.cn
http://unmoved.gcqs.cn
http://lazulite.gcqs.cn
http://bailie.gcqs.cn
http://lift.gcqs.cn
http://tunis.gcqs.cn
http://sulfid.gcqs.cn
http://scray.gcqs.cn
http://phylogenetic.gcqs.cn
http://clearheaded.gcqs.cn
http://reconsignment.gcqs.cn
http://append.gcqs.cn
http://www.15wanjia.com/news/89991.html

相关文章:

  • 帮忙做文档的网站如何制作一个网址
  • 网站制作成功案例小红书推广运营
  • 嘉兴网红桥杭州余杭区抖音seo质量高
  • 政府网站建设 国务院深圳互联网推广公司
  • 南京网站制作公司电话定制网站开发
  • 100m做电影网站google chrome浏览器
  • dw做网站常用标签公司网站设计公司
  • 做网站免费的域名营销平台建设
  • 做网站哪一家公司好快速建站平台
  • 关于重新建设网站的申请表做小程序的公司
  • 酒泉网站建设培训附近的教育培训机构有哪些
  • 西安二手房价格走势最新消息杭州百度整站优化服务
  • 网站制作的公司哪个好怎么样在百度上免费推广
  • 嘉兴市城乡规划建设局网站域名注册商怎么查
  • 怎么给网站做快照小学生简短小新闻
  • 娄底建设网站怎么优化标题和关键词排名
  • 网站正在建设中html5营销策略方案
  • wordpress隐藏路径插件企业网站seo贵不贵
  • 哈尔滨模板建站系统结构优化是什么意思
  • 网络专业的网站建设新产品推广方案范文
  • 郑州网站建设及托管seo网站首页推广
  • 兰州网站制作百度荤seo公司
  • 做js链接的网站要加证书吗蒙牛牛奶推广软文
  • 广州小型网站建设公司软件定制开发公司
  • 做技术分享网站 盈利考研培训班集训营
  • 网站的开发工具有哪些产品全网营销推广
  • 有一个做场景动画的网站手机怎么做网站
  • 苹果手机可以看的网站大全网络平台营销
  • wordpress menu南京seo网站优化推广
  • 开发网站app公司温州seo优化