• 在Spark shell中基于Alluxio进行wordcount交互式分析


    Spark是一个分布式内存计算框架,可部署在YARN或者MESOS管理的分布式系统中(Fully Distributed),也可以以Pseudo Distributed方式部署在单个机器上面,还可以以Standalone方式部署在单个机器上面。运行Spark的方式有interactive和submit方式。本文中所有的操作都是以interactive方式操作以Standalone方式部署的Spark。具体的部署方式,请参考Hadoop Ecosystem

    Alluxio是基于内存的分布式文件管理系统,整体层次在分布式文件系统(譬如说典型的HDFS)和分布式计算框架(譬如说典型的Spark)之间,号称能够提升性能10x倍。Alluxio可以以本地模式或者集群模式进行部署,本文中使用的是本地模式。具体的部署方式,请参考Hadoop Ecosystem

    目标:

    能够通过Alluxio方式进行WordCount的操作。

    前提:

    存在一个文件,可通过Alluxio Browser(http://localhost:19999/home)查看。

    配置Spark:

    Step 1:完成Alluxio本身的安装,本文中使用本地模式

    Step 2:在Alluxio顶层目录中执行maven命令来构建Alluxio,如果网络不好,需要等待很长时间。

    mvn clean package -Pspark -DskipTests

    Step 3:配置spark-defaults.conf

    cd /usr/share/spark/conf

    vi spark-defaults.conf

    spark.driver.extraClassPath /usr/local/alluxio/core/client/target/alluxio-core-client-1.3.0-jar-with-dependencies.jar
    spark.executor.extraClassPath /usr/local/alluxio/core/client/target/alluxio-core-client-1.3.0-jar-with-dependencies.jar

    Step 4:配置core-site.xml

    cd /usr/share/spark/conf

    vi core-site.xml

    <configuration>
      <property>
        <name>fs.alluxio.impl</name>
        <value>alluxio.hadoop.FileSystem</value>
      </property>
    </configuration>

    步骤:

    Step 1:进入Spark-shell交互式命令行。

    spark-shell

    Step 2:读取LICENSE文件,并check读取是否成功。如果不存在,则提示如下错误。

    val s = sc.textFile("alluxio://localhost:19998/LICENSE")

    s.count

    Step 3:设定输出的文件个数并执行统计逻辑

    val numOutputFiles = 128

    val counts = s.flatMap(line => line.split(" ")).map(word => (word, 1)).reduceByKey(_ + _, numOutputFiles)

    Step 4:保存计算结果到Alluxio中

    counts.saveAsTextFile("alluxio://localhost:19998/LICENSE_COUNT_ALLUXIO")

    Step 5:在Alluxio Browser中查看结果

    结论:

    通过Alluxio,我们可以在Spark-shell中轻松地进行交互式的分析(word count统计)。

    参考资料:

    http://www.alluxio.org/docs/master/cn/Running-Spark-on-Alluxio.html

    http://spark.apache.org/docs/latest/programming-guide.html

    http://coe4bd.github.io/HadoopHowTo/sparkScala/sparkScala.html

    http://coe4bd.github.io/HadoopHowTo/sparkJava/sparkJava.html

  • 相关阅读:
    Activity的几种启动模式
    android 环境搭建
    认识python中__name__、程序主入口
    32位与64位之谈
    shell中字符串基本用法
    C++ push方法与push_back方法
    8-10总结
    第九章 硬件抽象层:HAL
    第十章 嵌入式Linux的调试技术
    第八章
  • 原文地址:https://www.cnblogs.com/allanli/p/running_alluxio_in_spark_shell.html
Copyright © 2020-2023  润新知