運行spark-shell時遇到的主機地址的錯誤

來源:互聯網
上載者:User

標籤: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時遇到的主機地址的錯誤

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.