mac运行spark 1.4 -shell时遇到hostname错误
本帖最后由 desehawk 于 2015-7-4 23:48 编辑下载了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 但是如果我在/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 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 = MapPartitionsRDD at textFile at :21
scala> textFile.count()
res0: Long = 98
scala> textFile.first()
res1: String = # Apache Spark
很酷!
页:
[1]