scalaspark开发人员必须在他的计算机上安装spark和hadoop吗?

yvgpqqbh  于 2021-05-18  发布在  Spark
关注(0)|答案(1)|浏览(354)

我已经在服务器上安装了hadoop+spark集群。在主服务器上的sparkshell中编写scala代码工作得很好。
我将spark库(jar文件)放在我的项目中,并通过intellij在我的计算机上编写我的第一个scala代码。
当我运行一个简单的代码,创建一个sparkcontext对象,通过hdfs协议从hdfs读取一个文件时,它会输出错误消息。
测试功能:

import org.apache.spark.SparkContext

class SpcDemoProgram {

  def demoPrint(): Unit ={
    println("class spe demoPrint")
    test()
  }

  def test(){

    var spark = new SparkContext();
  }
}

这些信息是:
20/11/02 12:36:26信息sparkcontext:运行spark版本3.0.0 20/11/02 12:36:26警告shell:未找到winutils.exe:{}java.io.filenotfoundexception:java.io.filenotfoundexception:hadoop\u home和hadoop.home.dir未设置-看到了吗https://wiki.apache.org/hadoop/windowsproblems 在org.apache.hadoop.util.shell.filenotfoundexception(shell。java:548)在org.apache.hadoop.util.shell.gethadoophomedir(shell。java:569)在org.apache.hadoop.util.shell.getqualifiedbin(shell。java:592)在org.apache.hadoop.util.shell。java:689)在org.apache.hadoop.util.stringutils.(stringutils。java:78)在org.apache.hadoop.conf.configuration.getboolean(配置。java:1664)位于org.apache.hadoop.security.securityutil.setconfigurationinternal(securityutil。java:104)在org.apache.hadoop.security.securityutil。java:88)在org.apache.hadoop.security.usergroupinformation.initialize(用户组信息)。java:316)位于org.apache.hadoop.security.usergroupinformation.ensureinitialized(usergroupinformation)。java:304)在org.apache.hadoop.security.usergroupinformation.dosubjectlogin(usergroupinformation。java:1828)在org.apache.hadoop.security.usergroupinformation.createloginuser(用户组信息)。java:710)位于org.apache.hadoop.security.usergroupinformation.getloginuser(usergroupinformation)。java:660)在org.apache.hadoop.security.usergroupinformation.getcurrentuser(usergroupinformation。java:571)在org.apache.spark.util.utils$.$anonfun$getcurrentusername$1(utils。scala:2412)在scala.option.getorelse(option。scala:189)在org.apache.spark.util.utils$.getcurrentusername(utils。scala:2412)在org.apache.spark.sparkcontext。scala:303)在org.apache.spark.sparkcontext。scala:120)在scala.spc.demo.spcdemoprogram.test(spcdemoprogram。scala:14)在scala.spc.demo.spcdemoprogram.demoprint(spcdemoprogram。scala:9)在scala.spc.demo.spcdemoprogram$.main(spcdemoprogram。scala:50)在scala.spc.demo.spcdemoprogram.main(spcdemoprogram.scala)中,由以下原因引起:java.io.filenotfoundexception:hadoop\u home和hadoop.home.dir未设置。在org.apache.hadoop.util.shell.checkhadoophomeinner(shell。java:468)在org.apache.hadoop.util.shell.checkhadoophome(shell。java:439)在org.apache.hadoop.util.shell。java:516) ... 19更多20/11/02 12:36:26警告nativecodeloader:无法为您的平台加载本机hadoop库。。。在适用的情况下使用内置java类20/11/02 12:36:27 error sparkcontext:初始化sparkcontext时出错。org.apache.spark.sparkexception:必须在org.apache.spark.sparkcontext的配置中设置主url。scala:380)在org.apache.spark.sparkcontext。scala:120)在scala.spc.demo.spcdemoprogram.test(spcdemoprogram。scala:14)在scala.spc.demo.spcdemoprogram.demoprint(spcdemoprogram。scala:9)在scala.spc.demo.spcdemoprogram$.main(spcdemoprogram。scala:50)在scala.spc.demo.spcdemoprogram.main(spcdemoprogram.scala)20/11/02 12:36:27 info sparkcontext:已成功停止线程“main”org.apache.spark.sparkexception中的sparkcontext异常:必须在以下位置在配置中设置主url:org.apache.spark.sparkcontext.(sparkcontext。scala:380)在org.apache.spark.sparkcontext。scala:120)在scala.spc.demo.spcdemoprogram.test(spcdemoprogram。scala:14)在scala.spc.demo.spcdemoprogram.demoprint(spcdemoprogram。scala:9)在scala.spc.demo.spcdemoprogram$.main(spcdemoprogram。scala:50)在scala.spc.demo.spcdemoprogram.main(spcdemoprogram.scala)
这个错误消息是否意味着hadoop和spark必须安装在我的计算机上?
我需要做什么配置?

ktecyv1j

ktecyv1j1#

我假设,您正在尝试读取路径为的文件 hdfs://<FILE_PATH> 那么是的,您需要安装hadoop,如果它只是一个本地目录,您可以尝试在文件路径中不使用“hdfs://”。

相关问题