如何在公司代理后面使用 spark-shell 解析外部包?

How to resolve external packages with spark-shell when behind a corporate proxy?

我想 运行 spark-shell 使用公司代理后面的外部包。不幸的是,通过 --packages 选项传递的外部包未被解析。

例如,当运行宁

bin/spark-shell --packages datastax:spark-cassandra-connector:1.5.0-s_2.10

cassandra 连接器包未解析(卡在最后一行):

Ivy Default Cache set to: /root/.ivy2/cache
The jars for the packages stored in: /root/.ivy2/jars
:: loading settings :: url = jar:file:/opt/spark/lib/spark-assembly-1.6.1-hadoop2.6.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
datastax#spark-cassandra-connector added as a dependency
:: resolving dependencies :: org.apache.spark#spark-submit-parent;1.0
        confs: [default]

一段时间后连接超时,包含如下错误消息:

:::: ERRORS
        Server access error at url https://repo1.maven.org/maven2/datastax/spark-cassandra-connector/1.5.0-s_2.10/spark-cassandra-connector-1.5.0-s_2.10.pom (java.net.ConnectException: Connection timed out)

当我使用公司代理停用 VPN 时,程序包会立即解析并下载。

到目前为止我尝试了什么:

将代理公开为环境变量:

export http_proxy=<proxyHost>:<proxyPort>
export https_proxy=<proxyHost>:<proxyPort>
export JAVA_OPTS="-Dhttp.proxyHost=<proxyHost> -Dhttp.proxyPort=<proxyPort>"
export ANT_OPTS="-Dhttp.proxyHost=<proxyHost> -Dhttp.proxyPort=<proxyPort>"

运行 spark-shell 带有额外的 java 选项:

bin/spark-shell --conf "spark.driver.extraJavaOptions=-Dhttp.proxyHost=<proxyHost> -Dhttp.proxyPort=<proxyPort>" --conf "spark.executor.extraJavaOptions=-Dhttp.proxyHost=<proxyHost> -Dhttp.proxyPort=<proxyPort>" --packages datastax:spark-cassandra-connector:1.6.0-M1-s_2.10

我还缺少其他配置吗?

找到正确的设置:

bin/spark-shell --conf "spark.driver.extraJavaOptions=-Dhttp.proxyHost=<proxyHost> -Dhttp.proxyPort=<proxyPort> -Dhttps.proxyHost=<proxyHost> -Dhttps.proxyPort=<proxyPort>" --packages <somePackage>

http 和 https 代理都必须设置为额外的驱动程序选项。 JAVA_OPTS 好像什么都没做。

这在 spark 1.6.1 中对我有用:

bin\spark-shell --driver-java-options "-Dhttp.proxyHost=<proxyHost> -Dhttp.proxyPort=<proxyPort> -Dhttps.proxyHost=<proxyHost> -Dhttps.proxyPort=<proxyPort>" --packages <package>

在 windows 7 上使用 spark-2.0.0-bin-hadoop2.7 我在 %SPARK_HOME%"\spark-2.0.0-bin-hadoop2.7\conf\spark-defaults.conf 中设置 spark.driver.extraJavaOptions 如:

spark.driver.extraJavaOptions -Dhttp.proxyHost=hostname -Dhttp.proxyPort=port -Dhttps.proxyHost=host -Dhttps.proxyPort=port

添加

spark.driver.extraJavaOptions=-Dhttp.proxyHost=<proxyHost> -Dhttp.proxyPort=<proxyPort> -Dhttps.proxyHost=<proxyHost> -Dhttps.proxyPort=<proxyPort>

$SPARK_HOME/conf/spark-defaults.conf 适合我。

如果您的 OS 上的代理配置正确,您可以使用 java 属性: java.net.useSystemProxies:

--conf "spark.driver.extraJavaOptions=-Djava.net.useSystemProxies=true"

因此将配置代理主机/端口和 no-proxy 主机。

如果您需要身份验证才能使用代理,您可以在默认配置文件中使用以下内容:

spark.driver.extraJavaOptions  -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= -Dhttp.proxyUsername= -Dhttp.proxyPassword= -Dhttps.proxyUsername= -Dhttps.proxyPassword= 

在我发现这个之前一直在与 pyspark 作斗争:

补充@黄涛的回答:

bin/pyspark --driver-java-options="-Dhttp.proxyUser=user -Dhttp.proxyPassword=password -Dhttps.proxyUser=user -Dhttps.proxyPassword=password -Dhttp.proxyHost=proxy -Dhttp.proxyPort=port -Dhttps.proxyHost=proxy -Dhttps.proxyPort=port" --packages [groupId:artifactId]

即应该是 -Dhttp(s).proxyUser 而不是 ...proxyUsername