gpt4 book ai didi

scala - 从Spark作业访问HDFS HA(UnknownHostException错误)

转载 作者:行者123 更新时间:2023-12-03 18:28:53 29 4
gpt4 key购买 nike

我有Apache Mesos 0.22.1集群(3个主节点和5个从节点),在HA配置和Spark 1.5.1框架中运行Cloudera HDFS(2.5.0-cdh5.3.1)。

当我尝试 Spark 提交已编译的HdfsTest.scala示例应用程序(来自Spark 1.5.1源)时,它在执行程序日志中失败,并出现java.lang.IllegalArgumentException: java.net.UnknownHostException: hdfs错误。仅当我将HDFS HA路径作为参数hdfs://hdfs/<file>传递时才观察到此错误,而当我传递hdfs://namenode1.hdfs.mesos:50071/tesfile时-一切正常。

启用TRACE日志记录后,我发现Spark驱动程序实际上正确读取了hdfs://hdfs URL,但是Spark执行程序却没有。

我的Scala应用程式程式码:

import org.apache.spark._
object HdfsTest {
def main(args: Array[String]) {
val sparkConf = new SparkConf().setAppName("HdfsTest")
val sc = new SparkContext(sparkConf)
val file = sc.textFile(args(0))
val mapped = file.map(s => s.length).cache()
for (iter <- 1 to 10) {
val start = System.currentTimeMillis()
for (x <- mapped) { x + 2 }
val end = System.currentTimeMillis()
println("Iteration " + iter + " took " + (end-start) + " ms")
}
sc.stop()
}
}

我编译此代码,然后以集群模式将jar文件提交给Spark:
/opt/spark/bin/spark-submit --deploy-mode cluster --class com.cisco.hdfs.HdfsTest http://1.2.3.4/HdfsTest-0.0.1.jar hdfs://hdfs/testfile

我的spark-defaults.conf文件:
spark.master                     spark://1.2.3.4:7077
spark.eventLog.enabled true
spark.driver.memory 1g

我的spark-env.sh文件:
export HADOOP_HOME=/opt/spark
export HADOOP_CONF_DIR=/opt/spark/conf

我将 Spark 部署在/opt/spark目录中的每个从属服务器上。

我可以在控制台中使用“hdfs dfs -ls hdfs://hdfs/”命令访问HDFS,而无需指定事件的namenode地址和端口。
core-site.xml:
----------------------------------------------------------------------
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://hdfs</value>
</property>
</configuration>

hdfs-site.xml:
----------------------------------------------------------------------
<configuration>
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>

<property>
<name>dfs.nameservice.id</name>
<value>hdfs</value>
</property>

<property>
<name>dfs.nameservices</name>
<value>hdfs</value>
</property>

<property>
<name>dfs.ha.namenodes.hdfs</name>
<value>nn1,nn2</value>
</property>

<property>
<name>dfs.namenode.rpc-address.hdfs.nn1</name>
<value>namenode1.hdfs.mesos:50071</value>
</property>

<property>
<name>dfs.namenode.http-address.hdfs.nn1</name>
<value>namenode1.hdfs.mesos:50070</value>
</property>

<property>
<name>dfs.namenode.rpc-address.hdfs.nn2</name>
<value>namenode2.hdfs.mesos:50071</value>
</property>

<property>
<name>dfs.namenode.http-address.hdfs.nn2</name>
<value>namenode2.hdfs.mesos:50070</value>
</property>

<property>
<name>dfs.client.failover.proxy.provider.hdfs</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider </value>
</property>

<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://journalnode1.hdfs.mesos:8485;journalnode2.hdfs.mesos:8485;journalnode3.hdfs.mesos:8485/hdfs</value>
</property>

<property>
<name>ha.zookeeper.quorum</name>
<value>master.mesos:2181</value>
</property>

<property>
<name>dfs.journalnode.edits.dir</name>
<value>/var/lib/hdfs/data/jn</value>
</property>

<property>
<name>dfs.namenode.name.dir</name>
<value>file:///var/lib/hdfs/data/name</value>
</property>

<property>
<name>dfs.datanode.data.dir</name>
<value>file:///var/lib/hdfs/data/data</value>
</property>

<property>
<name>dfs.ha.fencing.methods</name>
<value>shell(/bin/true)</value>
</property>

<property>
<name>dfs.permissions</name>
<value>false</value>
</property>

<property>
<name>dfs.datanode.du.reserved</name>
<value>10485760</value>
</property>

<property>
<name>dfs.datanode.balance.bandwidthPerSec</name>
<value>41943040</value>
</property>

<property>
<name>dfs.namenode.safemode.threshold-pct</name>
<value>0.90</value>
</property>

<property>
<name>dfs.namenode.heartbeat.recheck-interval</name>
<value>60000</value>
</property>

<property>
<name>dfs.datanode.handler.count</name>
<value>10</value>
</property>

<property>
<name>dfs.namenode.handler.count</name>
<value>20</value>
</property>

<property>
<name>dfs.image.compress</name>
<value>true</value>
</property>

<property>
<name>dfs.image.compression.codec</name>
<value>org.apache.hadoop.io.compress.SnappyCodec</value>
</property>

<property>
<name>dfs.namenode.invalidate.work.pct.per.iteration</name>
<value>0.35f</value>
</property>

<property>
<name>dfs.namenode.replication.work.multiplier.per.iteration</name>
<value>4</value>
</property>

<property>
<name>dfs.namenode.datanode.registration.ip-hostname-check</name>
<value>false</value>
</property>

<property>
<name>dfs.client.read.shortcircuit</name>
<value>true</value>
</property>

<property>
<name>dfs.client.read.shortcircuit.streams.cache.size</name>
<value>1000</value>
</property>

<property>
<name>dfs.client.read.shortcircuit.streams.cache.size.expiry.ms</name>
<value>1000</value>
</property>

<property>
<name>dfs.domain.socket.path</name>
<value>/var/run/hadoop-hdfs/dn._PORT</value>
</property>
</configuration>

最佳答案

我找到了解决方案-添加

spark.files file:///opt/spark/conf/hdfs-site.xml,file:///opt/spark/conf/core-site.xml

到每个从站上的 conf/spark-defaults.conf即可解决此问题。

之后,执行程序成功将 core-site.xmlhdfs-site.xml从驱动程序下载到执行程序。

关于scala - 从Spark作业访问HDFS HA(UnknownHostException错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33174386/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com