【问题标题】:Apache Livy doesn't work with local jar fileApache Livy 不适用于本地 jar 文件
【发布时间】:2018-06-26 08:30:20
【问题描述】:

我正在尝试使用 spark-submit 运行本地 jar 文件,该文件运行良好。这是命令-

spark-submit --class "SimpleApp" --master local myProject/target/scala-2.11/simple-project_2.11-1.0.jar

但是当我尝试使用 curl 时

curl -X POST --data '{
 "file": "file:///home/user/myProject/target/scala-2.11/simple-project_2.11-1.0.jar",
 "className": "SimpleApp",
}'  
-H 
"Content-Type: application/json" 
http://server:8998/batches

报错

"requirement failed: Local path /home/user/myProject/target/scala-2.11/simple-project_2.11-1.0.jar cannot be added to user sessions."

这是我的 livy.conf 文件,因为一些文章建议更改一些内容。

# What host address to start the server on. By default, Livy will bind to all network interfaces.
livy.server.host = 0.0.0.0

# What port to start the server on.
livy.server.port = 8998

# What spark master Livy sessions should use.
livy.spark.master = local

# What spark deploy mode Livy sessions should use.
livy.spark.deploy-mode = client

# List of local directories from where files are allowed to be added to user sessions. By
# default it's empty, meaning users can only reference remote URIs when starting their
# sessions.
livy.file.local-dir-whitelist= /home/user/.livy-sessions/

请帮我解决这个问题。

提前致谢。

【问题讨论】:

    标签: scala apache-spark livy


    【解决方案1】:

    我最近从 Apache Livy 获得了本地文件读取的解决方案,因为我使用 cURL 创建了错误的请求。我刚刚用 'local:/' 替换了 'file://' 中的文件读取协议,这对我有用。

    curl -X POST --data '{
      "file": "local:/home/user/myProject/target/scala-2.11/simple-project_2.11-1.0.jar",
      "className": "SimpleApp",
    }'  
    -H 
    "Content-Type: application/json" 
    http://server:8998/batches
    

    这是一个很小的错误,但仍然无法从 HDFS 访问我的 jar 文件。

    感谢大家的帮助。

    【讨论】:

    • 感谢您添加“本地”的提示。
    【解决方案2】:

    Apache Livy jar 文件的存在是强制性要求。没有对应的jar文件是不行的。

    我的建议是下一个:只需将 livy jar 文件附加到带有 java's cp option 的类路径:

    java -cp /usr/local/livy.jar com.myclass.Main
    

    或者干脆使用 SBT:

    libraryDependencies += "org.apache.livy" % "livy-api" % "0.4.0-incubating"
    

    马文:

    <dependency>
        <groupId>org.apache.livy</groupId>
        <artifactId>livy-api</artifactId>
        <version>0.4.0-incubating</version>
    </dependency>
    

    或者你最喜欢的构建工具。

    顺便说一句,您也可以将livy jar 文件上传到HDFS 并在您的Hadoop 集群上使用,它可以大大简化您的生活。

    【讨论】:

    • 我也尝试过使用 hdfs,但我仍然遇到问题。你可以在这里查看我的查询-stackoverflow.com/questions/50969333/…
    • 您必须使用您的代码库 + 必要的 jar - sbt assembly 或一些 maven 插件制作 fat jar 文件,将此 jar 文件上传到 hdfs 并使用此 jar 文件运行 spark-submit放在hdfs 或使用curl。
    • 如果你不想制作fat jar文件并上传到hdfs,可以考虑python脚本,可以像纯文本一样提交,没有任何jar文件。
    • @Divine 我已经详细回答了你的另一个问题,请查收。
    【解决方案3】:

    如here所述,以下答案对我有用 Apache Livy cURL not working for spark-submit command

    要将本地文件用于 livy 批处理作业,您需要将本地文件夹添加到 livy.conf 中的 livy.file.local-dir-whitelist 属性。

    来自 livy.conf.template 的描述:

    允许将文件添加到用户会话的本地目录列表。默认情况下它是空的,这意味着用户只能在开始他们的会话时引用远程 URI。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-12
      • 1970-01-01
      • 1970-01-01
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 2022-10-18
      • 1970-01-01
      相关资源
      最近更新 更多