標籤:spark scala
下載了spark 1.4,運行spark-shell時遇到以下錯誤:
java.net.UnknownHostException: UKON-M-Q0EP: UKON-M-Q0EP: nodename nor servname provided, or not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
這並不是spark特有的錯誤,而是Mac上使用java常見的一個問題,是application在查詢主機對應的ip地址時無法查詢到ip地址。
其中UKON-M-Q0EP
是我Mac的主機名稱,可以通過Mac terminal的hostname
命令查詢到:
UKON-M-Q0EP:~ ukon$ hostname
UKON-M-Q0EP
但是系統卻不能找到此主機名稱的ip地址,(其實我是不太能理解為什麼不能找到,系統就不能智能一點嗎?但的確是不能),這可以通過下面的命令來驗證:
UKON-M-Q0EP:~ ukon$ ping UKON-M-Q0EP
^C
但是如果我在/etc/hosts
檔案中加入此主機名稱與127.0.0.1
就能夠ping到了:
UKON-M-Q0EP:~ ukon$ ping UKON-M-Q0EP
PING ukon-m-q0ep (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.056 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.133 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.121 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.134 ms
^C
可見,系統的確需要我們手動的在/etc/hosts中配置才能夠找到主機的ip地址。
再次運行./bin/spark-shell
,就能夠成功了
UKON-M-Q0EP:spark-1.4.0-bin-hadoop2.6 ukon$ ./bin/spark-shell
2015-07-04 00:12:04.604 java[31755:1803488] Unable to load realm info from SCDynamicStore
Welcome to
__
/ / _ _/ /__
\ \/ \/ _ `/ _/ ‘/
// ./_,// //_\ version 1.4.0
/_/
Using Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45)
Type in expressions to have them evaluated.
Type :help for more information.
Spark context available as sc.
SQL context available as sqlContext.
scala>
DONE!
然後,成功的運行了一段spark代碼,統計一個本地檔案的行數和查詢第一行的常值內容:
scala> val textFile = sc.textFile(“README.md”)
textFile: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[1] at textFile at :21
scala> textFile.count()
res0: Long = 98
scala> textFile.first()
res1: String = # Apache Spark
很酷!
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
運行spark-shell時遇到的主機地址的錯誤